diff --git a/plugins/fs-watch/src/lib.rs b/plugins/fs-watch/src/lib.rs index facf3298..ee87535c 100644 --- a/plugins/fs-watch/src/lib.rs +++ b/plugins/fs-watch/src/lib.rs @@ -3,8 +3,7 @@ use notify::{ Watcher as _, }; use serde::{ser::Serializer, Deserialize, Serialize}; -use serde_json::Value as JsonValue; -use tauri::{command, plugin::Plugin, AppHandle, Invoke, Manager, Runtime, State, Window}; +use tauri::{command, plugin::{Builder as PluginBuilder, TauriPlugin}, Manager, Runtime, State, Window}; use std::{ collections::HashMap, @@ -160,30 +159,12 @@ async fn unwatch(watchers: State<'_, WatcherCollection>, id: Id) -> Result<()> { Ok(()) } -/// Tauri plugin. -pub struct Watcher { - invoke_handler: Box) + Send + Sync>, -} - -impl Default for Watcher { - fn default() -> Self { - Self { - invoke_handler: Box::new(tauri::generate_handler![watch, unwatch]), - } - } -} - -impl Plugin for Watcher { - fn name(&self) -> &'static str { - "fs-watch" - } - - fn initialize(&mut self, app: &AppHandle, _config: JsonValue) -> tauri::plugin::Result<()> { - app.manage(WatcherCollection::default()); - Ok(()) - } - - fn extend_api(&mut self, message: Invoke) { - (self.invoke_handler)(message) - } -} +pub fn init() -> TauriPlugin { + PluginBuilder::new("fs-watch") + .invoke_handler(tauri::generate_handler![watch, unwatch]) + .setup(|app| { + app.manage(WatcherCollection::default()); + Ok(()) + }) + .build() +} \ No newline at end of file