fix(gui): Don't check elevation on start on Windows (#1822)

This fixes Electron startup on Windows

Change-Type: patch
This commit is contained in:
Jonas Hermsmeier 2017-10-31 20:20:27 +01:00 committed by GitHub
parent 68f3f695cd
commit 03b252024e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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())) {
if (_.includes([ 'win32', 'darwin' ], os.platform()) || isElevated) { require('./gui/etcher')
require('./gui/etcher') } else {
return Bluebird.resolve() permissions.isElevated().then((isElevated) => {
} if (isElevated) {
require('./gui/etcher')
return Bluebird.resolve()
}
return Bluebird.any(_.map(ELEVATOR_COMMANDS, (command) => { return Bluebird.any(_.map(ELEVATOR_COMMANDS, (command) => {
return commandExists(command.name).then((exists) => { return commandExists(command.name).then((exists) => {
if (!exists) { if (!exists) {
throw new Error(`Command does not exist: ${command.name}`) throw new Error(`Command does not exist: ${command.name}`)
} }
return command return command
}) })
})).then((command) => { })).then((command) => {
return new Bluebird((resolve, reject) => { return new Bluebird((resolve, reject) => {
const argv = process.env.APPIMAGE ? [ process.env.APPIMAGE ] : process.argv const argv = process.env.APPIMAGE ? [ process.env.APPIMAGE ] : process.argv
const options = command.options.concat([ 'env', 'SKIP=1' ]).concat(argv) const options = command.options.concat([ 'env', 'SKIP=1' ]).concat(argv)
console.log(`Running ${command.name}`) console.log(`Running ${command.name}`)
const child = childProcess.spawn(command.name, options, { const child = childProcess.spawn(command.name, options, {
detached: true, detached: true,
env: process.env env: process.env
}) })
child.stdout.on('data', (data) => { child.stdout.on('data', (data) => {
console.log(data.toString()) console.log(data.toString())
}) })
child.stderr.on('data', (data) => { child.stderr.on('data', (data) => {
console.error(data.toString()) console.error(data.toString())
}) })
child.on('exit', () => { child.on('exit', () => {
electron.app.quit() electron.app.quit()
}) })
child.on('error', reject) child.on('error', reject)
}) })
}).catch(Bluebird.AggregateError, () => { }).catch(Bluebird.AggregateError, () => {
const commands = _.map(ELEVATOR_COMMANDS, 'name') const commands = _.map(ELEVATOR_COMMANDS, 'name')
const formattedCommands = `${_.initial(commands).join(', ')}, or ${_.last(commands)}` const formattedCommands = `${_.initial(commands).join(', ')}, or ${_.last(commands)}`
throw errors.createUserError({ throw errors.createUserError({
title: 'Can\'t elevate the application', title: 'Can\'t elevate the application',
description: `Please ensure you have either ${formattedCommands} available in your system` 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)
})
} }