mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-26 12:42:34 +08:00
♻️ search 框输入交互优化
This commit is contained in:
60
src/common/utils/localConfig.ts
Normal file
60
src/common/utils/localConfig.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import getLocalDataFile from "./getLocalDataFile";
|
||||
import { app } from "electron";
|
||||
|
||||
const configPath = path.join(getLocalDataFile(), "./rubick-config.json");
|
||||
|
||||
const defaultConfigForAnyPlatform = {
|
||||
version: 1,
|
||||
perf: {
|
||||
shortCut: {
|
||||
showAndHidden: "Option+R",
|
||||
separate: "Ctrl+D",
|
||||
quit: "Shift+Escape",
|
||||
},
|
||||
common: {
|
||||
start: true,
|
||||
space: true,
|
||||
// 是否失焦隐藏。默认在dev环境不隐藏,在打包后隐藏。
|
||||
hideOnBlur: app.isPackaged,
|
||||
},
|
||||
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));
|
||||
},
|
||||
};
|
||||
@@ -34,15 +34,17 @@ global.LOCAL_PLUGINS = {
|
||||
},
|
||||
addPlugin(plugin) {
|
||||
let has = false;
|
||||
global.LOCAL_PLUGINS.PLUGINS.some((p) => {
|
||||
const currentPlugins = global.LOCAL_PLUGINS.getLocalPlugins();
|
||||
currentPlugins.some((p) => {
|
||||
has = p.name === plugin.name;
|
||||
return has;
|
||||
});
|
||||
if (!has) {
|
||||
global.LOCAL_PLUGINS.PLUGINS.unshift(plugin);
|
||||
currentPlugins.unshift(plugin);
|
||||
global.LOCAL_PLUGINS.PLUGINS = currentPlugins;
|
||||
fs.writeFileSync(
|
||||
configPath,
|
||||
JSON.stringify(global.LOCAL_PLUGINS.PLUGINS)
|
||||
JSON.stringify(currentPlugins)
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user