From 127191abc2f0547ae5c86fdae119fac173936e70 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 28 Aug 2024 09:12:46 +0200 Subject: [PATCH] Migrated the installation of updates from Tauri JS to the runtime API --- app/MindWork AI Studio/Tools/Rust.cs | 12 ++++++++++-- runtime/src/main.rs | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/MindWork AI Studio/Tools/Rust.cs b/app/MindWork AI Studio/Tools/Rust.cs index 2eb5ad60..caf858a1 100644 --- a/app/MindWork AI Studio/Tools/Rust.cs +++ b/app/MindWork AI Studio/Tools/Rust.cs @@ -138,8 +138,16 @@ public sealed class Rust(string apiPort) : IDisposable public async Task InstallUpdate(IJSRuntime jsRuntime) { - var cts = new CancellationTokenSource(); - await jsRuntime.InvokeVoidAsync("window.__TAURI__.invoke", cts.Token, "install_update"); + try + { + var cts = new CancellationTokenSource(); + await this.http.GetAsync("/updates/install", cts.Token); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } } #region IDisposable diff --git a/runtime/src/main.rs b/runtime/src/main.rs index e308c7dd..ca1e6f26 100644 --- a/runtime/src/main.rs +++ b/runtime/src/main.rs @@ -194,7 +194,7 @@ async fn main() { // tauri::async_runtime::spawn(async move { _ = 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() .launch().await.unwrap(); }); @@ -319,7 +319,7 @@ async fn main() { }) .plugin(tauri_plugin_window_state::Builder::default().build()) .invoke_handler(tauri::generate_handler![ - store_secret, get_secret, delete_secret, install_update + store_secret, get_secret, delete_secret ]) .build(tauri::generate_context!()) .expect("Error while running Tauri application"); @@ -732,7 +732,7 @@ struct CheckUpdateResponse { changelog: String, } -#[tauri::command] +#[get("/updates/install")] async fn install_update() { let cloned_response_option = CHECK_UPDATE_RESPONSE.lock().unwrap().clone(); match cloned_response_option {