Skip to content

Commit fae383d

Browse files
committed
Add auto-start on boot and checkbox in UI
1 parent ee6a6e1 commit fae383d

7 files changed

Lines changed: 111 additions & 7 deletions

File tree

dweb-app/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dweb-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"license": "MIT",
1515
"dependencies": {
1616
"@tauri-apps/api": "^2.8.0",
17+
"@tauri-apps/plugin-autostart": "^2.5.0",
1718
"@tauri-apps/plugin-opener": "^2"
1819
},
1920
"devDependencies": {

dweb-app/src-tauri/Cargo.lock

Lines changed: 60 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dweb-app/src-tauri/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ open = "5.3.2"
2727
dweb-server = { path = "../../dweb-server", features = ["development"] }
2828
dweb = { path = "../../dweb-lib", features = ["development"] }
2929

30+
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
31+
tauri-plugin-autostart = "2"
32+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"identifier": "desktop-capability",
3+
"platforms": [
4+
"macOS",
5+
"windows",
6+
"linux"
7+
],
8+
"windows": [
9+
"main"
10+
],
11+
"permissions": [
12+
"autostart:allow-enable",
13+
"autostart:allow-disable",
14+
"autostart:allow-is-enabled"
15+
]
16+
}

dweb-app/src-tauri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ struct ServerState {
3939
dweb_service: Mutex<DwebService>,
4040
}
4141

42-
4342
#[cfg_attr(mobile, tauri::mobile_entry_point)]
4443
pub fn run() {
4544
tauri::Builder::default()
45+
.plugin(tauri_plugin_autostart::Builder::new().build())
4646
.setup(|app| {
4747
// Make builtin names such as 'awesome' available (in addition to opening xor addresses)
4848
dweb::web::name::register_builtin_names(false);

dweb-app/src/routes/+page.svelte

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,31 @@ import { invoke } from "@tauri-apps/api/core";
1818
import {onMount} from 'svelte';
1919
import { getVersion } from '@tauri-apps/api/app';
2020
21-
let appVersion;
21+
// Autostart (see https://tauri.app/plugin/autostart/#setup)
22+
import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart';
23+
let autoStartUI;
24+
25+
async function onClickAutoStart() {
26+
if (autoStartUI) {
27+
autoStartUI = false;
28+
disable();
29+
} else {
30+
autoStartUI = true;
31+
enable();
32+
}
2233
34+
console.log(`registered for autostart? ${await isEnabled()}`);
35+
}
36+
37+
let appVersion;
2338
2439
onMount(async () => {
2540
console.log("onMount() starting dweb server...");
2641
appVersion = await getVersion();
2742
await startServer();
43+
44+
autoStartUI = await isEnabled(); // run dweb-app on boot?
45+
2846
await refreshWallet();
2947
});
3048
@@ -151,6 +169,7 @@ async function refreshWallet() {
151169
/>
152170
<button title="Go directly to a website or app" onclick={openByAddress}>Open</button>
153171
</div>
172+
<p><input type="checkbox" bind:checked={autoStartUI} onclick={onClickAutoStart}/>Auto-start on reboot</p>
154173
</main>
155174

156175
<style>

0 commit comments

Comments
 (0)