add Settings
This commit is contained in:
1 parent
3ed022af37
commit
a1adbe69c5
4 files changed
+162
-107
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import * as fs from 'fs';
|
||||
|
||||
const settingPath = 'settings.json';
|
||||
|
||||
export interface SettingsModel {
|
||||
recentWorkspaces: string[];
|
||||
recentFiles: string[];
|
||||
nodeConfigPath: string; // 节点配置路径
|
||||
}
|
||||
|
||||
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: ''
|
||||
};
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
||||
set(config: any) {
|
||||
this.settings = {
|
||||
...this.settings,
|
||||
...config
|
||||
};
|
||||
this.save();
|
||||
}
|
||||
|
||||
save() {
|
||||
fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user