Skip to content

Commit 16f2c30

Browse files
committed
feat: add the ability to check if the app is autostart
1 parent dde6f3c commit 16f2c30

7 files changed

Lines changed: 77 additions & 5 deletions

File tree

plugins/autostart/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
const COMMANDS: &[&str] = &["enable", "disable", "is_enabled"];
5+
const COMMANDS: &[&str] = &["enable", "disable", "is_enabled", "is_autostart"];
66

77
fn main() {
88
tauri_plugin::Builder::new(COMMANDS)

plugins/autostart/guest-js/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ export async function enable(): Promise<void> {
1515
export async function disable(): Promise<void> {
1616
await invoke('plugin:autostart|disable')
1717
}
18+
19+
export async function isAutostart(): Promise<boolean> {
20+
await invoke('plugin:autostart|is_autostart')
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-is-autostart"
7+
description = "Enables the is_autostart command without any pre-configured scope."
8+
commands.allow = ["is_autostart"]
9+
10+
[[permission]]
11+
identifier = "deny-is-autostart"
12+
description = "Denies the is_autostart command without any pre-configured scope."
13+
commands.deny = ["is_autostart"]

plugins/autostart/permissions/autogenerated/reference.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ disable the automatic start on boot.
1616
- `allow-enable`
1717
- `allow-disable`
1818
- `allow-is-enabled`
19+
- `allow-is-autostart`
1920

2021
## Permission Table
2122

@@ -81,6 +82,32 @@ Denies the enable command without any pre-configured scope.
8182
<tr>
8283
<td>
8384

85+
`autostart:allow-is-autostart`
86+
87+
</td>
88+
<td>
89+
90+
Enables the is_autostart command without any pre-configured scope.
91+
92+
</td>
93+
</tr>
94+
95+
<tr>
96+
<td>
97+
98+
`autostart:deny-is-autostart`
99+
100+
</td>
101+
<td>
102+
103+
Denies the is_autostart command without any pre-configured scope.
104+
105+
</td>
106+
</tr>
107+
108+
<tr>
109+
<td>
110+
84111
`autostart:allow-is-enabled`
85112

86113
</td>

plugins/autostart/permissions/default.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ disable the automatic start on boot.
1212
1313
"""
1414

15-
permissions = ["allow-enable", "allow-disable", "allow-is-enabled"]
15+
permissions = ["allow-enable", "allow-disable", "allow-is-enabled", "allow-is-autostart"]

plugins/autostart/permissions/schemas/schema.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,18 @@
318318
"const": "deny-enable",
319319
"markdownDescription": "Denies the enable command without any pre-configured scope."
320320
},
321+
{
322+
"description": "Enables the is_autostart command without any pre-configured scope.",
323+
"type": "string",
324+
"const": "allow-is-autostart",
325+
"markdownDescription": "Enables the is_autostart command without any pre-configured scope."
326+
},
327+
{
328+
"description": "Denies the is_autostart command without any pre-configured scope.",
329+
"type": "string",
330+
"const": "deny-is-autostart",
331+
"markdownDescription": "Denies the is_autostart command without any pre-configured scope."
332+
},
321333
{
322334
"description": "Enables the is_enabled command without any pre-configured scope.",
323335
"type": "string",
@@ -331,10 +343,10 @@
331343
"markdownDescription": "Denies the is_enabled command without any pre-configured scope."
332344
},
333345
{
334-
"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`",
346+
"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`",
335347
"type": "string",
336348
"const": "default",
337-
"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`"
349+
"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`"
338350
}
339351
]
340352
}

plugins/autostart/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ async fn is_enabled(manager: State<'_, AutoLaunchManager>) -> Result<bool> {
9898
manager.is_enabled()
9999
}
100100

101+
#[command]
102+
async fn is_autostart(manager: State<'_, AutoLaunchManager>) -> Result<bool> {
103+
let process_args: Vec<String> = std::env::args().collect();
104+
105+
let passed_args = manager.0.get_args();
106+
107+
let is_autostart = passed_args.iter().all(|arg| process_args.contains(arg));
108+
109+
Ok(is_autostart)
110+
}
111+
101112
#[derive(Default)]
102113
pub struct Builder {
103114
#[cfg(target_os = "macos")]
@@ -156,7 +167,12 @@ impl Builder {
156167

157168
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
158169
PluginBuilder::new("autostart")
159-
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
170+
.invoke_handler(tauri::generate_handler![
171+
enable,
172+
disable,
173+
is_enabled,
174+
is_autostart
175+
])
160176
.setup(move |app, _api| {
161177
let mut builder = AutoLaunchBuilder::new();
162178
builder.set_app_name(&app.package_info().name);

0 commit comments

Comments
 (0)