mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-10 15:39:01 +00:00
30 lines
660 B
JavaScript
30 lines
660 B
JavaScript
const electron = require('electron');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
class Store {
|
|
constructor(opts) {
|
|
const userDataPath = __dirname
|
|
this.path = path.join(userDataPath, opts.configName + '.json');
|
|
|
|
this.data = parseDataFile(this.path, opts.defaults);
|
|
}
|
|
|
|
get(key) {
|
|
return this.data[key];
|
|
}
|
|
|
|
set(key, val) {
|
|
this.data[key] = val;
|
|
fs.writeFileSync(this.path, JSON.stringify(this.data));
|
|
}
|
|
}
|
|
|
|
function parseDataFile(filePath, defaults) {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(filePath));
|
|
} catch(error) {
|
|
return defaults;
|
|
}
|
|
}
|
|
module.exports = Store; |