diff --git a/app/main.js b/app/main.js index abbc24902..7b8a9566a 100644 --- a/app/main.js +++ b/app/main.js @@ -16,6 +16,29 @@ let subpy // set to true when the quitting sequence has started let quitting = false; +/* + * Replacement for Electron's shell.openItem. The Electron version doesn't + * reliably work from the main process, and we need to be able to run it + * when no windows are open. + */ +function openItem(fullPath) { + const subprocOptions = { + detached: true, + stdio: 'ignore', + }; + + let child; + if (process.platform == 'darwin') { + child = child_process.spawn('open', [fullPath], subprocOptions); + } else if (process.platform == 'linux') { + child = child_process.spawn('xdg-open', [fullPath], subprocOptions); + } else if (process.platform == 'win32') { + child = child_process.execSync('start', [fullPath], subprocOptions); + } + + // Causes child process reference to be garbage collected, allowing main process to exit + child.unref(); +} function createWindow () { win = new BrowserWindow({backgroundColor: '#155b4a'}) @@ -177,11 +200,9 @@ function shutdown() { function upgrade(event, installerPath) { app.on('quit', () => { - // shell.openItem doesn't reliably work from the app process, so run xdg-open directly - child_process.spawn('xdg-open', [installerPath], { - stdio: 'ignore', - }); + openItem(installerPath); }); + if (win) { win.loadURL(`file://${__dirname}/dist/upgrade.html`); } diff --git a/ui/js/app.js b/ui/js/app.js index 2826b4675..3a639c945 100644 --- a/ui/js/app.js +++ b/ui/js/app.js @@ -24,7 +24,6 @@ import {Link} from './component/link.js'; const {remote, ipcRenderer, shell} = require('electron'); const {download} = remote.require('electron-dl'); -const os = require('os'); const path = require('path'); const app = require('electron').remote.app; const fs = remote.require('fs'); @@ -44,23 +43,29 @@ var App = React.createClass({ _version: null, getUpdateUrl: function() { - switch (os.platform()) { + switch (process.platform) { case 'darwin': return 'https://lbry.io/get/lbry.dmg'; case 'linux': return 'https://lbry.io/get/lbry.deb'; case 'win32': - return 'https://lbry.io/get/lbry.exe'; // should now be msi + return 'https://lbry.io/get/lbry.exe'; + default: + throw 'Unknown platform'; } }, - // Temporary workaround since electron-dl throws errors when you try to get the filename + // Hard code the filenames as a temporary workaround, because + // electron-dl throws errors when you try to get the filename getUpgradeFilename: function() { - if (os.platform() == 'darwin') { - return `LBRY-${this._version}.dmg`; - } else if (os.platform() == 'linux') { - return `LBRY_${this._version}_amd64.deb`; - } else { - return `LBRY.Setup.${this._version}.exe`; + switch (process.platform) { + case 'darwin': + return `LBRY-${this._version}.dmg`; + case 'linux': + return `LBRY_${this._version}_amd64.deb`; + case 'windows': + return `LBRY.Setup.${this._version}.exe`; + default: + throw 'Unknown platform'; } }, getInitialState: function() {