From 7e85e09ab9805074875e518c41b1403aaa0f59a9 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 13 May 2023 01:06:49 -0300 Subject: [PATCH] allow fs scope on file drop --- plugins/fs/src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/fs/src/lib.rs b/plugins/fs/src/lib.rs index 2873b108..aff55da3 100644 --- a/plugins/fs/src/lib.rs +++ b/plugins/fs/src/lib.rs @@ -5,7 +5,7 @@ use config::FsScope; use tauri::{ plugin::{Builder as PluginBuilder, TauriPlugin}, - Manager, Runtime, + FileDropEvent, Manager, RunEvent, Runtime, WindowEvent, }; mod commands; @@ -60,5 +60,22 @@ pub fn init() -> TauriPlugin> { )); Ok(()) }) + .on_event(|app, event| { + if let RunEvent::WindowEvent { + label: _, + event: WindowEvent::FileDrop(FileDropEvent::Dropped(paths)), + .. + } = event + { + let scope = app.fs_scope(); + for path in paths { + if path.is_file() { + let _ = scope.allow_file(path); + } else { + let _ = scope.allow_directory(path, false); + } + } + } + }) .build() }