Add auto updater to the launcher
This commit is contained in:
19 files changed
+170
-39
No files matched your search
@@ -22,7 +22,7 @@ tokio = "1.50.0"
|
||||
futures-util = { version = "0.3.32", features = ["io"] }
|
||||
tauri-plugin-decorum = "1.1.1"
|
||||
tauri-plugin-fs = "2.4.5"
|
||||
zip = "8.4.0"
|
||||
zip = "8.5.0"
|
||||
tauri-plugin-dialog = "2.6.0"
|
||||
tauri-plugin-notification = "2.3.3"
|
||||
sha2 = "0.11.0"
|
||||
@@ -40,6 +40,7 @@ sysinfo = "0.38.4"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-single-instance = "2.4.0"
|
||||
tauri-plugin-updater = "2.10.0"
|
||||
tauri-plugin-window-state = "2.4.1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"window-state:default"
|
||||
"window-state:default",
|
||||
"updater:default"
|
||||
]
|
||||
}
|
||||
@@ -19,6 +19,7 @@ use tauri::window::{ProgressBarState, ProgressBarStatus};
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
use tauri_plugin_os::platform;
|
||||
use tauri_plugin_prevent_default::Flags;
|
||||
use tauri_plugin_updater::UpdaterExt;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::{io::AsyncWriteExt, time::timeout};
|
||||
use zip::ZipArchive;
|
||||
@@ -520,6 +521,7 @@ async fn cancel_download(name: String) {
|
||||
pub fn run() {
|
||||
#[allow(unused_variables)]
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_store::Builder::new().build())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(
|
||||
@@ -568,8 +570,45 @@ pub fn run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
let handle = app.handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
update(handle).await.unwrap();
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
|
||||
let window = app.get_webview_window("main").unwrap();
|
||||
|
||||
if let Some(update) = app.updater()?.check().await? {
|
||||
let mut new_url = window.url().unwrap();
|
||||
new_url.set_path("/update/updating");
|
||||
window.navigate(new_url).unwrap();
|
||||
|
||||
let mut downloaded = 0;
|
||||
|
||||
update
|
||||
.download_and_install(
|
||||
|chunk_length, content_length| {
|
||||
downloaded += chunk_length;
|
||||
println!("downloaded {downloaded} from {content_length:?}");
|
||||
},
|
||||
|| {
|
||||
println!("download finished");
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("update installed");
|
||||
app.restart();
|
||||
}
|
||||
|
||||
let mut new_url = window.url().unwrap();
|
||||
new_url.set_path("/main");
|
||||
window.navigate(new_url).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
"windows": [
|
||||
{
|
||||
"title": "Lncvrt Games Launcher",
|
||||
"url": "/update/checking",
|
||||
"width": 1000,
|
||||
"height": 600,
|
||||
"minWidth": 875,
|
||||
@@ -24,6 +25,17 @@
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": false
|
||||
"active": true,
|
||||
"targets": ["deb", "rpm"],
|
||||
"icon": ["icons/*.png"],
|
||||
"createUpdaterArtifacts": true
|
||||
},
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IERFODI3MTAwQkNBMjE4REEKUldUYUdLSzhBSEdDM3J0N1NvbENsdDQ3c3BOdWlFajErVnlLZitSc2l5WVI0VjQ1ZHNMWjYzaUwK",
|
||||
"endpoints": [
|
||||
"https://games.lncvrt.xyz/api/launcher/update?target={{target}}&arch={{arch}}¤tVersion={{current_version}}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
"windows": [
|
||||
{
|
||||
"title": "Lncvrt Games Launcher",
|
||||
"url": "/update/checking",
|
||||
"width": 1000,
|
||||
"height": 600,
|
||||
"minWidth": 875,
|
||||
@@ -28,10 +29,19 @@
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": ["app"],
|
||||
"targets": ["dmg", "app"],
|
||||
"icon": ["icons/icon.icns"],
|
||||
"createUpdaterArtifacts": true,
|
||||
"macOS": {
|
||||
"minimumSystemVersion": "13.0"
|
||||
},
|
||||
"icon": ["icons/icon.icns"]
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IERFODI3MTAwQkNBMjE4REEKUldUYUdLSzhBSEdDM3J0N1NvbENsdDQ3c3BOdWlFajErVnlLZitSc2l5WVI0VjQ1ZHNMWjYzaUwK",
|
||||
"endpoints": [
|
||||
"https://games.lncvrt.xyz/api/launcher/update?target={{target}}&arch={{arch}}¤tVersion={{current_version}}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
"windows": [
|
||||
{
|
||||
"title": "Lncvrt Games Launcher",
|
||||
"url": "/update/checking",
|
||||
"width": 1000,
|
||||
"height": 632,
|
||||
"minWidth": 875,
|
||||
@@ -29,7 +30,17 @@
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": false,
|
||||
"icon": ["icons/icon.ico"]
|
||||
"active": true,
|
||||
"targets": ["msi"],
|
||||
"icon": ["icons/icon.ico"],
|
||||
"createUpdaterArtifacts": true
|
||||
},
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IERFODI3MTAwQkNBMjE4REEKUldUYUdLSzhBSEdDM3J0N1NvbENsdDQ3c3BOdWlFajErVnlLZitSc2l5WVI0VjQ1ZHNMWjYzaUwK",
|
||||
"endpoints": [
|
||||
"https://games.lncvrt.xyz/api/launcher/update?target={{target}}&arch={{arch}}¤tVersion={{current_version}}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user