Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main #1418

Merged
merged 1 commit into from
Nov 25, 2024
Merged

main #1418

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 71 additions & 71 deletions desktop/src-tauri/src/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ pub async fn check_updates(app_handle: AppHandle) -> Result<bool, UpdateError> {
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);
}
Expand All @@ -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::<AppState>();
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::<AppState>();
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::<AppState>();
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::<AppState>();
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::<AppState>();
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::<AppState>();
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;
}
}

Expand Down
57 changes: 29 additions & 28 deletions desktop/src-tauri/src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,32 @@ impl ToSystemTraySubmenu for WorkspacesState {
}

fn on_tray_item_clicked(&self, id: &str) -> Option<SystemTrayClickHandler> {
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);
};
}
})
}))
}
}

Expand Down Expand Up @@ -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);
});
Expand Down
Loading