This commit is contained in:
2026-09-12 13:59:12 +08:00
commit 941ce4baab
71 changed files with 13037 additions and 0 deletions

37
lib/settings-handlers.js Normal file
View File

@@ -0,0 +1,37 @@
'use strict';
const cfg = require('../config.js');
const SETTINGS_HANDLERS = {
autoLaunch: {
// 宽松强制转换:布尔、真值字符串('true' / 'yes'、1 都视为开启
apply: (cur, v) => cfg.sanitize({ ...cur, autoLaunch: Boolean(v) }),
},
maxItems: {
apply: (cur, v) => cfg.sanitize({ ...cur, maxItems: v }),
},
displayLimit: {
// 界面显示条数 —— 只影响渲染层,不动数据库。运行时改完要通知所有窗口
// 重拉preload 的默认值才会跟着变(见 main.js settings:set 分支)。
apply: (cur, v) => cfg.sanitize({ ...cur, displayLimit: v }),
},
pollMs: {
apply: (cur, v) => cfg.sanitize({ ...cur, pollMs: v }),
},
hotkey: {
// 预设白名单校验在 cfg.sanitize 里(非法值回落默认 Ctrl+Alt+V
// 运行时的注册/解绑在 main.js settings:set 的 hotkey 分支,
// 那里才拿得到 globalShortcut。
apply: (cur, v) => cfg.sanitize({ ...cur, hotkey: v }),
},
// dataDir 刻意没有 handler更换目录必须走 settings:choose-dir
// (关库 → 搬文件 → 校验 → 改配置 → 重启)。只在这里改 config.dataDir
// 运行中的数据库连接仍指向旧目录 —— 内存与落盘分叉,重启后数据"消失"。
};
function applyPatch(current, { key, value }) {
const h = SETTINGS_HANDLERS[key];
if (!h) return { ...current };
return h.apply(current, value);
}
module.exports = { SETTINGS_HANDLERS, applyPatch };