refactor!: consistent naming in tauri::scope module (#7944)

This commit is contained in:
Amr Bashir
2023-10-03 13:50:00 +03:00
committed by GitHub
parent 1bce7397a4
commit b7fd88e18d
5 changed files with 23 additions and 16 deletions

9
.changes/tauri-scopes.md Normal file
View File

@@ -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.

View File

@@ -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<R: Runtime> Builder<R> {
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());

View File

@@ -821,7 +821,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
}
/// Gets the scope for the IPC.
fn ipc_scope(&self) -> IpcScope {
fn ipc_scope(&self) -> scope::ipc::Scope {
self.state::<Scopes>().inner().ipc.clone()
}

View File

@@ -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 {

View File

@@ -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<P: AsRef<Path>>(&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<P: AsRef<Path>>(&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<P: AsRef<Path>>(&self, path: P) -> crate::Result<()> {
#[cfg(feature = "protocol-asset")]
self.asset_protocol.forbid_file(path)?;