mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 11:22:04 +00:00
simplify allow_file impl
This commit is contained in:
parent
802c63fef2
commit
b8882f2fd0
@ -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)?
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user