1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! Runtime access scopes.
//!
//! A scope narrows what an allowed feature may actually touch at runtime.
//! Tauri has two complementary scoping mechanisms:
//!
//! - **The IPC scope**, which is part of the [Access Control List](crate::ipc::RuntimeAuthority):
//! capabilities define which commands each window/webview and origin may call, and the scope
//! attached to a permission is read from a command with [`CommandScope`](crate::ipc::CommandScope)
//! and [`GlobalScope`](crate::ipc::GlobalScope). That scope is static - it is resolved from the
//! capability files at compile time (or added at runtime with
//! [`Manager::add_capability`](crate::Manager::add_capability)) - and it is the command
//! implementation that decides what to do with it.
//! - **The file system scope** in [`mod@fs`], a mutable list of allowed and forbidden glob patterns
//! that the [asset protocol](https://v2.tauri.app/security/asset-protocol/) checks before serving
//! a file. It is seeded from `app > security > assetProtocol > scope` in the configuration and
//! can be changed while the application is running.
//!
//! Use `Manager::asset_protocol_scope` (`protocol-asset` Cargo feature) to get the asset
//! protocol scope and [`fs::Scope::allow_directory`], [`fs::Scope::allow_file`],
//! [`fs::Scope::forbid_directory`] and [`fs::Scope::forbid_file`] to change it, for instance to
//! grant access to a file the user just picked in a dialog:
//!
//! ```rust
//! # #[cfg(feature = "protocol-asset")]
//! # fn run() {
//! use tauri::Manager;
//!
//! tauri::Builder::default()
//! .setup(|app| {
//! app.asset_protocol_scope().allow_directory("/home/user/pictures", true)?;
//! Ok(())
//! });
//! # }
//! ```
//!
//! Scope changes are not persisted: they are lost when the application restarts.
//! Use the [persisted scope plugin](https://v2.tauri.app/plugin/persisted-scope/)
//! if you need them to survive a restart.
/// FS scope.
use Path;
/// Unique id of a scope event.
pub type ScopeEventId = u32;
/// Managed state for all the core scopes in a tauri application.