From 71b88e0a221478a925b562559eadaeb1837077d1 Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Mon, 17 Feb 2025 21:51:44 -0500 Subject: [PATCH] feat(desktop): add autostart (#137) * feat(desktop): add Tauri autostart plugin and update launch at login settings * chore(ci): update beta build workflow defaults and matrix generation --- .github/workflows/beta-build.yml | 12 +++---- Cargo.lock | 35 +++++++++++++++++++ apps/desktop/package.json | 1 + apps/desktop/src-tauri/Cargo.toml | 1 + .../src-tauri/capabilities/default.json | 5 ++- apps/desktop/src-tauri/src/lib.rs | 12 +++++-- .../standalone/general-settings.svelte | 33 +++++++++++++---- apps/desktop/src/lib/stores/appConfig.ts | 1 - apps/desktop/src/routes/app/+layout.svelte | 2 -- packages/types/src/appConfig.ts | 1 - pnpm-lock.yaml | 10 ++++++ 11 files changed, 94 insertions(+), 19 deletions(-) diff --git a/.github/workflows/beta-build.yml b/.github/workflows/beta-build.yml index c5a4c72..ea81131 100644 --- a/.github/workflows/beta-build.yml +++ b/.github/workflows/beta-build.yml @@ -12,27 +12,27 @@ on: description: "Enable updater?" required: true type: boolean - default: true + default: false platform_windows: description: "windows" required: true type: boolean - default: true + default: false platform_linux: description: "linux" required: true type: boolean - default: true + default: false platform_macos_aarch64: description: "macos-aarch64" required: true type: boolean - default: true + default: false platform_macos_x86_64: description: "macos-x86_64" required: true type: boolean - default: true + default: false isDebug: description: "is debug?" required: true @@ -93,7 +93,7 @@ jobs: id: setting run: | matrix="" - if [ "${{ github.event_name }}" == "schedule" ]; then + if [ "${{ github.event_name }}" == "schedule" ] || [ "${{ github.event_name }}" == "pull_request" ]; then matrix="\"windows-latest\",\"ubuntu-22.04\",\"macos-14\",\"macos-13\"" build_mode="" build_path="release" diff --git a/Cargo.lock b/Cargo.lock index beab13c..a0a409a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,6 +481,17 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "auto-launch" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471" +dependencies = [ + "dirs 4.0.0", + "thiserror 1.0.66", + "winreg 0.10.1", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -3789,6 +3800,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-autostart", "tauri-plugin-cli", "tauri-plugin-clipboard", "tauri-plugin-deep-link", @@ -7367,6 +7379,20 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-autostart" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c13f843e5e5df3eed270fc42b02923cc1a6b5c7e56b0f3ac1d858ab2c8b5fb" +dependencies = [ + "auto-launch", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.3", +] + [[package]] name = "tauri-plugin-cli" version = "2.0.1" @@ -9481,6 +9507,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "winreg" version = "0.50.0" diff --git a/apps/desktop/package.json b/apps/desktop/package.json index f0d8803..84f0cba 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -26,6 +26,7 @@ "@supabase/supabase-js": "^2.48.0", "@tanstack/table-core": "^8.20.5", "@tauri-apps/api": "^2.1.1", + "@tauri-apps/plugin-autostart": "^2.2.0", "@tauri-apps/plugin-shell": "^2.2.0", "@tauri-apps/plugin-stronghold": "^2.2.0", "dompurify": "^3.2.3", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index a982bd6..7b6b186 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -66,6 +66,7 @@ objc = "0.2.7" [target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies] +tauri-plugin-autostart = "2" tauri-plugin-cli = "2" tauri-plugin-global-shortcut = "2.0.1" tauri-plugin-single-instance = { version = "2", features = ["deep-link"] } diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json index ddcfd4b..404d595 100644 --- a/apps/desktop/src-tauri/capabilities/default.json +++ b/apps/desktop/src-tauri/capabilities/default.json @@ -164,6 +164,9 @@ } ] }, - "deep-link:default" + "deep-link:default", + "autostart:allow-enable", + "autostart:allow-disable", + "autostart:allow-is-enabled" ] } diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 38fb2e1..76ead7c 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -7,12 +7,16 @@ use log; #[cfg(target_os = "macos")] use tauri::ActivationPolicy; use tauri::Manager; +use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_jarvis::{ - constants::KUNKUN_PUBLISH, db::JarvisDB, server::Protocol, utils::{ + constants::KUNKUN_PUBLISH, + db::JarvisDB, + server::Protocol, + utils::{ path::{get_default_extensions_dir, get_kunkun_db_path}, settings::AppSettings, - } + }, }; use tauri_plugin_keyring::KeyringExt; pub use tauri_plugin_log::fern::colors::ColoredLevelConfig; @@ -97,6 +101,10 @@ pub fn run() { .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_process::init()) + .plugin(tauri_plugin_autostart::init( + MacosLauncher::LaunchAgent, + Some(vec![]), + )) .plugin(tauri_plugin_upload::init()) .plugin(tauri_plugin_store::Builder::default().build()) .plugin(tauri_plugin_global_shortcut::Builder::new().build()) diff --git a/apps/desktop/src/lib/components/standalone/general-settings.svelte b/apps/desktop/src/lib/components/standalone/general-settings.svelte index 7978c44..52ebc46 100644 --- a/apps/desktop/src/lib/components/standalone/general-settings.svelte +++ b/apps/desktop/src/lib/components/standalone/general-settings.svelte @@ -11,21 +11,42 @@ } from "@/paraglide/runtime" import { appConfig } from "@/stores" import { Select, Switch } from "@kksh/svelte5" + import * as autoStart from "@tauri-apps/plugin-autostart" + import { onMount } from "svelte" + import { toast } from "svelte-sonner" const languages = availableLanguageTags.map((lang) => ({ value: lang, label: LanguageMap[lang] ?? lang })) - - let value = $state(languageTag()) - - const triggerContent = $derived(languages.find((f) => f.value === value)?.label ?? "Language") + let launchAtLogin = $state(false) + let language = $state(languageTag()) + onMount(() => { + autoStart.isEnabled().then((enabled) => { + launchAtLogin = enabled + }) + }) + const triggerContent = $derived(languages.find((f) => f.value === language)?.label ?? "Language")