Add Mac and Windows installer launching

Also starts a detached process so the window doesn't get held open
(many GUI apps launch the interface in a new process, so xdg-open
returns immediately, but it's not guaranteed).
This commit is contained in:
Alex Liebowitz 2017-03-23 14:08:14 -04:00 committed by Alex Grintsvayg
parent 71e8d42b27
commit dead2bdeb3
2 changed files with 40 additions and 14 deletions

View file

@ -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`);
}

View file

@ -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() {