Use 'open' module to open stuff

Summary:
Instead of our ad-hoc mechanism. There's quite a bit
of trickery involved to make this work reliably on Windows
so I'd rather take an off-the-shelf solution than reimplement this
myself.

Reviewed By: jknoxville

Differential Revision: D17628949

fbshipit-source-id: 98806b60a107231d9ee07b721ebb70f2cbd8aec1
This commit is contained in:
Pascal Hartig
2019-09-30 03:47:58 -07:00
committed by Facebook Github Bot
parent ba559ac338
commit 0039d5be4a
3 changed files with 14 additions and 17 deletions

View File

@@ -125,6 +125,7 @@
"lodash.debounce": "^4.0.8",
"mkdirp": "^0.5.1",
"node-fetch": "^2.3.0",
"open": "^6.4.0",
"openssl-wrapper": "^0.3.4",
"p-map": "^3.0.0",
"pkg": "^4.3.7",

View File

@@ -17,6 +17,7 @@ import {reportPlatformFailures} from '../utils/metrics';
import config from '../utils/processConfig';
import BaseDevice from '../devices/BaseDevice';
import {State as Store} from '../reducers';
import open from 'open';
const CAPTURE_LOCATION = expandTilde(
config().screenCapturePath || remote.app.getPath('desktop'),
@@ -36,27 +37,15 @@ type State = {
capturingScreenshot: boolean;
};
function openFile(path: string | null) {
async function openFile(path: string | null) {
if (!path) {
return;
}
const child = spawn(getOpenCommand(), [path]);
child.on('exit', code => {
if (code != 0) {
console.error(`${getOpenCommand()} failed with exit code ${code}`);
}
});
}
function getOpenCommand(): string {
//TODO: TESTED ONLY ON MAC!
switch (os.platform()) {
case 'win32':
return 'start';
case 'linux':
return 'xdg-open';
default:
return 'open';
try {
await open(path);
} catch (e) {
console.error(`Opening ${path} failed with error ${e}.`);
}
}

View File

@@ -6665,6 +6665,13 @@ onetime@^2.0.0:
dependencies:
mimic-fn "^1.0.0"
open@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/open/-/open-6.4.0.tgz#5c13e96d0dc894686164f18965ecfe889ecfc8a9"
integrity sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==
dependencies:
is-wsl "^1.1.0"
openssl-wrapper@^0.3.4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/openssl-wrapper/-/openssl-wrapper-0.3.4.tgz#c01ec98e4dcd2b5dfe0b693f31827200e3b81b07"