mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-02 02:53:01 +08:00
fix(config): Don't loop config changes through ipc
This commit is contained in:
parent
8ad72a43f9
commit
abaa3fe63f
2 changed files with 20 additions and 15 deletions
|
@ -104,28 +104,27 @@ export default class ConfigPersistenceManager {
|
||||||
this._saveThrottled();
|
this._saveThrottled();
|
||||||
}
|
}
|
||||||
|
|
||||||
getRawValues = () => {
|
getRawValuesString = () => {
|
||||||
return this.settings;
|
return JSON.stringify(this.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
setRawValue = (keyPath, value) => {
|
setRawValue = (keyPath, value, sourceWebcontentsId) => {
|
||||||
if (keyPath) {
|
if (keyPath) {
|
||||||
_.setValueForKeyPath(this.settings, keyPath, value);
|
_.setValueForKeyPath(this.settings, keyPath, value);
|
||||||
} else {
|
} else {
|
||||||
this.settings = value;
|
this.settings = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emitChangeEvent();
|
this.emitChangeEvent({sourceWebcontentsId});
|
||||||
this.saveSoon();
|
this.saveSoon();
|
||||||
|
return null;
|
||||||
return this.settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emitChangeEvent = () => {
|
emitChangeEvent = ({sourceWebcontentsId} = {}) => {
|
||||||
global.application.config.updateSettings(this.settings);
|
global.application.config.updateSettings(this.settings);
|
||||||
|
|
||||||
BrowserWindow.getAllWindows().forEach((win) => {
|
BrowserWindow.getAllWindows().forEach((win) => {
|
||||||
if (win.webContents) {
|
if ((win.webContents) && (win.webContents.id !== sourceWebcontentsId)) {
|
||||||
win.webContents.send('on-config-reloaded', this.settings);
|
win.webContents.send('on-config-reloaded', this.settings);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,10 +7,12 @@ EmitterMixin = require('emissary').Emitter
|
||||||
|
|
||||||
Color = require './color'
|
Color = require './color'
|
||||||
|
|
||||||
if global.application
|
if process.type is 'renderer'
|
||||||
app = global.application
|
|
||||||
else
|
|
||||||
app = remote.getGlobal('application')
|
app = remote.getGlobal('application')
|
||||||
|
webContentsId = remote.getCurrentWebContents().id
|
||||||
|
else
|
||||||
|
app = global.application
|
||||||
|
webContentsId = null
|
||||||
|
|
||||||
# Essential: Used to access all of N1's configuration details.
|
# Essential: Used to access all of N1's configuration details.
|
||||||
#
|
#
|
||||||
|
@ -438,7 +440,7 @@ class Config
|
||||||
if _.isObject(value)
|
if _.isObject(value)
|
||||||
value = JSON.parse(JSON.stringify(value))
|
value = JSON.parse(JSON.stringify(value))
|
||||||
|
|
||||||
@updateSettings(@setRawValue(keyPath, value))
|
@setRawValue(keyPath, value)
|
||||||
true
|
true
|
||||||
|
|
||||||
# Essential: Restore the setting at `keyPath` to its default value.
|
# Essential: Restore the setting at `keyPath` to its default value.
|
||||||
|
@ -606,17 +608,21 @@ class Config
|
||||||
@transact =>
|
@transact =>
|
||||||
settings = @getRawValues()
|
settings = @getRawValues()
|
||||||
settings = @makeValueConformToSchema(null, settings, suppressException: true)
|
settings = @makeValueConformToSchema(null, settings, suppressException: true)
|
||||||
@updateSettings(@setRawValue(null, settings))
|
@setRawValue(null, settings)
|
||||||
return
|
return
|
||||||
|
|
||||||
emitChangeEvent: ->
|
emitChangeEvent: ->
|
||||||
@emitter.emit 'did-change' unless @transactDepth > 0
|
@emitter.emit 'did-change' unless @transactDepth > 0
|
||||||
|
|
||||||
getRawValues: ->
|
getRawValues: ->
|
||||||
return app.configPersistenceManager.getRawValues()
|
try
|
||||||
|
return JSON.parse(app.configPersistenceManager.getRawValuesString())
|
||||||
|
catch
|
||||||
|
return {}
|
||||||
|
|
||||||
setRawValue: (keyPath, value) ->
|
setRawValue: (keyPath, value) ->
|
||||||
return app.configPersistenceManager.setRawValue(keyPath, value)
|
app.configPersistenceManager.setRawValue(keyPath, value, webContentsId)
|
||||||
|
@load()
|
||||||
|
|
||||||
# Base schema enforcers. These will coerce raw input into the specified type,
|
# Base schema enforcers. These will coerce raw input into the specified type,
|
||||||
# and will throw an error when the value cannot be coerced. Throwing the error
|
# and will throw an error when the value cannot be coerced. Throwing the error
|
||||||
|
|
Loading…
Reference in a new issue