diff --git a/desktop/src-tauri/src/updates.rs b/desktop/src-tauri/src/updates.rs index b0e90f6a2..78a889f71 100644 --- a/desktop/src-tauri/src/updates.rs +++ b/desktop/src-tauri/src/updates.rs @@ -136,10 +136,7 @@ pub async fn check_updates(app_handle: AppHandle) -> Result { match updater.check().await { Ok(update) => { let update_available = update.is_some(); - debug!( - "Update check completed, update available: {}", - update_available - ); + info!("Update check completed, result: {}", update_available); return Ok(update_available); } @@ -164,86 +161,89 @@ impl<'a> UpdateHelper<'a> { } pub async fn poll(&self) { + #[cfg(debug_assertions)] // disable during development { - #[cfg(debug_assertions)] // disable during development - { - return - } + return + } - loop { - // check if we have updated the app recently - // if so, show changelog in app + loop { + // check if we have updated the app recently + // if so, show changelog in app - let app_handle = self.app_handle.clone(); - let updater = app_handle.updater(); - if updater.is_err() { - error!("Failed to get updater"); + let app_handle = self.app_handle.clone(); + let updater = app_handle.updater(); + if updater.is_err() { + error!("Failed to get updater"); - continue; - } - if let Ok(update) = updater.unwrap().check().await { - if let Some(update) = update { - let state = self.app_handle.state::(); - let update_installed_state = *state.update_installed.lock().unwrap(); - // prevent ourselves from installing the same update multiple times - if update_installed_state { - return; - } + continue; + } + info!("Attempting to check update"); + if let Ok(update) = updater.unwrap().check().await { + match update { + Some(..) => info!("update available"), + None => info!("no update available") + }; + + if let Some(update) = update { + let state = self.app_handle.state::(); + let update_installed_state = *state.update_installed.lock().unwrap(); + // prevent ourselves from installing the same update multiple times + if update_installed_state { + return; + } - let new_version = update.version.as_str(); - let update_helper = UpdateHelper::new(&self.app_handle); - if let Err(e) = update_helper.update_app_releases(new_version).await { - error!("Failed to update app releases: {}", e); + let new_version = update.version.as_str(); + let update_helper = UpdateHelper::new(&self.app_handle); + if let Err(e) = update_helper.update_app_releases(new_version).await { + error!("Failed to update app releases: {}", e); + } + + if Settings::auto_update_enabled(&self.app_handle) { + let on_chunk = |_, _| {}; + let on_download_fininshed = || { + info!("Download for version {} finished", new_version); + }; + info!( + "Update available, current: {}, new: {}", + update.current_version, new_version, + ); + info!("Starting to download"); + if let Err(err) = update + .download_and_install(on_chunk, on_download_fininshed) + .await + { + error!("Failed to download and install update: {}", err); } - if Settings::auto_update_enabled(&self.app_handle) { - let on_chunk = |_, _| {}; - let on_download_fininshed = || { - info!("Download for version {} finished", new_version); - }; - info!( - "Update available, current: {}, new: {}", - update.current_version, new_version, - ); - info!("Starting to download"); - if let Err(err) = update - .download_and_install(on_chunk, on_download_fininshed) - .await - { - error!("Failed to download and install update: {}", err); - } + let window_helper = WindowHelper::new(self.app_handle.clone()); + let _ = window_helper.new_update_ready_window(); - let window_helper = WindowHelper::new(self.app_handle.clone()); - let _ = window_helper.new_update_ready_window(); - - let state = self.app_handle.state::(); - let mut pending_update_state = state.pending_update.lock().unwrap(); - *pending_update_state = None; - - let mut update_installed_state = state.update_installed.lock().unwrap(); - *update_installed_state = true; - } else { - match self.update_app_releases(new_version).await { - Ok(release) => { - if let Err(err) = self.notify_update_available(&release).await { - warn!("Failed to send update notification: {}", err); - } - - // display update available in the UI - let state = self.app_handle.state::(); - let mut pending_update_state = - state.pending_update.lock().unwrap(); - *pending_update_state = Some(release); - } - Err(e) => { - error!("Failed to update app releases: {}", e); + let state = self.app_handle.state::(); + let mut pending_update_state = state.pending_update.lock().unwrap(); + *pending_update_state = None; + + let mut update_installed_state = state.update_installed.lock().unwrap(); + *update_installed_state = true; + } else { + match self.update_app_releases(new_version).await { + Ok(release) => { + if let Err(err) = self.notify_update_available(&release).await { + warn!("Failed to send update notification: {}", err); } + + // display update available in the UI + let state = self.app_handle.state::(); + let mut pending_update_state = state.pending_update.lock().unwrap(); + *pending_update_state = Some(release); + } + Err(e) => { + error!("Failed to update app releases: {}", e); } } } } - tokio::time::sleep(UPDATE_POLL_INTERVAL).await; - }; + } + tokio::time::sleep(UPDATE_POLL_INTERVAL).await; } } diff --git a/desktop/src-tauri/src/workspaces.rs b/desktop/src-tauri/src/workspaces.rs index b3212cc23..8c6a2fa7f 100644 --- a/desktop/src-tauri/src/workspaces.rs +++ b/desktop/src-tauri/src/workspaces.rs @@ -82,32 +82,32 @@ impl ToSystemTraySubmenu for WorkspacesState { } fn on_tray_item_clicked(&self, id: &str) -> Option { - let id = id.to_string(); - - Some(Box::new(move |_app_handle, state| { - tauri::async_runtime::block_on(async { - let tx = &state.ui_messages; - - if id == Self::CREATE_WORKSPACE_ID { - if let Err(err) = tx - .send(UiMessage::OpenWorkspace(OpenWorkspaceMsg::empty())) - .await - { - error!("Failed to send create workspace message: {:?}", err); - }; - } else { - let workspace_id = id.replace(Self::IDENTIFIER_PREFIX, ""); - if let Err(err) = tx - .send(UiMessage::OpenWorkspace(OpenWorkspaceMsg::with_id( - workspace_id, - ))) - .await - { - error!("Failed to send create workspace message: {:?}", err); - }; - } - }) - })) + let id = id.to_string(); + + Some(Box::new(move |_app_handle, state| { + tauri::async_runtime::block_on(async { + let tx = &state.ui_messages; + + if id == Self::CREATE_WORKSPACE_ID { + if let Err(err) = tx + .send(UiMessage::OpenWorkspace(OpenWorkspaceMsg::empty())) + .await + { + error!("Failed to send create workspace message: {:?}", err); + }; + } else { + let workspace_id = id.replace(Self::IDENTIFIER_PREFIX, ""); + if let Err(err) = tx + .send(UiMessage::OpenWorkspace(OpenWorkspaceMsg::with_id( + workspace_id, + ))) + .await + { + error!("Failed to send create workspace message: {:?}", err); + }; + } + }) + })) } } @@ -171,8 +171,9 @@ pub fn setup(app_handle: &AppHandle, state: tauri::State<'_, AppState>) { let ws_app_handle = app_handle.clone(); thread::spawn(move || loop { - let workspaces = WorkspacesState::load(&ws_app_handle).unwrap(); - workspaces_tx.send(Update::Workspaces(workspaces)).unwrap(); + if let Ok(workspaces) = WorkspacesState::load(&ws_app_handle) { + workspaces_tx.send(Update::Workspaces(workspaces)).unwrap(); + } thread::sleep(sleep_duration); });