Extract temp path util
Summary: `electron.remote` access is slow so we can cache this like we do in other places. Also means one fewer `electron` import which is gonna add up for Flipper Decap. Reviewed By: mweststrate Differential Revision: D30247431 fbshipit-source-id: 90f0e8df99af8bed40fbebcfd445abaca2965b7c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
11c1c39bdc
commit
4e17fb9c48
@@ -12,7 +12,6 @@ import child_process, {ChildProcess} from 'child_process';
|
|||||||
import BaseDevice from './BaseDevice';
|
import BaseDevice from './BaseDevice';
|
||||||
import JSONStream from 'JSONStream';
|
import JSONStream from 'JSONStream';
|
||||||
import {Transform} from 'stream';
|
import {Transform} from 'stream';
|
||||||
import electron from 'electron';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {v1 as uuid} from 'uuid';
|
import {v1 as uuid} from 'uuid';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -21,6 +20,7 @@ import {exec} from 'child_process';
|
|||||||
import {default as promiseTimeout} from '../utils/promiseTimeout';
|
import {default as promiseTimeout} from '../utils/promiseTimeout';
|
||||||
import {IOSBridge} from '../utils/IOSBridge';
|
import {IOSBridge} from '../utils/IOSBridge';
|
||||||
import split2 from 'split2';
|
import split2 from 'split2';
|
||||||
|
import {getAppTempPath} from '../utils/pathUtils';
|
||||||
|
|
||||||
type IOSLogLevel = 'Default' | 'Info' | 'Debug' | 'Error' | 'Fault';
|
type IOSLogLevel = 'Default' | 'Info' | 'Debug' | 'Error' | 'Fault';
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ export default class IOSDevice extends BaseDevice {
|
|||||||
return Buffer.from([]);
|
return Buffer.from([]);
|
||||||
}
|
}
|
||||||
const tmpImageName = uuid() + '.png';
|
const tmpImageName = uuid() + '.png';
|
||||||
const tmpDirectory = (electron.app || electron.remote.app).getPath('temp');
|
const tmpDirectory = getAppTempPath();
|
||||||
const tmpFilePath = path.join(tmpDirectory, tmpImageName);
|
const tmpFilePath = path.join(tmpDirectory, tmpImageName);
|
||||||
const command =
|
const command =
|
||||||
this.deviceType === 'emulator'
|
this.deviceType === 'emulator'
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {remote} from 'electron';
|
// In utils this is fine when used with caching.
|
||||||
|
// eslint-disable-next-line flipper/no-electron-remote-imports
|
||||||
|
import {default as electron, remote} from 'electron';
|
||||||
import config from '../fb-stubs/config';
|
import config from '../fb-stubs/config';
|
||||||
|
|
||||||
let _staticPath = '';
|
let _staticPath = '';
|
||||||
@@ -55,6 +57,17 @@ export function getAppPath() {
|
|||||||
return _appPath;
|
return _appPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _tempPath: string | undefined = undefined;
|
||||||
|
export function getAppTempPath() {
|
||||||
|
if (!_tempPath) {
|
||||||
|
// We cache this.
|
||||||
|
// eslint-disable-next-line no-restricted-properties
|
||||||
|
_tempPath = (electron.app || electron.remote.app).getPath('temp');
|
||||||
|
}
|
||||||
|
|
||||||
|
return _tempPath;
|
||||||
|
}
|
||||||
|
|
||||||
export function getChangelogPath() {
|
export function getChangelogPath() {
|
||||||
const changelogPath = getStaticPath(config.isFBBuild ? 'facebook' : '.');
|
const changelogPath = getStaticPath(config.isFBBuild ? 'facebook' : '.');
|
||||||
if (fs.existsSync(changelogPath)) {
|
if (fs.existsSync(changelogPath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user