From 03b252024e8cabdcb3699596924d9fda7eb3825f Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Tue, 31 Oct 2017 20:20:27 +0100 Subject: [PATCH] fix(gui): Don't check elevation on start on Windows (#1822) This fixes Electron startup on Windows Change-Type: patch --- lib/start.js | 100 ++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/lib/start.js b/lib/start.js index 07497858..91d07024 100644 --- a/lib/start.js +++ b/lib/start.js @@ -60,56 +60,60 @@ if (process.env.ELECTRON_RUN_AS_NODE || process.env.ATOM_SHELL_INTERNAL_RUN_AS_N } ] - permissions.isElevated().then((isElevated) => { - if (_.includes([ 'win32', 'darwin' ], os.platform()) || isElevated) { - require('./gui/etcher') - return Bluebird.resolve() - } + if (_.includes([ 'win32', 'darwin' ], os.platform())) { + require('./gui/etcher') + } else { + permissions.isElevated().then((isElevated) => { + if (isElevated) { + require('./gui/etcher') + return Bluebird.resolve() + } - return Bluebird.any(_.map(ELEVATOR_COMMANDS, (command) => { - return commandExists(command.name).then((exists) => { - if (!exists) { - throw new Error(`Command does not exist: ${command.name}`) - } + return Bluebird.any(_.map(ELEVATOR_COMMANDS, (command) => { + return commandExists(command.name).then((exists) => { + if (!exists) { + throw new Error(`Command does not exist: ${command.name}`) + } - return command - }) - })).then((command) => { - return new Bluebird((resolve, reject) => { - const argv = process.env.APPIMAGE ? [ process.env.APPIMAGE ] : process.argv - const options = command.options.concat([ 'env', 'SKIP=1' ]).concat(argv) - - console.log(`Running ${command.name}`) - - const child = childProcess.spawn(command.name, options, { - detached: true, - env: process.env - }) - - child.stdout.on('data', (data) => { - console.log(data.toString()) - }) - - child.stderr.on('data', (data) => { - console.error(data.toString()) - }) - - child.on('exit', () => { - electron.app.quit() - }) - - child.on('error', reject) - }) - }).catch(Bluebird.AggregateError, () => { - const commands = _.map(ELEVATOR_COMMANDS, 'name') - const formattedCommands = `${_.initial(commands).join(', ')}, or ${_.last(commands)}` - throw errors.createUserError({ - title: 'Can\'t elevate the application', - description: `Please ensure you have either ${formattedCommands} available in your system` + return command + }) + })).then((command) => { + return new Bluebird((resolve, reject) => { + const argv = process.env.APPIMAGE ? [ process.env.APPIMAGE ] : process.argv + const options = command.options.concat([ 'env', 'SKIP=1' ]).concat(argv) + + console.log(`Running ${command.name}`) + + const child = childProcess.spawn(command.name, options, { + detached: true, + env: process.env + }) + + child.stdout.on('data', (data) => { + console.log(data.toString()) + }) + + child.stderr.on('data', (data) => { + console.error(data.toString()) + }) + + child.on('exit', () => { + electron.app.quit() + }) + + child.on('error', reject) + }) + }).catch(Bluebird.AggregateError, () => { + const commands = _.map(ELEVATOR_COMMANDS, 'name') + const formattedCommands = `${_.initial(commands).join(', ')}, or ${_.last(commands)}` + throw errors.createUserError({ + title: 'Can\'t elevate the application', + description: `Please ensure you have either ${formattedCommands} available in your system` + }) }) + }).catch((error) => { + electron.dialog.showErrorBox(errors.getTitle(error), errors.getDescription(error)) + electron.app.exit(EXIT_CODES.GENERAL_ERROR) }) - }).catch((error) => { - electron.dialog.showErrorBox(errors.getTitle(error), errors.getDescription(error)) - electron.app.exit(EXIT_CODES.GENERAL_ERROR) - }) + } }