-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split configuration into low and high traffic files
Also, we're now handling config ourselves instead of using electron-config and config dependencies.
- Loading branch information
1 parent
f59ec92
commit 998c35d
Showing
9 changed files
with
112 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const fs = require('fs'); | ||
|
||
const _ = require('lodash'); | ||
|
||
const ENCODING = 'utf8'; | ||
|
||
module.exports = { | ||
start, | ||
}; | ||
|
||
function start(name, targetPath) { | ||
let cachedValue = null; | ||
|
||
try { | ||
const text = fs.readFileSync(targetPath, ENCODING); | ||
cachedValue = JSON.parse(text); | ||
console.log(`config/get: Successfully read ${name} config file`); | ||
|
||
if (!cachedValue) { | ||
console.log( | ||
`config/get: ${name} config value was falsy, cache is now empty object` | ||
); | ||
cachedValue = Object.create(null); | ||
} | ||
} catch (error) { | ||
if (error.code !== 'ENOENT') { | ||
throw error; | ||
} | ||
|
||
console.log( | ||
`config/get: Did not find ${name} config file, cache is now empty object` | ||
); | ||
cachedValue = Object.create(null); | ||
} | ||
|
||
function get(keyPath) { | ||
return _.get(cachedValue, keyPath); | ||
} | ||
|
||
function set(keyPath, value) { | ||
_.set(cachedValue, keyPath, value); | ||
console.log(`config/set: Saving ${name} config to disk`); | ||
const text = JSON.stringify(cachedValue, null, ' '); | ||
fs.writeFileSync(targetPath, text, ENCODING); | ||
} | ||
|
||
function remove() { | ||
console.log(`config/remove: Deleting ${name} config from disk`); | ||
fs.unlinkSync(targetPath); | ||
cachedValue = Object.create(null); | ||
} | ||
|
||
return { | ||
set, | ||
get, | ||
remove, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const path = require('path'); | ||
|
||
const { app } = require('electron'); | ||
|
||
const { start } = require('./base_config'); | ||
|
||
const userDataPath = app.getPath('userData'); | ||
const targetPath = path.join(userDataPath, 'ephemeral.json'); | ||
|
||
const ephemeralConfig = start('ephemeral', targetPath); | ||
|
||
module.exports = ephemeralConfig; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters