fix(autostart): toggle 失败给用户看错误,不再吞到 console (#194)
原版 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 持有真相)。
This commit is contained in:
1 parent
e5608db21e
commit
07c083d9a1
3 files changed
+16
-1
No files matched your search
@@ -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)',
|
||||
|
||||
@@ -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 模型(润色)',
|
||||
|
||||
@@ -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<string | null>(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 ? <Toggle on={enabled} onToggle={onToggle} /> : null}
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
{loaded ? <Toggle on={enabled} onToggle={onToggle} /> : null}
|
||||
{error && (
|
||||
<div style={{ fontSize: 11, color: 'var(--ol-err)', marginTop: 4, lineHeight: 1.5 }}>
|
||||
{t('settings.recording.startupAtBootError', { message: error })}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</SettingRow>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user