feat: 添加开机自启支持与开发版本提示

This commit is contained in:
Yuhang Wu
2026-10-22 16:36:11 +08:00
parent fcab06d28f
commit ffd0ef7935
10 changed files with 77 additions and 13 deletions
+6
View File
@@ -1,4 +1,10 @@
import { isTauri } from "@/utils/window"
import { invoke } from "@tauri-apps/api/core"
export async function isAutostartSupported(): Promise<boolean> {
if (!isTauri()) return false
return invoke<boolean>("is_autostart_supported")
}
/**
* 开机自启封装(Tauri 官方 autostart 插件)。
+1
View File
@@ -88,6 +88,7 @@
"autostart": "Launch at startup",
"autostartTip": "Start FrpcPilot automatically after you sign in. The switch writes straight to the system startup entry.",
"autostartUnsupported": "System startup entries are not accessible here, so this setting is unavailable.",
"autostartRequiresRelease": "Enable launch at startup in a release build. Development builds require a local server and cannot run independently after a restart.",
"autostartEnabled": "Launch at startup enabled",
"autostartDisabled": "Launch at startup disabled",
"autostartFailed": "Failed to update launch at startup: {message}",
+1
View File
@@ -88,6 +88,7 @@
"autostart": "开机自启",
"autostartTip": "登录系统后自动启动 FrpcPilot,开关状态直接写入系统启动项",
"autostartUnsupported": "当前环境无法读写系统启动项,暂不支持该设置",
"autostartRequiresRelease": "请在正式构建的应用中开启自启;开发版本依赖本地服务,无法在重启后独立运行",
"autostartEnabled": "已开启开机自启",
"autostartDisabled": "已关闭开机自启",
"autostartFailed": "设置开机自启失败:{message}",
+10 -3
View File
@@ -1,7 +1,7 @@
import { defineStore } from "pinia"
import { message } from "ant-design-vue"
import { isTauri } from "@/utils/window"
import { isAutostartEnabled, setAutostartEnabled } from "@/api/autostart"
import { isAutostartEnabled, isAutostartSupported, setAutostartEnabled } from "@/api/autostart"
import { translate } from "@/i18n"
/**
@@ -17,7 +17,8 @@ export const useAutostartStore = defineStore("autostart", () => {
/** 读取 / 写入系统启动项期间显示加载态,同时防止重复操作 */
const loading = ref(isTauri())
/** 当前环境能否读写系统启动项 */
const supported = ref(isTauri())
const supported = ref(false)
const requiresRelease = ref(false)
function errMsg(e: unknown) {
return e instanceof Error ? e.message : String(e)
@@ -28,6 +29,12 @@ export const useAutostartStore = defineStore("autostart", () => {
if (!isTauri()) return
loading.value = true
try {
requiresRelease.value = !(await isAutostartSupported())
if (requiresRelease.value) {
enabled.value = false
supported.value = false
return
}
enabled.value = await isAutostartEnabled()
supported.value = true
} catch {
@@ -61,5 +68,5 @@ export const useAutostartStore = defineStore("autostart", () => {
}
}
return { enabled, loading, supported, refresh, toggle }
return { enabled, loading, supported, requiresRelease, refresh, toggle }
})
+5 -3
View File
@@ -81,9 +81,11 @@ const languageRadios = languageOptions.map((item) => ({ label: item.label, value
/** 无法访问系统启动项时(非桌面环境)给出说明,避免开关无故置灰 */
const autostartTip = computed(() =>
autostartStore.supported
? t("settings.general.autostartTip")
: t("settings.general.autostartUnsupported"),
autostartStore.requiresRelease
? t("settings.general.autostartRequiresRelease")
: autostartStore.supported
? t("settings.general.autostartTip")
: t("settings.general.autostartUnsupported"),
)
/** 切换开机自启:失败时由 store 回滚开关状态并提示原因 */