Skip to content

Commit

Permalink
simplify allow_file impl
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 13, 2023
1 parent 802c63f commit b8882f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
15 changes: 9 additions & 6 deletions core/tauri/src/manager.rs
Expand Up @@ -1599,12 +1599,15 @@ fn on_window_event<R: Runtime>(
WindowEvent::FileDrop(event) => match event {
FileDropEvent::Hovered(paths) => window.emit(WINDOW_FILE_DROP_HOVER_EVENT, paths)?,
FileDropEvent::Dropped(paths) => {
let scopes = window.state::<Scopes>();
for path in paths {
if path.is_file() {
let _ = scopes.allow_file(path);
} else {
let _ = scopes.allow_directory(path, false);
#[cfg(feature = "protocol-asset")]
{
let scopes = window.state::<Scopes>();
for path in paths {
if path.is_file() {
let _ = scopes.asset_protocol.allow_file(path);
} else {
let _ = scopes.asset_protocol.allow_directory(path, false);
}
}
}
window.emit(WINDOW_FILE_DROP_EVENT, paths)?
Expand Down
17 changes: 0 additions & 17 deletions core/tauri/src/scope/mod.rs
Expand Up @@ -8,26 +8,9 @@ pub mod ipc;

pub use self::ipc::Scope as IpcScope;
pub use fs::{Event as FsScopeEvent, Pattern as GlobPattern, Scope as FsScope};
use std::path::Path;

pub(crate) struct Scopes {
pub ipc: IpcScope,
#[cfg(feature = "protocol-asset")]
pub asset_protocol: FsScope,
}

impl Scopes {
#[allow(dead_code, unused)]
pub(crate) fn allow_directory(&self, path: &Path, recursive: bool) -> crate::Result<()> {
#[cfg(feature = "protocol-asset")]
self.asset_protocol.allow_directory(path, recursive)?;
Ok(())
}

#[allow(dead_code, unused)]
pub(crate) fn allow_file(&self, path: &Path) -> crate::Result<()> {
#[cfg(feature = "protocol-asset")]
self.asset_protocol.allow_file(path)?;
Ok(())
}
}

0 comments on commit b8882f2

Please sign in to comment.