From 07c083d9a18ed268ddd603963e8c3f20d4c66326 Mon Sep 17 00:00:00 2001 From: baiqing Date: Mon, 4 May 2026 07:33:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(autostart):=20toggle=20=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=BB=99=E7=94=A8=E6=88=B7=E7=9C=8B=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E5=90=9E=E5=88=B0=20console=20(#194)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原版 AutostartRow 的 onToggle catch 只 console.error + 回滚, 失败完全不在 UI 上反馈:Windows 写 HKCU\Run 被组策略拦、 macOS LaunchAgent plist 写入失败 这些真实场景下,用户只看到 toggle 弹回去,根本不知道为什么。 补一个 error state: - onToggle 进入清 null,catch 里 setError(message)。 - SettingRow children 改成 flex column:toggle 上面、错误小字下面。 - 配色 var(--ol-err) 跟 about 卡片的 update error 同款。 - i18n 加 settings.recording.startupAtBootError,{{message}} 插 入插件抛的具体错。 不动 isEnabled 失败路径(#194 验收没列);不动 prefs 持久化 策略(仍由 OS 持有真相)。 --- openless-all/app/src/i18n/en.ts | 1 + openless-all/app/src/i18n/zh-CN.ts | 1 + openless-all/app/src/pages/Settings.tsx | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/openless-all/app/src/i18n/en.ts b/openless-all/app/src/i18n/en.ts index 8b408236..9c65ace3 100644 --- a/openless-all/app/src/i18n/en.ts +++ b/openless-all/app/src/i18n/en.ts @@ -268,6 +268,7 @@ export const en: typeof zhCN = { restoreClipboardDesc: 'Windows / Linux only: restore your original clipboard after a successful paste (default on). Turn off to keep the dictation text in the clipboard so you can manually Ctrl+V if the simulated paste did not actually land. See issue #111.', startupAtBoot: 'Launch at login', startupAtBootDesc: 'Start OpenLess automatically when you sign in. macOS uses a LaunchAgent, Linux writes ~/.config/autostart, Windows writes HKCU\\Run (no admin required). See issue #194.', + startupAtBootError: 'Failed to toggle launch at login: {{message}}', }, providers: { llmTitle: 'LLM (polishing)', diff --git a/openless-all/app/src/i18n/zh-CN.ts b/openless-all/app/src/i18n/zh-CN.ts index 825d56d8..402961ab 100644 --- a/openless-all/app/src/i18n/zh-CN.ts +++ b/openless-all/app/src/i18n/zh-CN.ts @@ -266,6 +266,7 @@ export const zhCN = { restoreClipboardDesc: '仅 Windows / Linux:粘贴成功后恢复你原来的剪贴板内容(默认开)。关掉就把听写文本留在剪贴板,模拟粘贴没真正落地时可以手动 Ctrl+V 找回。详见 issue #111。', startupAtBoot: '开机自启', startupAtBootDesc: '登录后自动启动 OpenLess。macOS 写 LaunchAgent,Linux 写 ~/.config/autostart,Windows 写 HKCU\\Run(不需要管理员)。详见 issue #194。', + startupAtBootError: '开机自启切换失败:{{message}}', }, providers: { llmTitle: 'LLM 模型(润色)', diff --git a/openless-all/app/src/pages/Settings.tsx b/openless-all/app/src/pages/Settings.tsx index de370263..7795c0e6 100644 --- a/openless-all/app/src/pages/Settings.tsx +++ b/openless-all/app/src/pages/Settings.tsx @@ -248,6 +248,10 @@ function AutostartRow() { const { t } = useTranslation(); const [enabled, setEnabled] = useState(false); const [loaded, setLoaded] = useState(false); + // 切 plist / 注册表失败时给用户看的错误。null = 没有失败/上次操作已成功。 + // 不渲染等于把失败吞掉 —— Windows 写 HKCU\Run 被组策略拦、macOS 写 + // LaunchAgent plist 权限不够 都是真实可能。issue #194。 + const [error, setError] = useState(null); useEffect(() => { let cancelled = false; @@ -269,12 +273,14 @@ function AutostartRow() { const onToggle = async (next: boolean) => { setEnabled(next); + setError(null); try { if (next) await enableAutostart(); else await disableAutostart(); } catch (err) { console.error('[autostart] toggle failed', err); setEnabled(!next); + setError(err instanceof Error ? err.message : String(err)); } }; @@ -283,7 +289,14 @@ function AutostartRow() { label={t('settings.recording.startupAtBoot')} desc={t('settings.recording.startupAtBootDesc')} > - {loaded ? : null} +
+ {loaded ? : null} + {error && ( +
+ {t('settings.recording.startupAtBootError', { message: error })} +
+ )} +
); }