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()) || 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)
})
}
}