mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-22 05:34:04 +02:00
added auto updater
This commit is contained in:
parent
9a38b2114f
commit
62c19dfd40
5 changed files with 735 additions and 2 deletions
|
@ -7,6 +7,7 @@ mod clipboard;
|
|||
mod database;
|
||||
mod hotkeys;
|
||||
mod tray;
|
||||
mod updater;
|
||||
|
||||
use tauri::Manager;
|
||||
use tauri::PhysicalPosition;
|
||||
|
@ -46,6 +47,8 @@ fn main() {
|
|||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_sql::Builder::default().build())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_updater::Builder::default().build())
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
MacosLauncher::LaunchAgent,
|
||||
Some(vec![]),
|
||||
|
@ -73,6 +76,10 @@ fn main() {
|
|||
let app_data_dir = app.path().app_data_dir().expect("Failed to get app data directory");
|
||||
clipboard::set_app_data_dir(app_data_dir);
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
updater::check_for_updates(app_handle).await;
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|app, event| match event {
|
||||
|
|
46
src-tauri/src/updater.rs
Normal file
46
src-tauri/src/updater.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use tauri::{AppHandle, async_runtime};
|
||||
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
|
||||
use tauri_plugin_updater::UpdaterExt;
|
||||
|
||||
|
||||
pub async fn check_for_updates(app: AppHandle) {
|
||||
println!("Checking for updates...");
|
||||
|
||||
let updater = app.updater().unwrap();
|
||||
let response = updater.check().await;
|
||||
|
||||
match response {
|
||||
Ok(Some(update)) => {
|
||||
let cur_ver = &update.current_version;
|
||||
let new_ver = &update.version;
|
||||
let mut msg = String::new();
|
||||
msg.extend([
|
||||
&format!("New Version: {new_ver}\nCurrent Version: {cur_ver}\n\n"),
|
||||
"Would you like to install it now?",
|
||||
]);
|
||||
|
||||
app.dialog()
|
||||
.message(msg)
|
||||
.title("Update Available")
|
||||
.ok_button_label("Yes")
|
||||
.cancel_button_label("No")
|
||||
.show(move |response| {
|
||||
if !response {
|
||||
return;
|
||||
}
|
||||
async_runtime::spawn(async move {
|
||||
if let Err(e) = update.download_and_install(|_, _| {}, || {}).await {
|
||||
println!("Error installing new update: {:?}", e);
|
||||
app.dialog().message(
|
||||
"Failed to install new update. The new update can be downloaded from Github"
|
||||
).kind(MessageDialogKind::Error).show(|_| {});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Ok(None) => println!("No updates available."),
|
||||
Err(e) => {
|
||||
println!("Failed to check for updates: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue