mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-06 20:02:49 +08:00
feat: 开机自启功能(tauri-plugin-autostart)
- Cargo.toml: 添加 tauri-plugin-autostart 依赖(桌面端) - lib.rs: 初始化 autostart 插件(MacosLauncher::LaunchAgent) - capabilities/default.json: 添加 autostart 权限 - settings.js: 面板设置新增开机自启开关(仅 Tauri 模式显示) - package.json: 添加 @tauri-apps/plugin-autostart 前端依赖
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -1,15 +1,16 @@
|
||||
{
|
||||
"name": "clawpanel",
|
||||
"version": "0.7.2",
|
||||
"version": "0.9.9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "clawpanel",
|
||||
"version": "0.7.2",
|
||||
"version": "0.9.9",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.5.0",
|
||||
"@tauri-apps/plugin-autostart": "^2.5.1",
|
||||
"@tauri-apps/plugin-shell": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -1036,6 +1037,15 @@
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-autostart": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-autostart/-/plugin-autostart-2.5.1.tgz",
|
||||
"integrity": "sha512-zS/xx7yzveCcotkA+8TqkI2lysmG2wvQXv2HGAVExITmnFfHAdj1arGsbbfs3o6EktRHf6l34pJxc3YGG2mg7w==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-shell": {
|
||||
"version": "2.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-shell/-/plugin-shell-2.3.5.tgz",
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.5.0",
|
||||
"@tauri-apps/plugin-autostart": "^2.5.1",
|
||||
"@tauri-apps/plugin-shell": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -32,3 +32,6 @@ base64 = "0.22"
|
||||
urlencoding = "2"
|
||||
regex = "1"
|
||||
tokio = { version = "1", features = ["process", "time"] }
|
||||
|
||||
[target.'cfg(any(target_os = "macos", windows, target_os = "linux"))'.dependencies]
|
||||
tauri-plugin-autostart = "2"
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"shell:allow-open"
|
||||
"shell:allow-open",
|
||||
"autostart:allow-enable",
|
||||
"autostart:allow-disable",
|
||||
"autostart:allow-is-enabled"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ pub fn run() {
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
|
||||
None,
|
||||
))
|
||||
.register_uri_scheme_protocol("tauri", move |ctx, request| {
|
||||
let uri_path = request.uri().path();
|
||||
let path = if uri_path == "/" || uri_path.is_empty() {
|
||||
|
||||
@@ -61,6 +61,11 @@ export async function render() {
|
||||
<div id="language-bar"></div>
|
||||
</div>
|
||||
|
||||
${window.__TAURI_INTERNALS__ ? `<div class="config-section" id="autostart-section">
|
||||
<div class="config-section-title">${t('settings.autostart') || '开机自启'}</div>
|
||||
<div id="autostart-bar"><div class="stat-card loading-placeholder" style="height:48px"></div></div>
|
||||
</div>` : ''}
|
||||
|
||||
`
|
||||
|
||||
bindEvents(page)
|
||||
@@ -71,6 +76,7 @@ export async function render() {
|
||||
async function loadAll(page) {
|
||||
const tasks = [loadProxyConfig(page), loadModelProxyConfig(page), loadOpenclawDir(page), loadCliBinding(page)]
|
||||
tasks.push(loadRegistry(page))
|
||||
if (window.__TAURI_INTERNALS__) tasks.push(loadAutostart(page))
|
||||
await Promise.all(tasks)
|
||||
loadLanguageSwitcher(page)
|
||||
}
|
||||
@@ -449,3 +455,41 @@ function loadLanguageSwitcher(page) {
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 开机自启 =====
|
||||
|
||||
async function loadAutostart(page) {
|
||||
const bar = page.querySelector('#autostart-bar')
|
||||
if (!bar) return
|
||||
try {
|
||||
const { isEnabled, enable, disable } = await import('@tauri-apps/plugin-autostart')
|
||||
const enabled = await isEnabled()
|
||||
bar.innerHTML = `
|
||||
<div style="display:flex;align-items:center;gap:var(--space-sm)">
|
||||
<label style="display:flex;align-items:center;gap:6px;font-size:var(--font-size-sm);cursor:pointer">
|
||||
<input type="checkbox" id="autostart-toggle" ${enabled ? 'checked' : ''}>
|
||||
${t('settings.autostartToggle') || '系统启动时自动运行 ClawPanel'}
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-hint" style="margin-top:var(--space-xs)">
|
||||
${t('settings.autostartHint') || '开启后,电脑重启时 ClawPanel 会自动启动并检测 Gateway 状态'}
|
||||
</div>
|
||||
`
|
||||
bar.querySelector('#autostart-toggle')?.addEventListener('change', async (e) => {
|
||||
try {
|
||||
if (e.target.checked) {
|
||||
await enable()
|
||||
toast(t('settings.autostartEnabled') || '已开启开机自启', 'success')
|
||||
} else {
|
||||
await disable()
|
||||
toast(t('settings.autostartDisabled') || '已关闭开机自启', 'success')
|
||||
}
|
||||
} catch (err) {
|
||||
e.target.checked = !e.target.checked
|
||||
toast((t('settings.autostartFailed') || '设置失败') + ': ' + err, 'error')
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
bar.innerHTML = `<div style="color:var(--text-tertiary);font-size:var(--font-size-sm)">${t('settings.autostartUnavailable') || '当前环境不支持开机自启'}</div>`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user