Merge pull request #5610 from bigtimebuddy/master
The "Error opening app" dialog
This commit is contained in:
commit
4d56437a26
1 changed files with 31 additions and 13 deletions
|
@ -234,7 +234,13 @@ function loadApplicationPackage (packagePath) {
|
|||
packagePath = path.resolve(packagePath)
|
||||
const packageJsonPath = path.join(packagePath, 'package.json')
|
||||
if (fs.existsSync(packageJsonPath)) {
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
|
||||
let packageJson
|
||||
try {
|
||||
packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
|
||||
} catch (e) {
|
||||
showErrorMessage('Unable to parse package.json.\n\n' +
|
||||
`${e.toString()} in ${packageJsonPath}`)
|
||||
}
|
||||
if (packageJson.version) app.setVersion(packageJson.version)
|
||||
|
||||
if (packageJson.productName) {
|
||||
|
@ -242,25 +248,23 @@ function loadApplicationPackage (packagePath) {
|
|||
} else if (packageJson.name) {
|
||||
app.setName(packageJson.name)
|
||||
}
|
||||
|
||||
app.setPath('userData', path.join(app.getPath('appData'), app.getName()))
|
||||
app.setPath('userCache', path.join(app.getPath('cache'), app.getName()))
|
||||
app.setAppPath(packagePath)
|
||||
}
|
||||
|
||||
const Module = require('module')
|
||||
try {
|
||||
Module._resolveFilename(packagePath, module, true)
|
||||
} catch (e) {
|
||||
showErrorMessage('Unable to find Electron app.\n\n' +
|
||||
`See: ${packagePath}`)
|
||||
}
|
||||
// Run the app.
|
||||
require('module')._load(packagePath, module, true)
|
||||
Module._load(packagePath, module, true)
|
||||
} catch (e) {
|
||||
if (e.code === 'MODULE_NOT_FOUND') {
|
||||
app.focus()
|
||||
dialog.showErrorBox(
|
||||
'Error opening app',
|
||||
'The app provided is not a valid Electron app, please read the docs on how to write one:\n' +
|
||||
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs
|
||||
|
||||
${e.toString()}`
|
||||
)
|
||||
process.exit(1)
|
||||
showErrorMessage('Unable to open Electron app.\n\n' +
|
||||
`${e.toString()}`)
|
||||
} else {
|
||||
console.error('App threw an error when running', e)
|
||||
throw e
|
||||
|
@ -268,6 +272,20 @@ ${e.toString()}`
|
|||
}
|
||||
}
|
||||
|
||||
function showErrorMessage (message) {
|
||||
app.focus()
|
||||
dialog.showMessageBox({
|
||||
message: 'Error opening app',
|
||||
detail: message,
|
||||
buttons: ['OK', 'Learn More']
|
||||
}, (response) => {
|
||||
if (response === 1) {
|
||||
shell.openExternal('http://electron.atom.io/docs')
|
||||
}
|
||||
})
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
function loadApplicationByUrl (appUrl) {
|
||||
require('./default_app').load(appUrl)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue