Fire-and-forget for openFile

Summary:
`xdg-open` is blocking on Linux. That means we won't do our cleanup steps
(or reset the button for that matter) until the user closes their viewer app.

This changes the call to be a `spawn`, so we can continue the chain. As no
one had actually used the value captured in the promise, this shouldn't
make a difference API-wise.

Reviewed By: danielbuechele

Differential Revision: D13465571

fbshipit-source-id: 5f698916157906d76ab983109deb9abe142baa9e
This commit is contained in:
Pascal Hartig
2018-12-18 03:15:49 -08:00
committed by Facebook Github Bot
parent 4cb82c1f1d
commit ee0b640c30

View File

@@ -12,7 +12,7 @@ import IOSDevice from '../devices/IOSDevice';
import os from 'os'; import os from 'os';
import fs from 'fs'; import fs from 'fs';
import adb from 'adbkit-fb'; import adb from 'adbkit-fb';
import {exec} from 'child_process'; import {exec, spawn} from 'child_process';
import {remote} from 'electron'; import {remote} from 'electron';
import path from 'path'; import path from 'path';
@@ -40,15 +40,12 @@ type State = {|
capturingScreenshot: boolean, capturingScreenshot: boolean,
|}; |};
function openFile(path: string): Promise<string> { function openFile(path: string) {
return new Promise((resolve, reject) => { const child = spawn(getOpenCommand(), [path]);
exec(`${getOpenCommand()} "${path}"`, (error, stdout, stderr) => { child.on('exit', (code, signal) => {
if (error) { if (code != 0) {
reject(error); console.error(`${getOpenCommand()} failed with exit code ${code}`);
} else { }
resolve(path);
}
});
}); });
} }
@@ -124,7 +121,7 @@ class ScreenCaptureButtons extends Component<Props, State> {
} }
}; };
captureScreenshot = (): ?Promise<string> => { captureScreenshot = (): ?Promise<void> => {
const {selectedDevice} = this.props; const {selectedDevice} = this.props;
if (selectedDevice instanceof AndroidDevice) { if (selectedDevice instanceof AndroidDevice) {
@@ -142,7 +139,8 @@ class ScreenCaptureButtons extends Component<Props, State> {
if (err) { if (err) {
reject(err); reject(err);
} else { } else {
resolve(await openFile(screenshotPath)); openFile(screenshotPath);
resolve();
} }
}, },
); );