mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-03 22:24:15 +02:00
Notify of plugin updates and add update UX (#339)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
use crate::commands::{install, search, uninstall, updates};
|
||||
use crate::commands::{install, search, uninstall, update_all, updates};
|
||||
use crate::manager::PluginManager;
|
||||
use log::info;
|
||||
use crate::plugin_updater::PluginUpdater;
|
||||
use log::{info, warn};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::Duration;
|
||||
use tauri::plugin::{Builder, TauriPlugin};
|
||||
use tauri::{Manager, RunEvent, Runtime, State, generate_handler};
|
||||
use tauri::{Manager, RunEvent, Runtime, State, WindowEvent, generate_handler};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
pub mod api;
|
||||
mod checksum;
|
||||
@@ -16,6 +19,7 @@ pub mod native_template_functions;
|
||||
mod nodejs;
|
||||
pub mod plugin_handle;
|
||||
pub mod plugin_meta;
|
||||
pub mod plugin_updater;
|
||||
mod server_ws;
|
||||
pub mod template_callback;
|
||||
mod util;
|
||||
@@ -24,10 +28,14 @@ static EXITING: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("yaak-plugins")
|
||||
.invoke_handler(generate_handler![search, install, uninstall, updates])
|
||||
.invoke_handler(generate_handler![search, install, uninstall, updates, update_all])
|
||||
.setup(|app_handle, _| {
|
||||
let manager = PluginManager::new(app_handle.clone());
|
||||
app_handle.manage(manager.clone());
|
||||
|
||||
let plugin_updater = PluginUpdater::new();
|
||||
app_handle.manage(Mutex::new(plugin_updater));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_event(|app, e| match e {
|
||||
@@ -44,6 +52,18 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
app.exit(0);
|
||||
});
|
||||
}
|
||||
RunEvent::WindowEvent { event: WindowEvent::Focused(true), label, .. } => {
|
||||
// Check for plugin updates on window focus
|
||||
let w = app.get_webview_window(&label).unwrap();
|
||||
let h = app.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(3)).await; // Wait a bit so it's not so jarring
|
||||
let val: State<'_, Mutex<PluginUpdater>> = h.state();
|
||||
if let Err(e) = val.lock().await.maybe_check(&w).await {
|
||||
warn!("Failed to check for plugin updates {e:?}");
|
||||
}
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user