Skip to content

feat(autostart): macOS / Linux / Windows 三平台开机自启#217

Merged
H-Chris233 merged 2 commits into
mainfrom
feat/autostart-194
May 4, 2026
Merged

feat(autostart): macOS / Linux / Windows 三平台开机自启#217
H-Chris233 merged 2 commits into
mainfrom
feat/autostart-194

Conversation

@appergb
Copy link
Copy Markdown
Collaborator

@appergb appergb commented May 3, 2026

User description

Closes #194

Summary

  • 设置页 → 录制 区追加「开机自启」Toggle
  • 三平台都用 Tauri 官方 tauri-plugin-autostart,零自写:
    • macOS:~/Library/LaunchAgents/com.openless.app.plist(LaunchAgent)
    • Linux:~/.config/autostart/openless.desktop(XDG)
    • Windows:HKCU\Software\Microsoft\Windows\CurrentVersion\Run(per-user,不需 admin)
  • 状态以 OS 为唯一真相:直接调 isEnabled / enable / disable,不写 prefs(避免缓存与系统设置不一致)

改动

Backend

  • Cargo.toml:加 tauri-plugin-autostart = \"2\"
  • lib.rs:注册插件 tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, None)
  • capabilities/default.json:加 \"autostart:default\"

Frontend

  • package.json:加 @tauri-apps/plugin-autostart
  • Settings.tsx:新增 <AutostartRow /> 子组件(mount 时读 OS 真值,toggle 失败回滚)
  • i18n/zh-CN.ts / en.ts:在 settings.recording 节点加 startupAtBoot + startupAtBootDesc

settings.personalize.startupAtBoot 是孤儿 key(personalize section 没渲染),未删除以保持 surgical。

关于 millionart 的「别走注册表」评论

插件无内置的 startup-folder .lnk 模式。HKCU\Run 是 Microsoft 文档化的 per-user 标准方式、不需要管理员,本 issue 验收标准("用户可设置开机启动")已满足。如必须走 .lnk,单独追加 follow-up(需要自己写 Windows 子流程)。

验证

  • cargo check 通过
  • npm run build (tsc + vite) 通过
  • 用户侧手测:
    • macOS:toggle ON → ls ~/Library/LaunchAgents/ | grep openless,重启或注销 / 登录后 OpenLess 自启
    • Linux:toggle ON → ls ~/.config/autostart/,重新登录后自启
    • Windows:toggle ON → reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\" 看到 OpenLess,重登后自启
    • toggle OFF 后对应记录消失

PR Type

Enhancement


Description

  • Add cross-platform autostart toggle in Settings

  • Use OS as source of truth for state

  • Show error message if toggle fails

  • Register tauri-plugin-autostart and grant permissions


Diagram Walkthrough

flowchart LR
  A["User toggles autostart"] -- "onToggle" --> B["AutostartRow component"]
  B -- "enable/disable" --> C["tauri-plugin-autostart"]
  C -- "writes" --> D["OS (LaunchAgent/XDG/Registry)"]
  C -- "on error" --> E["Set error state"]
  E -- "shows" --> F["Error message in UI"]
  B -- "on mount" --> G["isEnabled check"]
  G -- "reads" --> D
Loading

File Walkthrough

Relevant files
Enhancement
4 files
lib.rs
Register autostart plugin init                                                     
+7/-0     
en.ts
Add autostart i18n keys in English                                             
+3/-0     
zh-CN.ts
Add autostart i18n keys in Chinese                                             
+3/-0     
Settings.tsx
Implement AutostartRow with error feedback                             
+61/-0   
Dependencies
2 files
package.json
Add @tauri-apps/plugin-autostart dependency                           
+1/-0     
Cargo.toml
Add tauri-plugin-autostart crate                                                 
+1/-0     
Configuration changes
1 files
default.json
Grant autostart:default permission                                             
+2/-1     

接入官方 tauri-plugin-autostart:
- macOS:~/Library/LaunchAgents/com.openless.app.plist (LaunchAgent)
- Linux:~/.config/autostart/openless.desktop (XDG)
- Windows:HKCU\Software\Microsoft\Windows\CurrentVersion\Run (per-user,
  不需要 admin)

设置页 → 录制 区追加「开机自启」Toggle;状态以 OS 为唯一真相,
直接调插件 isEnabled / enable / disable,不进 prefs,避免缓存
与系统设置不一致。

Closes #194
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

PR Reviewer Guide 🔍

(Review updated until commit 07c083d)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

194 - PR Code Verified

Compliant requirements:

  • Windows 下能开机启动
  • 用户能设置是否开启

Requires further human verification:

  • Windows 下能开机启动(需在真实各平台环境手动测试)
  • 用户能设置是否开启(需手动测试 toggle 功能在各平台的表现)
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

原版 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 持有真相)。
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Persistent review updated to latest commit 07c083d

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Persistent review updated to latest commit 570a3a4

@appergb appergb force-pushed the feat/autostart-194 branch from 570a3a4 to 07c083d Compare May 3, 2026 23:54
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit 07c083d

@H-Chris233 H-Chris233 merged commit bdd4cb1 into main May 4, 2026
4 checks passed
@appergb appergb deleted the feat/autostart-194 branch May 6, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[area] window缺少随机启动功能

2 participants