From e59dd086fc2ac1eb9be4970707f17196cfd3a597 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 3 Jul 2025 12:43:13 -0500 Subject: [PATCH] Move update checking entirely into JS and open a modal if an update is available --- apps/app-frontend/src/App.vue | 34 +++++++-- .../src/components/ui/UpdateModal.vue | 37 +++++++++ apps/app-frontend/src/helpers/utils.js | 4 + apps/app/src/main.rs | 76 ++----------------- 4 files changed, 77 insertions(+), 74 deletions(-) create mode 100644 apps/app-frontend/src/components/ui/UpdateModal.vue diff --git a/apps/app-frontend/src/App.vue b/apps/app-frontend/src/App.vue index 1bc25942c..6b1a38904 100644 --- a/apps/app-frontend/src/App.vue +++ b/apps/app-frontend/src/App.vue @@ -1,5 +1,5 @@ + + diff --git a/apps/app-frontend/src/helpers/utils.js b/apps/app-frontend/src/helpers/utils.js index 89ebd52ba..554636dda 100644 --- a/apps/app-frontend/src/helpers/utils.js +++ b/apps/app-frontend/src/helpers/utils.js @@ -5,6 +5,10 @@ export async function isDev() { return await invoke('is_dev') } +export async function areUpdatesEnabled() { + return await invoke('are_updates_enabled') +} + // One of 'Windows', 'Linux', 'MacOS' export async function getOS() { return await invoke('plugin:utils|get_os') diff --git a/apps/app/src/main.rs b/apps/app/src/main.rs index b6b00ea81..07e9da0c6 100644 --- a/apps/app/src/main.rs +++ b/apps/app/src/main.rs @@ -21,75 +21,9 @@ async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> { tracing::info!("Initializing app event state..."); theseus::EventState::init(app.clone()).await?; - #[cfg(feature = "updater")] - 'updater: { - if env::var("MODRINTH_EXTERNAL_UPDATE_PROVIDER").is_ok() { - State::init().await?; - break 'updater; - } + tracing::info!("Initializing app state..."); + State::init().await?; - use tauri_plugin_updater::UpdaterExt; - - let updater = app.updater_builder().build()?; - - let update_fut = updater.check(); - - tracing::info!("Initializing app state..."); - State::init().await?; - - let check_bar = theseus::init_loading( - theseus::LoadingBarType::CheckingForUpdates, - 1.0, - "Checking for updates...", - ) - .await?; - - tracing::info!("Checking for updates..."); - let update = update_fut.await; - - drop(check_bar); - - if let Some(update) = update.ok().flatten() { - tracing::info!("Update found: {:?}", update.download_url); - let loader_bar_id = theseus::init_loading( - theseus::LoadingBarType::LauncherUpdate { - version: update.version.clone(), - current_version: update.current_version.clone(), - }, - 1.0, - "Updating Modrinth App...", - ) - .await?; - - // 100 MiB - const DEFAULT_CONTENT_LENGTH: u64 = 1024 * 1024 * 100; - - update - .download_and_install( - |chunk_length, content_length| { - let _ = theseus::emit_loading( - &loader_bar_id, - (chunk_length as f64) - / (content_length - .unwrap_or(DEFAULT_CONTENT_LENGTH) - as f64), - None, - ); - }, - || {}, - ) - .await?; - - app.restart(); - } - } - - #[cfg(not(feature = "updater"))] - { - State::init().await?; - } - - tracing::info!("Finished checking for updates!"); let state = State::get().await?; app.asset_protocol_scope() .allow_directory(state.directories.caches_dir(), true)?; @@ -125,6 +59,11 @@ fn is_dev() -> bool { cfg!(debug_assertions) } +#[tauri::command] +fn are_updates_enabled() -> bool { + cfg!(feature = "updater") +} + // Toggles decorations #[tauri::command] async fn toggle_decorations(b: bool, window: tauri::Window) -> api::Result<()> { @@ -264,6 +203,7 @@ fn main() { .invoke_handler(tauri::generate_handler![ initialize_state, is_dev, + are_updates_enabled, toggle_decorations, show_window, restart_app,