MainProcess add global val settings

This commit is contained in:
zhandouxiaojiji committed 2020-10-15 16:59:03 +08:00
1 parent d0690f0398
commit 23f4795562
5 files changed
+37 -22

No files matched your search

+16 -12
View File
@@ -25,18 +25,7 @@ const sampleNodeClassify: BehaviorNodeClassify[] = [
export default class Settings {
private settings: SettingsModel;
constructor() {
if (fs.existsSync(settingPath)) {
const str = fs.readFileSync(settingPath, 'utf8');
this.settings = JSON.parse(str);
} else {
this.settings = {
recentWorkspaces: [],
recentFiles: [],
nodeConfigPath: sampleNodeConfig,
nodeClassify: sampleNodeClassify,
};
this.save();
}
this.load();
}
get nodeConfigPath() {
@@ -65,6 +54,21 @@ export default class Settings {
this.save();
}
load() {
if (fs.existsSync(settingPath)) {
const str = fs.readFileSync(settingPath, 'utf8');
this.settings = JSON.parse(str);
} else {
this.settings = {
recentWorkspaces: [],
recentFiles: [],
nodeConfigPath: sampleNodeConfig,
nodeClassify: sampleNodeClassify,
};
this.save();
}
}
save() {
fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2));
}