mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Merge pull request #17040 from atom/aw/config-loss
Support multiple config file paths
This commit is contained in:
commit
5747cce4a7
@ -91,6 +91,27 @@ describe('ConfigFile', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ConfigFile.at()', () => {
|
||||
let path0, path1
|
||||
|
||||
beforeEach(() => {
|
||||
path0 = filePath
|
||||
path1 = path.join(fs.realpathSync(temp.mkdirSync()), 'the-config.cson')
|
||||
|
||||
configFile = ConfigFile.at(path0)
|
||||
})
|
||||
|
||||
it('returns an existing ConfigFile', () => {
|
||||
const cf = ConfigFile.at(path0)
|
||||
expect(cf).toEqual(configFile)
|
||||
})
|
||||
|
||||
it('creates a new ConfigFile for unrecognized paths', () => {
|
||||
const cf = ConfigFile.at(path1)
|
||||
expect(cf).not.toEqual(configFile)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function writeFileSync (filePath, content, seconds = 2) {
|
||||
|
@ -179,10 +179,10 @@ class ApplicationDelegate {
|
||||
return remote.systemPreferences.getUserDefault(key, type)
|
||||
}
|
||||
|
||||
async setUserSettings (config) {
|
||||
async setUserSettings (config, configFilePath) {
|
||||
this.pendingSettingsUpdateCount++
|
||||
try {
|
||||
await ipcHelpers.call('set-user-settings', JSON.stringify(config))
|
||||
await ipcHelpers.call('set-user-settings', JSON.stringify(config), configFilePath)
|
||||
} finally {
|
||||
this.pendingSettingsUpdateCount--
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class AtomEnvironment {
|
||||
this.config = new Config({
|
||||
saveCallback: settings => {
|
||||
if (this.enablePersistence) {
|
||||
this.applicationDelegate.setUserSettings(settings)
|
||||
this.applicationDelegate.setUserSettings(settings, this.config.getUserConfigPath())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -15,6 +15,21 @@ const EVENT_TYPES = new Set([
|
||||
|
||||
module.exports =
|
||||
class ConfigFile {
|
||||
static at (path) {
|
||||
if (!this._known) {
|
||||
this._known = new Map()
|
||||
}
|
||||
|
||||
const existing = this._known.get(path)
|
||||
if (existing) {
|
||||
return existing
|
||||
}
|
||||
|
||||
const created = new ConfigFile(path)
|
||||
this._known.set(path, created)
|
||||
return created
|
||||
}
|
||||
|
||||
constructor (path) {
|
||||
this.path = path
|
||||
this.emitter = new Emitter()
|
||||
|
@ -113,10 +113,12 @@ class AtomApplication extends EventEmitter {
|
||||
? path.join(process.env.ATOM_HOME, 'config.json')
|
||||
: path.join(process.env.ATOM_HOME, 'config.cson')
|
||||
|
||||
this.configFile = new ConfigFile(configFilePath)
|
||||
this.configFile = ConfigFile.at(configFilePath)
|
||||
this.config = new Config({
|
||||
saveCallback: settings => {
|
||||
if (!this.quitting) return this.configFile.update(settings)
|
||||
if (!this.quitting) {
|
||||
return this.configFile.update(settings)
|
||||
}
|
||||
}
|
||||
})
|
||||
this.config.setSchema(null, {type: 'object', properties: _.clone(ConfigSchema)})
|
||||
@ -561,8 +563,8 @@ class AtomApplication extends EventEmitter {
|
||||
window.setPosition(x, y)
|
||||
}))
|
||||
|
||||
this.disposable.add(ipcHelpers.respondTo('set-user-settings', (window, settings) =>
|
||||
this.configFile.update(JSON.parse(settings))
|
||||
this.disposable.add(ipcHelpers.respondTo('set-user-settings', (window, settings, filePath) =>
|
||||
ConfigFile.at(filePath || this.configFilePath).update(JSON.parse(settings))
|
||||
))
|
||||
|
||||
this.disposable.add(ipcHelpers.respondTo('center-window', window => window.center()))
|
||||
|
Loading…
Reference in New Issue
Block a user