Files
Clipboard/lib/settings-handlers.js
2026-09-12 13:59:12 +08:00

37 lines
1.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'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 };