feat: add the ability to check if the app is autostart

pull/2650/head
ayang 3 months ago
parent dde6f3c31c
commit 16f2c30e25
No known key found for this signature in database
GPG Key ID: 7CF0B972091D5C0C

@ -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)

@ -15,3 +15,7 @@ export async function enable(): Promise<void> {
export async function disable(): Promise<void> {
await invoke('plugin:autostart|disable')
}
export async function isAutostart(): Promise<boolean> {
await invoke('plugin:autostart|is_autostart')
}

@ -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"]

@ -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.
<tr>
<td>
`autostart:allow-is-autostart`
</td>
<td>
Enables the is_autostart command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`autostart:deny-is-autostart`
</td>
<td>
Denies the is_autostart command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`autostart:allow-is-enabled`
</td>

@ -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"]

@ -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`"
}
]
}

@ -98,6 +98,17 @@ async fn is_enabled(manager: State<'_, AutoLaunchManager>) -> Result<bool> {
manager.is_enabled()
}
#[command]
async fn is_autostart(manager: State<'_, AutoLaunchManager>) -> Result<bool> {
let process_args: Vec<String> = 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<R: Runtime>(self) -> TauriPlugin<R> {
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);

Loading…
Cancel
Save