pull/2650/merge
ayangweb 3 days ago committed by GitHub
commit 4e5dab7994
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,6 @@
---
fs: minor
fs-js: minor
---
Add the ability to check if the app is autostart

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"]; const COMMANDS: &[&str] = &["enable", "disable", "is_enabled", "is_autostart"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)

@ -15,3 +15,7 @@ export async function enable(): Promise<void> {
export async function disable(): Promise<void> { export async function disable(): Promise<void> {
await invoke('plugin:autostart|disable') 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"]

@ -14,6 +14,7 @@ disable the automatic start on boot.
- `allow-enable` - `allow-enable`
- `allow-disable` - `allow-disable`
- `allow-is-enabled` - `allow-is-enabled`
- `allow-is-autostart`
## Permission Table ## Permission Table
@ -79,6 +80,32 @@ Denies the enable command without any pre-configured scope.
<tr> <tr>
<td> <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` `autostart:allow-is-enabled`
</td> </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", "const": "deny-enable",
"markdownDescription": "Denies the enable command without any pre-configured scope." "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.", "description": "Enables the is_enabled command without any pre-configured scope.",
"type": "string", "type": "string",
@ -331,10 +343,10 @@
"markdownDescription": "Denies the is_enabled command without any pre-configured scope." "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", "type": "string",
"const": "default", "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() 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)] #[derive(Default)]
pub struct Builder { pub struct Builder {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@ -171,7 +182,12 @@ impl Builder {
pub fn build<R: Runtime>(self) -> TauriPlugin<R> { pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
PluginBuilder::new("autostart") 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| { .setup(move |app, _api| {
let mut builder = AutoLaunchBuilder::new(); let mut builder = AutoLaunchBuilder::new();

Loading…
Cancel
Save