mirror of
https://github.com/spacebarchat/client.git
synced 2024-11-25 03:32:54 +01:00
updater error event/dont update on dev builds
This commit is contained in:
parent
4051540301
commit
8fef7d1b94
@ -17,7 +17,11 @@ async fn close_splashscreen(window: tauri::Window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show main window
|
// Show main window
|
||||||
window.get_window("main").unwrap().show().unwrap();
|
let main_window = window.get_window("main").unwrap();
|
||||||
|
main_window.show().unwrap();
|
||||||
|
// Open the dev tools automatically when debugging the application
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
main_window.open_devtools();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,12 +77,6 @@ pub fn run() {
|
|||||||
tray::create_tray(handle)?;
|
tray::create_tray(handle)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the dev tools automatically when debugging the application
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
if let Some(main_window) = app.get_window("main") {
|
|
||||||
main_window.open_devtools();
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.on_window_event(|event| match event.event() {
|
.on_window_event(|event| match event.event() {
|
||||||
|
@ -62,6 +62,7 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Failed to parse url: {:?}. Failed to check for updates",
|
"[Updater] Failed to parse url: {:?}. Failed to check for updates",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
emit_update_error(window, format!("Failed to parse url: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -78,6 +79,7 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Failed to send request: {:?}. Failed to check for updates",
|
"[Updater] Failed to send request: {:?}. Failed to check for updates",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
emit_update_error(window, format!("Failed to send request: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -87,6 +89,10 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Non OK status code: {:?}. Failed to check for updates",
|
"[Updater] Non OK status code: {:?}. Failed to check for updates",
|
||||||
response.status()
|
response.status()
|
||||||
);
|
);
|
||||||
|
emit_update_error(
|
||||||
|
window,
|
||||||
|
format!("Non OK status code: {:?}", response.status()),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let releases = match response.json::<Vec<Release>>().await {
|
let releases = match response.json::<Vec<Release>>().await {
|
||||||
@ -96,6 +102,7 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Failed to parse response: {:?}. Failed to check for updates",
|
"[Updater] Failed to parse response: {:?}. Failed to check for updates",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
emit_update_error(window, format!("Failed to parse response: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -103,6 +110,15 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
// check if there are any releases
|
// check if there are any releases
|
||||||
if releases.len() == 0 {
|
if releases.len() == 0 {
|
||||||
println!("[Updater] No releases found. Failed to check for updates");
|
println!("[Updater] No releases found. Failed to check for updates");
|
||||||
|
match window.emit("UPDATE_NOT_AVAILABLE", Some({})) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
println!(
|
||||||
|
"[Updater] Failed to emit update not available event: {:?}",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +144,10 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
for asset in latest_release.assets.iter() {
|
for asset in latest_release.assets.iter() {
|
||||||
println!(" {:?}", asset.name);
|
println!(" {:?}", asset.name);
|
||||||
}
|
}
|
||||||
|
emit_update_error(
|
||||||
|
window,
|
||||||
|
format!("Failed to find latest.json asset. Failed to check for updates"),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -139,6 +159,7 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Failed to parse url: {:?}. Failed to check for updates",
|
"[Updater] Failed to parse url: {:?}. Failed to check for updates",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
emit_update_error(window, format!("Failed to parse url: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -151,17 +172,25 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
latest_version.version.clone()
|
latest_version.version.clone()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// if the current build is 00 then its a dev environment and we should not update
|
||||||
|
if current_version.build.to_string() == "00" {
|
||||||
|
println!("[Updater] Build ID is 00, looks like a development environment, not updating.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// upgrade
|
||||||
if latest_version.version > current_version {
|
if latest_version.version > current_version {
|
||||||
println!("[Updater] Latest version is greater than current version. ");
|
println!("[Updater] An update is available.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// downgrade
|
||||||
if latest_version.version < current_version {
|
if latest_version.version < current_version {
|
||||||
println!("[Updater] Latest version is lower than current version. ");
|
println!("[Updater] The installed version is newer than the latest version. A little odd, but ok.");
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return latest_version.version.build > current_version.build;
|
return false;
|
||||||
})
|
})
|
||||||
.endpoints(vec![tauri_release_endpoint])
|
.endpoints(vec![tauri_release_endpoint])
|
||||||
.header("User-Agent", "spacebar-client")
|
.header("User-Agent", "spacebar-client")
|
||||||
@ -172,6 +201,7 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Failed to build updater builder: {:?}. Failed to check for updates",
|
"[Updater] Failed to build updater builder: {:?}. Failed to check for updates",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
emit_update_error(window, format!("Failed to build updater builder: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -183,6 +213,7 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
"[Updater] Failed to build updater: {:?}. Failed to check for updates",
|
"[Updater] Failed to build updater: {:?}. Failed to check for updates",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
emit_update_error(window, format!("Failed to build updater: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -225,6 +256,12 @@ pub fn check_for_updates<R: Runtime>(ignore_prereleases: bool, window: tauri::Wi
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("[Updater] Failed to check for updates: {:?}.", e);
|
println!("[Updater] Failed to check for updates: {:?}.", e);
|
||||||
|
match window.emit("UPDATE_ERROR", Some(format!("{:?}", e))) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
println!("[Updater] Failed to emit update error event: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -238,6 +275,7 @@ pub async fn download_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
Some(update) => update,
|
Some(update) => update,
|
||||||
None => {
|
None => {
|
||||||
println!("[Updater] No update found to download");
|
println!("[Updater] No update found to download");
|
||||||
|
emit_update_error(window, format!("No update found to download"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -265,6 +303,8 @@ pub async fn download_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
|
|
||||||
if let Err(e) = download_response {
|
if let Err(e) = download_response {
|
||||||
println!("[Updater] Failed to download update: {:?}", e);
|
println!("[Updater] Failed to download update: {:?}", e);
|
||||||
|
emit_update_error(window, format!("Failed to download update: {:?}", e));
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
println!("[Updater] Update downloaded");
|
println!("[Updater] Update downloaded");
|
||||||
|
|
||||||
@ -281,6 +321,8 @@ pub async fn download_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("[Updater] Failed to save update package: {:?}", e);
|
println!("[Updater] Failed to save update package: {:?}", e);
|
||||||
|
emit_update_error(window, format!("Failed to save update package: {:?}", e));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,6 +349,7 @@ pub async fn install_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
Some(update) => update,
|
Some(update) => update,
|
||||||
None => {
|
None => {
|
||||||
println!("[Updater] No update found to install");
|
println!("[Updater] No update found to install");
|
||||||
|
emit_update_error(window, format!("No update found to install"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -321,6 +364,7 @@ pub async fn install_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
// check if the update package exists
|
// check if the update package exists
|
||||||
if !package_path.exists() {
|
if !package_path.exists() {
|
||||||
println!("[Updater] No pending update found to install");
|
println!("[Updater] No pending update found to install");
|
||||||
|
emit_update_error(window, format!("No pending update found to install"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,6 +373,7 @@ pub async fn install_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("[Updater] Failed to read update package: {:?}", e);
|
println!("[Updater] Failed to read update package: {:?}", e);
|
||||||
|
emit_update_error(window, format!("Failed to read update package: {:?}", e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -337,6 +382,7 @@ pub async fn install_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
|
|
||||||
if let Err(e) = install_response {
|
if let Err(e) = install_response {
|
||||||
println!("[Updater] Failed to install update: {:?}", e);
|
println!("[Updater] Failed to install update: {:?}", e);
|
||||||
|
emit_update_error(window, format!("Failed to install update: {:?}", e));
|
||||||
} else {
|
} else {
|
||||||
println!("[Updater] Update installed");
|
println!("[Updater] Update installed");
|
||||||
|
|
||||||
@ -345,6 +391,7 @@ pub async fn install_update<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("[Updater] Failed to remove update package: {:?}", e);
|
println!("[Updater] Failed to remove update package: {:?}", e);
|
||||||
|
emit_update_error(window, format!("Failed to remove update package: {:?}", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,6 +417,17 @@ pub fn clear_update_cache<R: Runtime>(window: tauri::Window<R>) {
|
|||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("[Updater] Failed to remove update package: {:?}", e);
|
println!("[Updater] Failed to remove update package: {:?}", e);
|
||||||
|
emit_update_error(window, format!("Failed to remove update package: {:?}", e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// utility function to emit UPDATE_ERROR
|
||||||
|
fn emit_update_error<R: Runtime>(window: tauri::Window<R>, error: String) {
|
||||||
|
match window.emit("UPDATE_ERROR", Some(error)) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => {
|
||||||
|
println!("[Updater] Failed to emit update error event: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,14 @@ export default class UpdaterStore {
|
|||||||
this.setUpdateDownloading(false);
|
this.setUpdateDownloading(false);
|
||||||
this.setUpdateDownloaded(true);
|
this.setUpdateDownloaded(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await listen("UPDATE_ERROR", (e) => {
|
||||||
|
this.logger.debug("Update error", e);
|
||||||
|
this.setCheckingForUpdates(false);
|
||||||
|
this.setUpdateAvailable(false);
|
||||||
|
this.setUpdateDownloading(false);
|
||||||
|
this.setUpdateDownloaded(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
setupListeners();
|
setupListeners();
|
||||||
|
Loading…
Reference in New Issue
Block a user