feat: autoupdates

This commit is contained in:
2025-03-29 02:04:33 +00:00
parent 17411e8f0d
commit 536f289cfe
7 changed files with 174 additions and 11 deletions

3
.gitignore vendored
View File

@ -23,5 +23,8 @@ dist-ssr
/*.png /*.png
*.bat *.bat
*.exe *.exe
*.ps1
manifest.json
tsconfig.tsbuildinfo tsconfig.tsbuildinfo

View File

@ -21,6 +21,7 @@
"@tauri-apps/plugin-fs": "^2.2.0", "@tauri-apps/plugin-fs": "^2.2.0",
"@tauri-apps/plugin-opener": "^2.2.6", "@tauri-apps/plugin-opener": "^2.2.6",
"@tauri-apps/plugin-shell": "~2.2.0", "@tauri-apps/plugin-shell": "~2.2.0",
"@tauri-apps/plugin-updater": "^2.6.1",
"@trivago/prettier-plugin-sort-imports": "^5.2.2", "@trivago/prettier-plugin-sort-imports": "^5.2.2",
"pinia": "^3.0.1", "pinia": "^3.0.1",
"primeicons": "^7.0.0", "primeicons": "^7.0.0",

134
rust/Cargo.lock generated
View File

@ -275,7 +275,7 @@ dependencies = [
"futures-lite", "futures-lite",
"parking", "parking",
"polling", "polling",
"rustix", "rustix 0.38.44",
"slab", "slab",
"tracing", "tracing",
"windows-sys 0.59.0", "windows-sys 0.59.0",
@ -307,7 +307,7 @@ dependencies = [
"cfg-if", "cfg-if",
"event-listener 5.4.0", "event-listener 5.4.0",
"futures-lite", "futures-lite",
"rustix", "rustix 0.38.44",
"tracing", "tracing",
] ]
@ -334,7 +334,7 @@ dependencies = [
"cfg-if", "cfg-if",
"futures-core", "futures-core",
"futures-io", "futures-io",
"rustix", "rustix 0.38.44",
"signal-hook-registry", "signal-hook-registry",
"slab", "slab",
"windows-sys 0.59.0", "windows-sys 0.59.0",
@ -1470,6 +1470,18 @@ dependencies = [
"rustc_version", "rustc_version",
] ]
[[package]]
name = "filetime"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586"
dependencies = [
"cfg-if",
"libc",
"libredox",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.0" version = "1.1.0"
@ -2674,6 +2686,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"libc", "libc",
"redox_syscall",
] ]
[[package]] [[package]]
@ -2682,6 +2695,12 @@ version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
[[package]]
name = "linux-raw-sys"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413"
[[package]] [[package]]
name = "litemap" name = "litemap"
version = "0.7.5" version = "0.7.5"
@ -2770,6 +2789,12 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "minisign-verify"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6367d84fb54d4242af283086402907277715b8fe46976963af5ebf173f8efba3"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.4" version = "0.7.4"
@ -3141,6 +3166,18 @@ dependencies = [
"objc2-foundation 0.2.2", "objc2-foundation 0.2.2",
] ]
[[package]]
name = "objc2-osa-kit"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1ac59da3ceebc4a82179b35dc550431ad9458f9cc326e053f49ba371ce76c5a"
dependencies = [
"bitflags 2.9.0",
"objc2 0.6.0",
"objc2-app-kit 0.3.0",
"objc2-foundation 0.3.0",
]
[[package]] [[package]]
name = "objc2-quartz-core" name = "objc2-quartz-core"
version = "0.2.2" version = "0.2.2"
@ -3298,6 +3335,20 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "osakit"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "732c71caeaa72c065bb69d7ea08717bd3f4863a4f451402fc9513e29dbd5261b"
dependencies = [
"objc2 0.6.0",
"objc2-foundation 0.3.0",
"objc2-osa-kit",
"serde",
"serde_json",
"thiserror 2.0.12",
]
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "3.5.0" version = "3.5.0"
@ -3624,7 +3675,7 @@ dependencies = [
"concurrent-queue", "concurrent-queue",
"hermit-abi 0.4.0", "hermit-abi 0.4.0",
"pin-project-lite", "pin-project-lite",
"rustix", "rustix 0.38.44",
"tracing", "tracing",
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
@ -4063,7 +4114,20 @@ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys 0.4.15",
"windows-sys 0.59.0",
]
[[package]]
name = "rustix"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e56a18552996ac8d29ecc3b190b4fdbb2d91ca4ec396de7bbffaf43f3d637e96"
dependencies = [
"bitflags 2.9.0",
"errno",
"libc",
"linux-raw-sys 0.9.3",
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
@ -4589,6 +4653,7 @@ dependencies = [
"tauri-plugin-opener", "tauri-plugin-opener",
"tauri-plugin-shell", "tauri-plugin-shell",
"tauri-plugin-single-instance", "tauri-plugin-single-instance",
"tauri-plugin-updater",
"tokio", "tokio",
"winsafe 0.0.23", "winsafe 0.0.23",
"yaml-rust2", "yaml-rust2",
@ -4805,6 +4870,17 @@ dependencies = [
"syn 2.0.99", "syn 2.0.99",
] ]
[[package]]
name = "tar"
version = "0.4.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a"
dependencies = [
"filetime",
"libc",
"xattr",
]
[[package]] [[package]]
name = "target-lexicon" name = "target-lexicon"
version = "0.12.16" version = "0.12.16"
@ -5077,6 +5153,38 @@ dependencies = [
"zbus", "zbus",
] ]
[[package]]
name = "tauri-plugin-updater"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31bfcfb4a8318008d2108ccfba439d8263cf48867baabf372cb0e9f24771896"
dependencies = [
"base64 0.22.1",
"dirs",
"flate2",
"futures-util",
"http",
"infer",
"log",
"minisign-verify",
"osakit",
"percent-encoding",
"reqwest",
"semver",
"serde",
"serde_json",
"tar",
"tauri",
"tauri-plugin",
"tempfile",
"thiserror 2.0.12",
"time",
"tokio",
"url",
"windows-sys 0.59.0",
"zip",
]
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "2.4.0" version = "2.4.0"
@ -5180,7 +5288,7 @@ dependencies = [
"fastrand", "fastrand",
"getrandom 0.3.1", "getrandom 0.3.1",
"once_cell", "once_cell",
"rustix", "rustix 0.38.44",
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
@ -5906,7 +6014,7 @@ checksum = "b7208998eaa3870dad37ec8836979581506e0c5c64c20c9e79e9d2a10d6f47bf"
dependencies = [ dependencies = [
"cc", "cc",
"downcast-rs", "downcast-rs",
"rustix", "rustix 0.38.44",
"scoped-tls", "scoped-tls",
"smallvec", "smallvec",
"wayland-sys", "wayland-sys",
@ -5919,7 +6027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2120de3d33638aaef5b9f4472bff75f07c56379cf76ea320bd3a3d65ecaf73f" checksum = "c2120de3d33638aaef5b9f4472bff75f07c56379cf76ea320bd3a3d65ecaf73f"
dependencies = [ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"rustix", "rustix 0.38.44",
"wayland-backend", "wayland-backend",
"wayland-scanner", "wayland-scanner",
] ]
@ -6622,6 +6730,16 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "xattr"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d65cbf2f12c15564212d48f4e3dfb87923d25d611f2aed18f4cb23f0413d89e"
dependencies = [
"libc",
"rustix 1.0.3",
]
[[package]] [[package]]
name = "xdg-home" name = "xdg-home"
version = "1.3.0" version = "1.3.0"

View File

@ -46,6 +46,7 @@ enumflags2 = { version = "0.7.11", features = ["serde"] }
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-cli = "2" tauri-plugin-cli = "2"
tauri-plugin-single-instance = { version = "2", features = ["deep-link"] } tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }
tauri-plugin-updater = "2"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
winsafe = { version = "0.0.23", features = ["user"] } winsafe = { version = "0.0.23", features = ["user"] }

View File

@ -9,6 +9,7 @@
"main" "main"
], ],
"permissions": [ "permissions": [
"cli:default" "cli:default",
"updater:default"
] ]
} }

View File

@ -18,6 +18,7 @@ use pkg_store::Payload;
use tauri::{AppHandle, Listener, Manager, RunEvent}; use tauri::{AppHandle, Listener, Manager, RunEvent};
use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_cli::CliExt; use tauri_plugin_cli::CliExt;
use tauri_plugin_updater::UpdaterExt;
use tokio::{fs, sync::Mutex, try_join}; use tokio::{fs, sync::Mutex, try_join};
static EXIT_REQUESTED: OnceLock<()> = OnceLock::new(); static EXIT_REQUESTED: OnceLock<()> = OnceLock::new();
@ -35,6 +36,7 @@ pub async fn run(_args: Vec<String>) {
); );
let tauri = tauri::Builder::default() let tauri = tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| { .plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
let _ = app let _ = app
.get_webview_window("main") .get_webview_window("main")
@ -165,6 +167,11 @@ pub async fn run(_args: Vec<String>) {
apph.exit(1); apph.exit(1);
} }
}); });
} else {
let apph = apph.clone();
tauri::async_runtime::spawn(async move {
update(apph).await.unwrap();
});
} }
Ok(()) Ok(())
@ -253,3 +260,25 @@ fn deep_link(app: AppHandle, args: Vec<String>) {
} }
} }
} }
async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
if let Some(update) = app.updater()?.check().await? {
let mut downloaded = 0;
update
.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
log::debug!("downloaded {downloaded} from {content_length:?}");
},
|| {
log::info!("download finished");
},
)
.await?;
log::info!("update installed");
app.restart();
}
Ok(())
}

View File

@ -1,7 +1,7 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "STARTLINER", "productName": "STARTLINER",
"version": "0.1.0", "version": "0.2.0",
"identifier": "zip.patafour.startliner", "identifier": "zip.patafour.startliner",
"build": { "build": {
"beforeDevCommand": "bun run dev", "beforeDevCommand": "bun run dev",
@ -18,6 +18,15 @@
"schemes": ["rainycolor"] "schemes": ["rainycolor"]
} }
}, },
"updater": {
"windows": {
"installMode": "passive"
},
"endpoints": [
"https://gitea.tendokyu.moe/akanyan/STARTLINER/releases/download/latest/manifest.json"
],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDNFQzBGM0Y5RDUzRDNENzQKUldSMFBUM1YrZlBBUHZkMkt0UVVVczhhWitLN2F1aFREQW1WY2FwRSsvRysrSkdYaTJFWmRPUloK"
},
"cli": { "cli": {
"description": "STARTLINER CLI", "description": "STARTLINER CLI",
"args": [ "args": [
@ -57,6 +66,7 @@
"bundle": { "bundle": {
"active": true, "active": true,
"targets": "all", "targets": "all",
"icon": ["icons/slow.png", "icons/slow.ico"] "icon": ["icons/slow.png", "icons/slow.ico"],
"createUpdaterArtifacts": true
} }
} }