Skip to main content

tauri/scope/
mod.rs

1// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5/// FS scope.
6pub mod fs;
7
8use std::path::Path;
9
10/// Unique id of a scope event.
11pub type ScopeEventId = u32;
12
13/// Managed state for all the core scopes in a tauri application.
14pub struct Scopes {
15  #[cfg(feature = "protocol-asset")]
16  pub(crate) asset_protocol: fs::Scope,
17}
18
19#[allow(unused)]
20impl Scopes {
21  /// Allows a directory on the scopes.
22  pub fn allow_directory<P: AsRef<Path>>(&self, path: P, recursive: bool) -> crate::Result<()> {
23    #[cfg(feature = "protocol-asset")]
24    self.asset_protocol.allow_directory(path, recursive)?;
25    Ok(())
26  }
27
28  /// Allows a file on the scopes.
29  pub fn allow_file<P: AsRef<Path>>(&self, path: P) -> crate::Result<()> {
30    #[cfg(feature = "protocol-asset")]
31    self.asset_protocol.allow_file(path)?;
32    Ok(())
33  }
34
35  /// Forbids a file on the scopes.
36  pub fn forbid_file<P: AsRef<Path>>(&self, path: P) -> crate::Result<()> {
37    #[cfg(feature = "protocol-asset")]
38    self.asset_protocol.forbid_file(path)?;
39    Ok(())
40  }
41}