diff --git a/lib/config.js b/lib/config.js deleted file mode 100644 index d4a42d80..00000000 --- a/lib/config.js +++ /dev/null @@ -1,82 +0,0 @@ -const electron = require('electron') -const app = electron.app -const ipc = electron.ipcMain -const jetpack = require('fs-jetpack') -const nodeIpc = require('@rokt33r/node-ipc') - -const defaultConfig = { - 'editor-font-size': '14', - 'editor-font-family': 'Monaco, Consolas', - 'editor-indent-type': 'space', - 'editor-indent-size': '4', - 'preview-font-size': '14', - 'preview-font-family': 'Lato', - 'switch-preview': 'blur', - 'disable-direct-write': false, - 'theme-ui': 'light', - 'theme-code': 'xcode', - 'theme-syntax': 'xcode', - 'preview-line-number': false -} -const configFile = 'config.json' - -var userDataPath = app.getPath('userData') - -function getConfig () { - var userDataPath = app.getPath('userData') - if (jetpack.cwd(userDataPath).exists(configFile)) { - try { - return JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8')) - } catch (err) {} - } - return null -} - -var config = null - -function saveConfig () { - var content - try { - content = JSON.stringify(config) - } catch (e) { - config = {} - content = JSON.stringify(config) - } - jetpack.cwd(userDataPath).file(configFile, { content }) -} - -// Init -config = getConfig() -if (config == null) { - config = Object.assign({}, defaultConfig) - saveConfig() -} - -config = Object.assign({}, defaultConfig, config) - -if (config['disable-direct-write']) { - app.commandLine.appendSwitch('disable-direct-write') -} - -function emitToFinder (type, data) { - var payload = { - type: type, - data: data - } - - nodeIpc.server.broadcast('message', payload) -} - -app.on('ready', function () { - const mainWindow = require('./main-window') - function applyConfig () { - mainWindow.webContents.send('config-apply', config) - emitToFinder('config-apply', config) - } - - ipc.on('configUpdated', function (event, newConfig) { - config = Object.assign({}, defaultConfig, config, newConfig) - saveConfig() - applyConfig() - }) -}) diff --git a/lib/main-app.js b/lib/main-app.js index 890b7d1c..40a8b73c 100644 --- a/lib/main-app.js +++ b/lib/main-app.js @@ -10,7 +10,6 @@ const nodeIpc = require('@rokt33r/node-ipc') const GhReleases = require('electron-gh-releases') // electron.crashReporter.start() -require('./config') var mainWindow = null var finderProcess = null var finderWindow = null @@ -273,7 +272,12 @@ app.on('ready', function () { mainWindow.setMenu(menu) } mainWindow.on('close', function (e) { - app.quit() + if (appQuit) { + app.quit() + } else { + mainWindow.hide() + e.preventDefault() + } }) switch (process.platform) { case 'darwin':