Skip to content
This repository has been archived by the owner on Oct 26, 2019. It is now read-only.

Commit

Permalink
Validate local ~/.zazurc.js file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaine Schmeisser committed Oct 7, 2016
1 parent 0d56824 commit 991f946
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
14 changes: 12 additions & 2 deletions app/background.js
@@ -1,4 +1,4 @@
const { app, globalShortcut } = require('electron')
const { dialog, app, globalShortcut } = require('electron')
const path = require('path')

const configuration = require('./lib/configuration')
Expand Down Expand Up @@ -34,11 +34,21 @@ globalEmitter.on('showAbout', (message) => {
})

app.on('ready', function () {
if (!configuration.load()) {
return dialog.showMessageBox({
type: 'error',
message: 'You have an invalid ~/.zazurc.js file.',
detail: 'Please edit your ~/.zazurc.js file and try loading Zazu again.',
defaultId: 0,
buttons: ['Ok'],
}, () => {
app.quit()
})
}
logger.debug('app is ready')
createMenu()
update.queueUpdate()
forceSingleInstance()
configuration.load()
addToStartup(configuration)

globalEmitter.on('registerHotkey', (accelerator) => {
Expand Down
1 change: 1 addition & 0 deletions app/helpers/menu.js
Expand Up @@ -18,6 +18,7 @@ const openDevTools = () => {
type: 'error',
message: 'No focused window',
detail: 'There are currently no focused windows.',
defaultId: 0,
buttons: ['Ok'],
})
}
Expand Down
24 changes: 17 additions & 7 deletions app/lib/configuration.js
Expand Up @@ -24,13 +24,23 @@ class Configuration {
jetpack.write(this.profilePath, template)
}

const data = require(this.profilePath)
this.plugins = data.plugins
this.theme = data.theme
this.hotkey = data.hotkey
this.disableAnalytics = data.disableAnalytics
this.debug = data.debug
this.loaded = true
try {
const data = require(this.profilePath)
this.plugins = data.plugins
this.theme = data.theme
this.hotkey = data.hotkey
this.disableAnalytics = data.disableAnalytics
this.debug = data.debug
this.loaded = true
} catch (e) {
const logger = require('./logger')
logger.log('error', 'Attempted to load an invalid ~/.zazurc.js file', {
message: e.message,
stack: e.stack,
})
}

return this.loaded
}
}

Expand Down

0 comments on commit 991f946

Please sign in to comment.