From 16f2c30e25d62cf7bcf6d7debee74e6f3011d093 Mon Sep 17 00:00:00 2001 From: ayang <473033518@qq.com> Date: Mon, 21 Apr 2025 20:45:35 +0800 Subject: [PATCH 1/2] feat: add the ability to check if the app is autostart --- plugins/autostart/build.rs | 2 +- plugins/autostart/guest-js/index.ts | 4 +++ .../autogenerated/commands/is_autostart.toml | 13 +++++++++ .../permissions/autogenerated/reference.md | 27 +++++++++++++++++++ plugins/autostart/permissions/default.toml | 2 +- .../autostart/permissions/schemas/schema.json | 16 +++++++++-- plugins/autostart/src/lib.rs | 18 ++++++++++++- 7 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 plugins/autostart/permissions/autogenerated/commands/is_autostart.toml diff --git a/plugins/autostart/build.rs b/plugins/autostart/build.rs index 1460469b5c..ded10e5b98 100644 --- a/plugins/autostart/build.rs +++ b/plugins/autostart/build.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"]; +const COMMANDS: &[&str] = &["enable", "disable", "is_enabled", "is_autostart"]; fn main() { tauri_plugin::Builder::new(COMMANDS) diff --git a/plugins/autostart/guest-js/index.ts b/plugins/autostart/guest-js/index.ts index fca8344ffc..5caf7c5813 100644 --- a/plugins/autostart/guest-js/index.ts +++ b/plugins/autostart/guest-js/index.ts @@ -15,3 +15,7 @@ export async function enable(): Promise { export async function disable(): Promise { await invoke('plugin:autostart|disable') } + +export async function isAutostart(): Promise { + await invoke('plugin:autostart|is_autostart') +} \ No newline at end of file diff --git a/plugins/autostart/permissions/autogenerated/commands/is_autostart.toml b/plugins/autostart/permissions/autogenerated/commands/is_autostart.toml new file mode 100644 index 0000000000..f4d8496192 --- /dev/null +++ b/plugins/autostart/permissions/autogenerated/commands/is_autostart.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-is-autostart" +description = "Enables the is_autostart command without any pre-configured scope." +commands.allow = ["is_autostart"] + +[[permission]] +identifier = "deny-is-autostart" +description = "Denies the is_autostart command without any pre-configured scope." +commands.deny = ["is_autostart"] diff --git a/plugins/autostart/permissions/autogenerated/reference.md b/plugins/autostart/permissions/autogenerated/reference.md index 6adb2be403..fb0afd4d0a 100644 --- a/plugins/autostart/permissions/autogenerated/reference.md +++ b/plugins/autostart/permissions/autogenerated/reference.md @@ -16,6 +16,7 @@ disable the automatic start on boot. - `allow-enable` - `allow-disable` - `allow-is-enabled` +- `allow-is-autostart` ## Permission Table @@ -81,6 +82,32 @@ Denies the enable command without any pre-configured scope. +`autostart:allow-is-autostart` + + + + +Enables the is_autostart command without any pre-configured scope. + + + + + + + +`autostart:deny-is-autostart` + + + + +Denies the is_autostart command without any pre-configured scope. + + + + + + + `autostart:allow-is-enabled` diff --git a/plugins/autostart/permissions/default.toml b/plugins/autostart/permissions/default.toml index a2ac766fde..225ace93c8 100644 --- a/plugins/autostart/permissions/default.toml +++ b/plugins/autostart/permissions/default.toml @@ -12,4 +12,4 @@ disable the automatic start on boot. """ -permissions = ["allow-enable", "allow-disable", "allow-is-enabled"] +permissions = ["allow-enable", "allow-disable", "allow-is-enabled", "allow-is-autostart"] diff --git a/plugins/autostart/permissions/schemas/schema.json b/plugins/autostart/permissions/schemas/schema.json index af681221fe..81e05fc300 100644 --- a/plugins/autostart/permissions/schemas/schema.json +++ b/plugins/autostart/permissions/schemas/schema.json @@ -318,6 +318,18 @@ "const": "deny-enable", "markdownDescription": "Denies the enable command without any pre-configured scope." }, + { + "description": "Enables the is_autostart command without any pre-configured scope.", + "type": "string", + "const": "allow-is-autostart", + "markdownDescription": "Enables the is_autostart command without any pre-configured scope." + }, + { + "description": "Denies the is_autostart command without any pre-configured scope.", + "type": "string", + "const": "deny-is-autostart", + "markdownDescription": "Denies the is_autostart command without any pre-configured scope." + }, { "description": "Enables the is_enabled command without any pre-configured scope.", "type": "string", @@ -331,10 +343,10 @@ "markdownDescription": "Denies the is_enabled command without any pre-configured scope." }, { - "description": "This permission set configures if your\napplication can enable or disable auto\nstarting the application on boot.\n\n#### Granted Permissions\n\nIt allows all to check, enable and\ndisable the automatic start on boot.\n\n\n#### This default permission set includes:\n\n- `allow-enable`\n- `allow-disable`\n- `allow-is-enabled`", + "description": "This permission set configures if your\napplication can enable or disable auto\nstarting the application on boot.\n\n#### Granted Permissions\n\nIt allows all to check, enable and\ndisable the automatic start on boot.\n\n\n#### This default permission set includes:\n\n- `allow-enable`\n- `allow-disable`\n- `allow-is-enabled`\n- `allow-is-autostart`", "type": "string", "const": "default", - "markdownDescription": "This permission set configures if your\napplication can enable or disable auto\nstarting the application on boot.\n\n#### Granted Permissions\n\nIt allows all to check, enable and\ndisable the automatic start on boot.\n\n\n#### This default permission set includes:\n\n- `allow-enable`\n- `allow-disable`\n- `allow-is-enabled`" + "markdownDescription": "This permission set configures if your\napplication can enable or disable auto\nstarting the application on boot.\n\n#### Granted Permissions\n\nIt allows all to check, enable and\ndisable the automatic start on boot.\n\n\n#### This default permission set includes:\n\n- `allow-enable`\n- `allow-disable`\n- `allow-is-enabled`\n- `allow-is-autostart`" } ] } diff --git a/plugins/autostart/src/lib.rs b/plugins/autostart/src/lib.rs index 83cac89c41..fdd7ab8dc6 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -98,6 +98,17 @@ async fn is_enabled(manager: State<'_, AutoLaunchManager>) -> Result { manager.is_enabled() } +#[command] +async fn is_autostart(manager: State<'_, AutoLaunchManager>) -> Result { + let process_args: Vec = std::env::args().collect(); + + let passed_args = manager.0.get_args(); + + let is_autostart = passed_args.iter().all(|arg| process_args.contains(arg)); + + Ok(is_autostart) +} + #[derive(Default)] pub struct Builder { #[cfg(target_os = "macos")] @@ -156,7 +167,12 @@ impl Builder { pub fn build(self) -> TauriPlugin { PluginBuilder::new("autostart") - .invoke_handler(tauri::generate_handler![enable, disable, is_enabled]) + .invoke_handler(tauri::generate_handler![ + enable, + disable, + is_enabled, + is_autostart + ]) .setup(move |app, _api| { let mut builder = AutoLaunchBuilder::new(); builder.set_app_name(&app.package_info().name); From 92ce8e45a8038647987903d2a627ea7c8387ae9f Mon Sep 17 00:00:00 2001 From: ayang <473033518@qq.com> Date: Mon, 21 Apr 2025 20:49:56 +0800 Subject: [PATCH 2/2] chore: update changelog --- .changes/is-autostart-ability.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/is-autostart-ability.md diff --git a/.changes/is-autostart-ability.md b/.changes/is-autostart-ability.md new file mode 100644 index 0000000000..08f60fd569 --- /dev/null +++ b/.changes/is-autostart-ability.md @@ -0,0 +1,6 @@ +--- +fs: minor +fs-js: minor +--- + +Add the ability to check if the app is autostart