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:
committed by
Facebook Github Bot
parent
ba559ac338
commit
0039d5be4a
@@ -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}.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user