feat(console): 开机自启默认关闭,服务管理窗口加手动开关

- DEFAULTS.startup.openAtLogin 与随包 config.json 默认改为 false;
  applyOpenAtLogin 只有显式 true 才注册登录项(缺省/null/false 都不注册)
- config.js 新增 updateConfig():只写回文件里已有的键 + 目标键,不把 DEFAULTS 落盘
- 主进程 setOpenAtLogin():改内存 → 写回 config.json → setLoginItemSettings,
  任一失败都回滚,返回 {ok, openAtLogin};状态快照新增 openAtLogin / openAtLoginSupported
- 渲染层:服务端状态卡片新增「开机自启」滑块(纯 CSS,无依赖),
  切换即时生效并有本地意图守卫,避免被随后到达的陈旧快照冲掉
- 文档:console/README.md 与 docs/部署指南.md 同步

注意:旧包 config.json 里已显式写 true 的用户升级后仍会自启(不悄悄改既有行为),
在窗口里关一次即可;全新安装默认不注册。
This commit is contained in:
AskaEth committed 2026-09-10 00:06:59 +08:00
1 parent 7c59dba9b9
commit 1b78c38bb8
9 files changed
+204 -12

No files matched your search

+14 -3
View File
@@ -39,8 +39,8 @@ const DEFAULTS = {
backgroundColor: '#0b0f1a'
},
startup: {
// 打包后随系统启动(doc 10 §4.3);开发态不注册
openAtLogin: true
// 默认不随系统启动;服务管理窗口里有开关,打开后写入登录项
openAtLogin: false
},
admin: {
width: 1040,
@@ -86,6 +86,17 @@ function loadConfig(configPath) {
}
}
// 就地改配置并写回文件:只动 raw 里已有的键,不把 DEFAULTS 全量落盘,
// 否则升级新增的默认值会被老文件冻结成显式值。
function updateConfig(configPath, mutate) {
const { values } = readJson(configPath)
const raw = isPlainObject(values) ? values : {}
mutate(raw)
fs.mkdirSync(path.dirname(configPath), { recursive: true })
fs.writeFileSync(configPath, JSON.stringify(raw, null, 2) + '\n', 'utf8')
return raw
}
// 相对路径的 exe 需要按「部署包根目录」理解,而部署包根目录在不同形态下不同:
// 开发时是 console/ 的上级,打包后是 exe 所在目录。逐个候选位置探测,避免写死。
function resolveExecutable(exe, configPath) {
@@ -104,4 +115,4 @@ function resolveExecutable(exe, configPath) {
return { path: found || candidates[0], candidates: [...new Set(candidates)] }
}
module.exports = { loadConfig, resolveExecutable }
module.exports = { loadConfig, updateConfig, resolveExecutable }