mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-09 04:16:23 +08:00
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import path from "path";
|
||
import fs from "fs";
|
||
import getLocalDataFile from "./getLocalDataFile";
|
||
import commonConst from "./commonConst";
|
||
|
||
const configPath = path.join(getLocalDataFile(), "./rubick-config.json");
|
||
|
||
const defaultConfigForAnyPlatform = {
|
||
version: 2,
|
||
perf: {
|
||
shortCut: {
|
||
showAndHidden: "OptionOrAlt+R",
|
||
separate: "Ctrl+D",
|
||
quit: "Shift+Escape",
|
||
},
|
||
common: {
|
||
start: true,
|
||
space: true,
|
||
// 是否失焦隐藏。默认在dev环境不隐藏,在打包后隐藏。
|
||
hideOnBlur: commonConst.production(),
|
||
autoPast: false,
|
||
},
|
||
local: {
|
||
search: true,
|
||
},
|
||
},
|
||
global: [],
|
||
};
|
||
|
||
global.OP_CONFIG = {
|
||
config: null,
|
||
get() {
|
||
try {
|
||
if (!global.config) {
|
||
global.config = JSON.parse(
|
||
fs.readFileSync(configPath, "utf8") ||
|
||
JSON.stringify(defaultConfigForAnyPlatform)
|
||
);
|
||
}
|
||
// 重置
|
||
if (
|
||
!global.config.version ||
|
||
global.config.version < defaultConfigForAnyPlatform.version
|
||
) {
|
||
global.config = defaultConfigForAnyPlatform;
|
||
fs.writeFileSync(
|
||
configPath,
|
||
JSON.stringify(defaultConfigForAnyPlatform)
|
||
);
|
||
}
|
||
return global.config;
|
||
} catch (e) {
|
||
global.config = defaultConfigForAnyPlatform;
|
||
return global.config;
|
||
}
|
||
},
|
||
set(key, value) {
|
||
global.config[key] = value;
|
||
fs.writeFileSync(configPath, JSON.stringify(global.config));
|
||
},
|
||
};
|