From 1b0aa42b28ebd1997a5c6b28fb2029d70f76f302 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Tue, 3 Oct 2023 02:25:47 +0300 Subject: [PATCH] refactor!: consistent naming in `tauri::scope` module ref: https://github.com/tauri-apps/tauri/issues/7756 --- .changes/tauri-scopes.md | 9 +++++++++ core/tauri/src/app.rs | 12 ++++++------ core/tauri/src/lib.rs | 2 +- core/tauri/src/scope/fs.rs | 3 ++- core/tauri/src/scope/mod.rs | 13 +++++-------- 5 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 .changes/tauri-scopes.md diff --git a/.changes/tauri-scopes.md b/.changes/tauri-scopes.md new file mode 100644 index 000000000000..76767c18ac17 --- /dev/null +++ b/.changes/tauri-scopes.md @@ -0,0 +1,9 @@ +--- +'tauri': 'patch:breaking' +--- + +`tauri::scope` module is recieving a couple of consistency changes: + +- Added `tauri::scope::fs` module. +- Removed `scope::IpcScope` re-export, use `scope::ipc::Scope`. +- Removed `FsScope`, `GlobPattern` and `FsScopeEvent`, use `scope::fs::Scope`, `scope::fs::Pattern` and `scope::fs::Event` respectively. diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 699dedbef1cb..3cc77496f5d7 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -15,7 +15,7 @@ use crate::{ window::{PendingWindow, WindowEvent as RuntimeWindowEvent}, ExitRequestedEventAction, RunEvent as RuntimeRunEvent, }, - scope::IpcScope, + scope, sealed::{ManagerBase, RuntimeOrDispatch}, utils::config::Config, utils::{assets::Assets, Env}, @@ -23,9 +23,6 @@ use crate::{ StateManager, Theme, Window, }; -#[cfg(feature = "protocol-asset")] -use crate::scope::FsScope; - #[cfg(desktop)] use crate::menu::{Menu, MenuEvent}; #[cfg(all(desktop, feature = "tray-icon"))] @@ -1576,9 +1573,12 @@ impl Builder { app.manage(env); app.manage(Scopes { - ipc: IpcScope::new(&app.config()), + ipc: scope::ipc::Scope::new(&app.config()), #[cfg(feature = "protocol-asset")] - asset_protocol: FsScope::for_fs_api(&app, &app.config().tauri.security.asset_protocol.scope)?, + asset_protocol: scope::fs::Scope::for_fs_api( + &app, + &app.config().tauri.security.asset_protocol.scope, + )?, }); app.manage(ChannelDataIpcQueue::default()); diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index 3b5b2e2e1f2d..e77e2ef19e90 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -821,7 +821,7 @@ pub trait Manager: sealed::ManagerBase { } /// Gets the scope for the IPC. - fn ipc_scope(&self) -> IpcScope { + fn ipc_scope(&self) -> scope::ipc::Scope { self.state::().inner().ipc.clone() } diff --git a/core/tauri/src/scope/fs.rs b/core/tauri/src/scope/fs.rs index 8a1bdc2306de..3d1f57b0e96a 100644 --- a/core/tauri/src/scope/fs.rs +++ b/core/tauri/src/scope/fs.rs @@ -9,10 +9,11 @@ use std::{ sync::{Arc, Mutex}, }; -pub use glob::Pattern; use tauri_utils::config::FsScope; use uuid::Uuid; +pub use glob::Pattern; + /// Scope change event. #[derive(Debug, Clone)] pub enum Event { diff --git a/core/tauri/src/scope/mod.rs b/core/tauri/src/scope/mod.rs index 3bb818d384b0..d69fbc07abde 100644 --- a/core/tauri/src/scope/mod.rs +++ b/core/tauri/src/scope/mod.rs @@ -2,24 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -mod fs; +/// FS scope. +pub mod fs; /// IPC scope. 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; /// Managed state for all the core scopes in a tauri application. pub struct Scopes { - pub(crate) ipc: IpcScope, + pub(crate) ipc: ipc::Scope, #[cfg(feature = "protocol-asset")] - pub(crate) asset_protocol: FsScope, + pub(crate) asset_protocol: fs::Scope, } +#[allow(unused)] impl Scopes { /// Allows a directory on the scopes. - #[allow(unused)] pub fn allow_directory>(&self, path: P, recursive: bool) -> crate::Result<()> { #[cfg(feature = "protocol-asset")] self.asset_protocol.allow_directory(path, recursive)?; @@ -27,7 +26,6 @@ impl Scopes { } /// Allows a file on the scopes. - #[allow(unused)] pub fn allow_file>(&self, path: P) -> crate::Result<()> { #[cfg(feature = "protocol-asset")] self.asset_protocol.allow_file(path)?; @@ -35,7 +33,6 @@ impl Scopes { } /// Forbids a file on the scopes. - #[allow(unused)] pub fn forbid_file>(&self, path: P) -> crate::Result<()> { #[cfg(feature = "protocol-asset")] self.asset_protocol.forbid_file(path)?;