♻️ search 框输入交互优化

This commit is contained in:
muwoo
2021-12-08 15:51:54 +08:00
parent 951f21f5fa
commit 8a35e60e48
17 changed files with 253 additions and 24 deletions

View 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));
},
};

View File

@@ -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)
);
}
},