Manually check for updates

This commit is contained in:
tk103331
2023-01-04 12:43:26 +08:00
parent b8614e73ff
commit c19698bc41
4 changed files with 94 additions and 3 deletions

View File

@@ -8,7 +8,8 @@ use std::{
path::{Path, PathBuf},
process::Command,
};
use tauri::{utils::config::Config, Manager};
use tauri::{utils::config::Config, Manager, AppHandle, Wry};
use tauri::updater::UpdateResponse;
pub fn chat_root() -> PathBuf {
tauri::api::path::home_dir().unwrap().join(".chatgpt")
@@ -128,3 +129,50 @@ pub async fn get_data(
Ok(None)
}
}
// Copy private api in tauri/updater/mod.rs. TODO: refactor to public api
// Prompt a dialog asking if the user want to install the new version
// Maybe we should add an option to customize it in future versions.
pub async fn prompt_for_install (
app: AppHandle<Wry>,
update: UpdateResponse<Wry>
) -> Result<()> {
let windows = app.windows();
let parent_window = windows.values().next();
let package_info = app.package_info().clone();
let body = update.body().unwrap();
// todo(lemarier): We should review this and make sure we have
// something more conventional.
let should_install = tauri::api::dialog::blocking::ask(
parent_window,
format!(r#"A new version of {} is available! "#, package_info.name),
format!(
r#"{} {} is now available -- you have {}.
Would you like to install it now?
Release Notes:
{}"#,
package_info.name, update.latest_version(), package_info.version, body),
);
if should_install {
// Launch updater download process
// macOS we display the `Ready to restart dialog` asking to restart
// Windows is closing the current App and launch the downloaded MSI when ready (the process stop here)
// Linux we replace the AppImage by launching a new install, it start a new AppImage instance, so we're closing the previous. (the process stop here)
update.download_and_install().await?;
// Ask user if we need to restart the application
let should_exit = tauri::api::dialog::blocking::ask(
parent_window,
"Ready to Restart",
"The installation was successful, do you want to restart the application now?",
);
if should_exit {
app.restart();
}
}
Ok(())
}