From ee0b640c3081fab64aa379e0e75b7271b12ebc81 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Tue, 18 Dec 2018 03:15:49 -0800 Subject: [PATCH] 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 --- src/chrome/ScreenCaptureButtons.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/chrome/ScreenCaptureButtons.js b/src/chrome/ScreenCaptureButtons.js index 523f376c2..111d0bdc9 100644 --- a/src/chrome/ScreenCaptureButtons.js +++ b/src/chrome/ScreenCaptureButtons.js @@ -12,7 +12,7 @@ import IOSDevice from '../devices/IOSDevice'; import os from 'os'; import fs from 'fs'; import adb from 'adbkit-fb'; -import {exec} from 'child_process'; +import {exec, spawn} from 'child_process'; import {remote} from 'electron'; import path from 'path'; @@ -40,15 +40,12 @@ type State = {| capturingScreenshot: boolean, |}; -function openFile(path: string): Promise { - return new Promise((resolve, reject) => { - exec(`${getOpenCommand()} "${path}"`, (error, stdout, stderr) => { - if (error) { - reject(error); - } else { - resolve(path); - } - }); +function openFile(path: string) { + const child = spawn(getOpenCommand(), [path]); + child.on('exit', (code, signal) => { + if (code != 0) { + console.error(`${getOpenCommand()} failed with exit code ${code}`); + } }); } @@ -124,7 +121,7 @@ class ScreenCaptureButtons extends Component { } }; - captureScreenshot = (): ?Promise => { + captureScreenshot = (): ?Promise => { const {selectedDevice} = this.props; if (selectedDevice instanceof AndroidDevice) { @@ -142,7 +139,8 @@ class ScreenCaptureButtons extends Component { if (err) { reject(err); } else { - resolve(await openFile(screenshotPath)); + openFile(screenshotPath); + resolve(); } }, );