mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
enhance applying config
This commit is contained in:
@@ -2,6 +2,7 @@ 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',
|
||||
@@ -23,35 +24,53 @@ function getConfig () {
|
||||
return JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8'))
|
||||
} catch (err) {}
|
||||
}
|
||||
return {}
|
||||
return null
|
||||
}
|
||||
|
||||
var config = null
|
||||
|
||||
function saveConfig () {
|
||||
var content
|
||||
try {
|
||||
content = JSON.stringify(global.config)
|
||||
content = JSON.stringify(config)
|
||||
} catch (e) {
|
||||
global.config = {}
|
||||
content = JSON.stringify(global.config)
|
||||
config = {}
|
||||
content = JSON.stringify(config)
|
||||
}
|
||||
jetpack.cwd(userDataPath).file(configFile, { content })
|
||||
}
|
||||
|
||||
// Init
|
||||
global.config = Object.assign({}, defaultConfig, getConfig())
|
||||
config = getConfig()
|
||||
if (config == null) {
|
||||
config = Object.assign({}, defaultConfig)
|
||||
saveConfig()
|
||||
}
|
||||
|
||||
if (global.config['disable-direct-write']) {
|
||||
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')
|
||||
mainWindow.webContents.send('config-apply', config)
|
||||
emitToFinder('config-apply', config)
|
||||
}
|
||||
|
||||
ipc.on('configUpdated', function (event, newConfig) {
|
||||
global.config = Object.assign({}, defaultConfig, global.config, newConfig)
|
||||
config = Object.assign({}, defaultConfig, config, newConfig)
|
||||
saveConfig()
|
||||
applyConfig()
|
||||
})
|
||||
|
||||
@@ -45,16 +45,20 @@ nodeIpc.connectTo(
|
||||
nodeIpc.of.main.on(
|
||||
'message',
|
||||
function (payload) {
|
||||
switch (payload.type) {
|
||||
case 'open-finder':
|
||||
if (isFinderLoaded) {
|
||||
if (isFinderLoaded) {
|
||||
switch (payload.type) {
|
||||
case 'open-finder':
|
||||
if (finderWindow.isFocused()) {
|
||||
hideFinder()
|
||||
} else {
|
||||
openFinder()
|
||||
}
|
||||
break
|
||||
case 'config-apply': {
|
||||
finderWindow.webContents.send('config-apply', payload.data)
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -157,7 +157,7 @@ updater.on('update-downloaded', (info) => {
|
||||
|
||||
nodeIpc.config.id = 'node'
|
||||
nodeIpc.config.retry = 1500
|
||||
// nodeIpc.config.silent = true
|
||||
nodeIpc.config.silent = true
|
||||
|
||||
function spawnFinder() {
|
||||
if (process.platform === 'darwin') {
|
||||
@@ -276,7 +276,6 @@ app.on('ready', function () {
|
||||
})
|
||||
|
||||
if (finderProcess == null && process.platform === 'darwin') {
|
||||
console.log('fired only once ')
|
||||
spawnFinder()
|
||||
} else {
|
||||
finderWindow = require('./finder-window')
|
||||
|
||||
Reference in New Issue
Block a user