mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-30 07:39:54 +08:00
ref: 项目基础开发
This commit is contained in:
21
src/main/common/utils.js
Normal file
21
src/main/common/utils.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import fs from "fs";
|
||||
|
||||
export const getlocalDataFile = () => {
|
||||
let localDataFile = process.env.HOME;
|
||||
if (!localDataFile) {
|
||||
localDataFile = process.env.LOCALAPPDATA;
|
||||
}
|
||||
return localDataFile;
|
||||
};
|
||||
|
||||
export function saveData(path, value) {
|
||||
fs.writeFileSync(path, JSON.stringify(value));
|
||||
}
|
||||
|
||||
export function getData(path, defaultValue) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(path, 'utf8'));
|
||||
} catch (e) {
|
||||
return defaultValue || undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user