diff --git a/README.md b/README.md index 2337f26..365b895 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Closing the window (X) only hides it; click the tray icon to bring it back. To q ## Update -Notelet updates itself. Each time it starts it checks for a new version, installs it and reopens, so nothing is lost: any change you are typing is saved first. To check now, right-click the tray icon → **Check for updates**. +Right-click the tray icon → **Check for updates**. If there is a new version, Notelet asks first, then installs it and reopens. Nothing is lost: any change you are typing is saved first. ## Moving from the Chrome extension diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index 21bdc9d..08e219e 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "notelet" -version = "0.8.0" +version = "0.9.0" description = "Lightweight notes with sprint tracking" edition = "2021" publish = false diff --git a/desktop/src/lib.rs b/desktop/src/lib.rs index 2ce9f4c..e5a5246 100644 --- a/desktop/src/lib.rs +++ b/desktop/src/lib.rs @@ -9,7 +9,7 @@ use tauri::menu::{CheckMenuItem, Menu, MenuItem, PredefinedMenuItem}; use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent}; use tauri::{AppHandle, Emitter, Manager, State, WebviewWindow, WindowEvent}; use tauri_plugin_autostart::{MacosLauncher, ManagerExt as _}; -use tauri_plugin_dialog::DialogExt; +use tauri_plugin_dialog::{DialogExt, MessageDialogButtons}; use tauri_plugin_updater::{Update, UpdaterExt}; use tauri_plugin_window_state::{AppHandleExt, StateFlags}; @@ -171,23 +171,32 @@ fn show_message(app: &AppHandle, text: String) { app.dialog().message(text).title("Notelet").show(|_| {}); } -/// At start a failed check stays silent and is retried next start; from the tray it says why. -async fn check_for_update(app: AppHandle, from_tray: bool) { +fn ask_to_install(app: &AppHandle, version: &str) -> bool { + app.dialog() + .message(format!( + "Notelet {version} is available (you have {}).\n\nDownload and install it now? Notelet restarts by itself.", + app.package_info().version + )) + .title("Notelet") + .buttons(MessageDialogButtons::OkCancelCustom("Install and restart".to_string(), "Later".to_string())) + .blocking_show() +} + +async fn check_for_update(app: AppHandle) { let result = match app.updater() { Ok(updater) => updater.check().await, Err(error) => Err(error), }; match result { + Ok(Some(update)) if !ask_to_install(&app, &update.version) => {} // Downloading first keeps the gap between the page's last save and the installer closing // the app to the install alone. Ok(Some(update)) => match update.download(|_, _| {}, || {}).await { Ok(bytes) => request_after_flush(&app, Pending::Update(Box::new(update), bytes)), - Err(error) if from_tray => show_message(&app, format!("Couldn't download the update: {error}")), - Err(_) => {} + Err(error) => show_message(&app, format!("Couldn't download the update: {error}")), }, - Ok(None) if from_tray => show_message(&app, format!("Notelet {} is the latest version.", app.package_info().version)), - Err(error) if from_tray => show_message(&app, format!("Couldn't check for updates: {error}")), - _ => {} + Ok(None) => show_message(&app, format!("Notelet {} is the latest version.", app.package_info().version)), + Err(error) => show_message(&app, format!("Couldn't check for updates: {error}")), } } @@ -233,7 +242,7 @@ fn build_tray(app: &AppHandle, autostart_on: bool) -> tauri::Result<()> { .on_menu_event(move |app, event| match event.id.as_ref() { "open" => show_main(app), "check-updates" => { - tauri::async_runtime::spawn(check_for_update(app.clone(), true)); + tauri::async_runtime::spawn(check_for_update(app.clone())); } "autostart" => set_autostart(app, autostart.is_checked().unwrap_or(false)), "quit" => request_after_flush(app, Pending::Quit), @@ -300,7 +309,6 @@ pub fn run() { if !std::env::args().any(|arg| arg == HIDDEN_ARG) { show_main(&handle); } - tauri::async_runtime::spawn(check_for_update(handle, false)); Ok(()) }) .run(tauri::generate_context!()) diff --git a/desktop/tauri.conf.json b/desktop/tauri.conf.json index 5787f67..b69a338 100644 --- a/desktop/tauri.conf.json +++ b/desktop/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Notelet", - "version": "0.8.0", + "version": "0.9.0", "identifier": "com.ttncode.notelet", "build": { "frontendDist": "../extension" diff --git a/package-lock.json b/package-lock.json index 8b96867..5b35bfd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "notelet", - "version": "0.8.0", + "version": "0.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "notelet", - "version": "0.8.0", + "version": "0.9.0", "devDependencies": { "@tauri-apps/cli": "^2.12.4", "linkedom": "^0.18.13" diff --git a/package.json b/package.json index db17f7a..1080551 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notelet", - "version": "0.8.0", + "version": "0.9.0", "private": true, "type": "module", "scripts": {