simplify persisted-scopes impl (remove protocol-asset feature)

pull/355/head
Lucas Nogueira 2 years ago
parent 7e85e09ab9
commit 0425d569ce
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7

14
Cargo.lock generated

@ -4960,7 +4960,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri" name = "tauri"
version = "2.0.0-alpha.8" version = "2.0.0-alpha.8"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes 1.4.0", "bytes 1.4.0",
@ -5010,7 +5010,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-build" name = "tauri-build"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cargo_toml", "cargo_toml",
@ -5030,7 +5030,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-codegen" name = "tauri-codegen"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"base64 0.21.0", "base64 0.21.0",
"brotli", "brotli",
@ -5055,7 +5055,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-macros" name = "tauri-macros"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"heck 0.4.1", "heck 0.4.1",
"proc-macro2", "proc-macro2",
@ -5449,7 +5449,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "0.13.0-alpha.4" version = "0.13.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"gtk", "gtk",
"http", "http",
@ -5469,7 +5469,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime-wry" name = "tauri-runtime-wry"
version = "0.13.0-alpha.4" version = "0.13.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"gtk", "gtk",
@ -5489,7 +5489,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-utils" name = "tauri-utils"
version = "2.0.0-alpha.4" version = "2.0.0-alpha.4"
source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#2bbd957a3b1b1072487f5890071317593481f118" source = "git+https://github.com/tauri-apps/tauri?branch=refactor/cleanup#04735516d5b459421e49755d4821a0773afb6969"
dependencies = [ dependencies = [
"aes-gcm 0.10.1", "aes-gcm 0.10.1",
"brotli", "brotli",

@ -5,7 +5,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tauri::{command, Runtime, State, Window}; use tauri::{command, Manager, Runtime, State, Window};
use tauri_plugin_fs::FsExt; use tauri_plugin_fs::FsExt;
use crate::{Dialog, FileDialogBuilder, FileResponse, MessageDialogKind, Result}; use crate::{Dialog, FileDialogBuilder, FileResponse, MessageDialogKind, Result};
@ -136,6 +136,9 @@ pub(crate) async fn open<R: Runtime>(
if let Some(files) = &files { if let Some(files) = &files {
for file in files { for file in files {
window.fs_scope().allow_file(&file.path)?; window.fs_scope().allow_file(&file.path)?;
window
.state::<tauri::scope::Scopes>()
.allow_file(&file.path)?;
} }
} }
OpenResponse::Files(files) OpenResponse::Files(files)
@ -143,6 +146,9 @@ pub(crate) async fn open<R: Runtime>(
let file = dialog_builder.blocking_pick_file(); let file = dialog_builder.blocking_pick_file();
if let Some(file) = &file { if let Some(file) = &file {
window.fs_scope().allow_file(&file.path)?; window.fs_scope().allow_file(&file.path)?;
window
.state::<tauri::scope::Scopes>()
.allow_file(&file.path)?;
} }
OpenResponse::File(file) OpenResponse::File(file)
}; };
@ -181,6 +187,7 @@ pub(crate) async fn save<R: Runtime>(
if let Some(s) = window.try_fs_scope() { if let Some(s) = window.try_fs_scope() {
s.allow_file(p)?; s.allow_file(p)?;
} }
window.state::<tauri::scope::Scopes>().allow_file(p)?;
} }
Ok(path) Ok(path)

@ -18,6 +18,3 @@ thiserror.workspace = true
aho-corasick = "1.0" aho-corasick = "1.0"
bincode = "1" bincode = "1"
tauri-plugin-fs = { path = "../fs", version = "0.0.0" } tauri-plugin-fs = { path = "../fs", version = "0.0.0" }
[features]
protocol-asset = [ "tauri/protocol-asset" ]

@ -87,18 +87,18 @@ fn save_scopes<R: Runtime>(app: &AppHandle<R>, app_dir: &Path, scope_state_path:
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("persisted-scope") Builder::new("persisted-scope")
.setup(|app, _api| { .setup(|app, _api| {
let fs_scope = app.fs_scope(); let fs_scope = app.try_fs_scope();
#[cfg(feature = "protocol-asset")] let core_scopes = app.state::<tauri::scope::Scopes>();
let asset_protocol_scope = app.asset_protocol_scope();
let app = app.clone(); let app = app.clone();
let app_dir = app.path().app_data_dir(); let app_dir = app.path().app_data_dir();
if let Ok(app_dir) = app_dir { if let Ok(app_dir) = app_dir {
let scope_state_path = app_dir.join(SCOPE_STATE_FILENAME); let scope_state_path = app_dir.join(SCOPE_STATE_FILENAME);
let _ = fs_scope.forbid_file(&scope_state_path); if let Some(s) = fs_scope {
#[cfg(feature = "protocol-asset")] let _ = s.forbid_file(&scope_state_path);
let _ = asset_protocol_scope.forbid_file(&scope_state_path); }
let _ = core_scopes.forbid_file(&scope_state_path);
// We're trying to fix broken .persisted-scope files seamlessly, so we'll be running this on the values read on the saved file. // We're trying to fix broken .persisted-scope files seamlessly, so we'll be running this on the values read on the saved file.
// We will still save some semi-broken values because the scope events are quite spammy and we don't want to reduce runtime performance any further. // We will still save some semi-broken values because the scope events are quite spammy and we don't want to reduce runtime performance any further.
@ -112,16 +112,18 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
for allowed in &scope.allowed_paths { for allowed in &scope.allowed_paths {
let allowed = fix_pattern(&ac, allowed); let allowed = fix_pattern(&ac, allowed);
let _ = fs_scope.allow_file(&allowed); if let Some(s) = fs_scope {
#[cfg(feature = "protocol-asset")] let _ = s.allow_file(&allowed);
let _ = asset_protocol_scope.allow_file(&allowed); }
let _ = core_scopes.allow_file(&allowed);
} }
for forbidden in &scope.forbidden_patterns { for forbidden in &scope.forbidden_patterns {
let forbidden = fix_pattern(&ac, forbidden); let forbidden = fix_pattern(&ac, forbidden);
let _ = fs_scope.forbid_file(&forbidden); if let Some(s) = fs_scope {
#[cfg(feature = "protocol-asset")] let _ = s.forbid_file(&forbidden);
let _ = asset_protocol_scope.forbid_file(&forbidden); }
let _ = core_scopes.forbid_file(&forbidden);
} }
// Manually save the fixed scopes to disk once. // Manually save the fixed scopes to disk once.
@ -129,11 +131,13 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
save_scopes(&app, &app_dir, &scope_state_path); save_scopes(&app, &app_dir, &scope_state_path);
} }
fs_scope.listen(move |event| { if let Some(s) = fs_scope {
if let FsScopeEvent::PathAllowed(_) = event { s.listen(move |event| {
save_scopes(&app, &app_dir, &scope_state_path); if let FsScopeEvent::PathAllowed(_) = event {
} save_scopes(&app, &app_dir, &scope_state_path);
}); }
});
}
} }
Ok(()) Ok(())
}) })

Loading…
Cancel
Save