Migrated the installation of updates from Tauri JS to the runtime API

This commit is contained in:
Thorsten Sommer 2024-08-28 09:12:46 +02:00
parent 2badbe0a19
commit 127191abc2
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 13 additions and 5 deletions

View File

@ -137,9 +137,17 @@ public sealed class Rust(string apiPort) : IDisposable
} }
public async Task InstallUpdate(IJSRuntime jsRuntime) public async Task InstallUpdate(IJSRuntime jsRuntime)
{
try
{ {
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
await jsRuntime.InvokeVoidAsync("window.__TAURI__.invoke", cts.Token, "install_update"); await this.http.GetAsync("/updates/install", cts.Token);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
} }
#region IDisposable #region IDisposable

View File

@ -194,7 +194,7 @@ async fn main() {
// //
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
_ = rocket::custom(figment) _ = rocket::custom(figment)
.mount("/", routes![dotnet_port, dotnet_ready, set_clipboard, check_for_update]) .mount("/", routes![dotnet_port, dotnet_ready, set_clipboard, check_for_update, install_update])
.ignite().await.unwrap() .ignite().await.unwrap()
.launch().await.unwrap(); .launch().await.unwrap();
}); });
@ -319,7 +319,7 @@ async fn main() {
}) })
.plugin(tauri_plugin_window_state::Builder::default().build()) .plugin(tauri_plugin_window_state::Builder::default().build())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
store_secret, get_secret, delete_secret, install_update store_secret, get_secret, delete_secret
]) ])
.build(tauri::generate_context!()) .build(tauri::generate_context!())
.expect("Error while running Tauri application"); .expect("Error while running Tauri application");
@ -732,7 +732,7 @@ struct CheckUpdateResponse {
changelog: String, changelog: String,
} }
#[tauri::command] #[get("/updates/install")]
async fn install_update() { async fn install_update() {
let cloned_response_option = CHECK_UPDATE_RESPONSE.lock().unwrap().clone(); let cloned_response_option = CHECK_UPDATE_RESPONSE.lock().unwrap().clone();
match cloned_response_option { match cloned_response_option {