From f4f823af7d44725684aee0d9c793f2021b198e94 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Wed, 21 Feb 2024 17:40:13 +0800 Subject: [PATCH 1/4] docs(features): add plugin-autostart --- src/content/docs/features/autostart.mdx | 134 +++++++++++++++++++++++- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/src/content/docs/features/autostart.mdx b/src/content/docs/features/autostart.mdx index c8069188c4..66d2338f76 100644 --- a/src/content/docs/features/autostart.mdx +++ b/src/content/docs/features/autostart.mdx @@ -3,12 +3,136 @@ title: Autostart description: Automatically launch your app at system startup. --- -import Stub from '@components/Stub.astro'; import PluginLinks from '@components/PluginLinks.astro'; +import { Tabs, TabItem } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; - - Based on - https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/autostart - +Automatically launch your application at system startup. + +Supports Windows, Mac (via AppleScript or Launch Agent), and Linux. + +## Setup + +Install the autostart plugin to get started. + + + + + Use your project's package manager to add the dependency: + + + + + + + 1. Run `cargo add tauri-plugin-autostart` to add the plugin to the project's dependencies in `Cargo.toml`. + + 2. Modify `lib.rs` to initialize the plugin: + + ```rust + // lib.rs + use tauri_plugin_autostart::MacosLauncher; + + #[cfg_attr(mobile, tauri::mobile_entry_point)] + fn run() { + tauri::Builder::default() + .plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]) /* arbitrary number of args to pass to your app */)) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. You can install the JavaScript Guest bindings using your preferred JavaScript package manager: + + + + + +## Usage + +The autostart plugin is available in both JavaScript and Rust. + + + + + ```js + import { enable, isEnabled, disable } from "@tauri-apps/plugin-autostart"; + + // Enable autostart + await enable(); + // Check enable state + console.log(`registered for autostart? ${await isEnabled()}`); + // Disable autostart + disable(); + ``` + + + + + ```rust + use tauri_plugin_autostart::MacosLauncher; + use tauri_plugin_autostart::ManagerExt; + + #[cfg_attr(mobile, tauri::mobile_entry_point)] + fn run() { + tauri::Builder::default() + .plugin(tauri_plugin_autostart::init( + MacosLauncher::LaunchAgent, + Some(vec!["--flag1", "--flag2"]), + )) + .setup(|app| { + // Get the autostart manager + let autostart_manager = app.autolaunch(); + // Enable autostart + let _ = autostart_manager.enable(); + // Check enable state + println!("registered for autostart? {}", autostart_manager.is_enabled().unwrap()); + // Disable autostart + let _ = autostart_manager.disable(); + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + + + +## Permissions + +By default all plugin commands are blocked and cannot be accessed. +You must define a list of permissions in your `capabilities` configuration. + +See [Access Control List](/references/v2/acl) for more information. + +`src-tauri/capabilities/main.json` + +```json +{ + "permissions": [ + ..., + "autostart:allow-enable", + "autostart:allow-disable", + "autostart:allow-is-enabled" + ] +} +``` + +| Permission | Description | +| --- | --- | +| `autostart:allow-disable` | Enables the disable command without any pre-configured scope. | +| `autostart:deny-disable` | Denies the disable command without any pre-configured scope. | +| `autostart:allow-enable` | Enables the enable command without any pre-configured scope. | +| `autostart:deny-enable` | Denies the enable command without any pre-configured scope. | +| `autostart:allow-is-enabled` | Enables the is_enabled command without any pre-configured scope. | +| `autostart:deny-is-enabled` | Denies the is_enabled command without any pre-configured scope. | From 9def00e5fe8e9d504a877491eb8581ff94b800a3 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Wed, 21 Feb 2024 20:46:45 +0800 Subject: [PATCH 2/4] Update src/content/docs/features/autostart.mdx Co-authored-by: Vitor Ayres --- src/content/docs/features/autostart.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/content/docs/features/autostart.mdx b/src/content/docs/features/autostart.mdx index 66d2338f76..d78871522d 100644 --- a/src/content/docs/features/autostart.mdx +++ b/src/content/docs/features/autostart.mdx @@ -115,9 +115,7 @@ You must define a list of permissions in your `capabilities` configuration. See [Access Control List](/references/v2/acl) for more information. -`src-tauri/capabilities/main.json` - -```json +```json title="src-tauri/capabilities/main.json" { "permissions": [ ..., From 15b5b27c9ac0c2bdffbcdc2b5e56846806146899 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Wed, 21 Feb 2024 20:46:52 +0800 Subject: [PATCH 3/4] Update src/content/docs/features/autostart.mdx Co-authored-by: Vitor Ayres --- src/content/docs/features/autostart.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/content/docs/features/autostart.mdx b/src/content/docs/features/autostart.mdx index d78871522d..f0cdf299a6 100644 --- a/src/content/docs/features/autostart.mdx +++ b/src/content/docs/features/autostart.mdx @@ -34,8 +34,7 @@ Install the autostart plugin to get started. 2. Modify `lib.rs` to initialize the plugin: - ```rust - // lib.rs + ```rust title="lib.rs" ins={1, 6} use tauri_plugin_autostart::MacosLauncher; #[cfg_attr(mobile, tauri::mobile_entry_point)] From a09ebd5eeccd8127220b6e7c799767dcd7b27bc0 Mon Sep 17 00:00:00 2001 From: Vitor Ayres Date: Wed, 28 Feb 2024 22:28:58 -0300 Subject: [PATCH 4/4] add Supported Platform heading --- src/content/docs/features/autostart.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/content/docs/features/autostart.mdx b/src/content/docs/features/autostart.mdx index f0cdf299a6..3a15865445 100644 --- a/src/content/docs/features/autostart.mdx +++ b/src/content/docs/features/autostart.mdx @@ -11,7 +11,11 @@ import CommandTabs from '@components/CommandTabs.astro'; Automatically launch your application at system startup. -Supports Windows, Mac (via AppleScript or Launch Agent), and Linux. +## Supported Platforms + +- Windows +- Mac (via AppleScript or Launch Agent) +- Linux ## Setup