Skip to content

Commit

Permalink
refactor!: consistent naming in tauri::scope module (#7944)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Oct 3, 2023
1 parent 1bce739 commit b7fd88e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .changes/tauri-scopes.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ use crate::{
window::{PendingWindow, WindowEvent as RuntimeWindowEvent},
ExitRequestedEventAction, RunEvent as RuntimeRunEvent,
},
scope::IpcScope,
scope,
sealed::{ManagerBase, RuntimeOrDispatch},
utils::config::Config,
utils::{assets::Assets, Env},
Context, DeviceEventFilter, EventLoopMessage, Icon, Manager, Monitor, Runtime, Scopes,
StateManager, Theme, Window,
};

#[cfg(feature = "protocol-asset")]
use crate::scope::FsScope;

#[cfg(desktop)]
use crate::menu::{Menu, MenuEvent};
#[cfg(all(desktop, feature = "tray-icon"))]
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
3 changes: 2 additions & 1 deletion core/tauri/src/scope/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 5 additions & 8 deletions core/tauri/src/scope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,37 @@
// 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)?;
Ok(())
}

/// 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)?;
Ok(())
}

/// 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)?;
Expand Down

0 comments on commit b7fd88e

Please sign in to comment.