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 JSONStream from 'JSONStream';
|
||||
import {Transform} from 'stream';
|
||||
import electron from 'electron';
|
||||
import fs from 'fs';
|
||||
import {v1 as uuid} from 'uuid';
|
||||
import path from 'path';
|
||||
@@ -21,6 +20,7 @@ import {exec} from 'child_process';
|
||||
import {default as promiseTimeout} from '../utils/promiseTimeout';
|
||||
import {IOSBridge} from '../utils/IOSBridge';
|
||||
import split2 from 'split2';
|
||||
import {getAppTempPath} from '../utils/pathUtils';
|
||||
|
||||
type IOSLogLevel = 'Default' | 'Info' | 'Debug' | 'Error' | 'Fault';
|
||||
|
||||
@@ -69,7 +69,7 @@ export default class IOSDevice extends BaseDevice {
|
||||
return Buffer.from([]);
|
||||
}
|
||||
const tmpImageName = uuid() + '.png';
|
||||
const tmpDirectory = (electron.app || electron.remote.app).getPath('temp');
|
||||
const tmpDirectory = getAppTempPath();
|
||||
const tmpFilePath = path.join(tmpDirectory, tmpImageName);
|
||||
const command =
|
||||
this.deviceType === 'emulator'
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
import path from 'path';
|
||||
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';
|
||||
|
||||
let _staticPath = '';
|
||||
@@ -55,6 +57,17 @@ export function getAppPath() {
|
||||
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() {
|
||||
const changelogPath = getStaticPath(config.isFBBuild ? 'facebook' : '.');
|
||||
if (fs.existsSync(changelogPath)) {
|
||||
|
||||
Reference in New Issue
Block a user