From ce9888a2d4c9b449bd2a306f0fa6c76507fd46d3 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Thu, 12 Jun 2025 13:39:36 +0200 Subject: [PATCH] feat(opener): Add requireLiteralLeadingDot config (#2762) --- .../opener-require-literal-leading-dot.md | 6 ++++++ plugins/opener/src/config.rs | 19 ++++++++++++++++++ plugins/opener/src/lib.rs | 20 ++++++++++++------- plugins/opener/src/scope.rs | 5 ++++- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 .changes/opener-require-literal-leading-dot.md create mode 100644 plugins/opener/src/config.rs diff --git a/.changes/opener-require-literal-leading-dot.md b/.changes/opener-require-literal-leading-dot.md new file mode 100644 index 00000000..bc47494a --- /dev/null +++ b/.changes/opener-require-literal-leading-dot.md @@ -0,0 +1,6 @@ +--- +opener: minor +opener-js: minor +--- + +Similar to the `fs` plugin the `opener` plugin now supports a `requireLiteralLeadingDot` configuration in `tauri.conf.json`. \ No newline at end of file diff --git a/plugins/opener/src/config.rs b/plugins/opener/src/config.rs new file mode 100644 index 00000000..db3bae45 --- /dev/null +++ b/plugins/opener/src/config.rs @@ -0,0 +1,19 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use serde::Deserialize; + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct Config { + /// Whether or not paths that contain components that start with a `.` + /// will require that `.` appears literally in the pattern; `*`, `?`, `**`, + /// or `[...]` will not match. This is useful because such files are + /// conventionally considered hidden on Unix systems and it might be + /// desirable to skip them when listing files. + /// + /// Defaults to `true` on Unix systems and `false` on Windows + // dotfiles are not supposed to be exposed by default on unix + pub require_literal_leading_dot: Option, +} diff --git a/plugins/opener/src/lib.rs b/plugins/opener/src/lib.rs index 9934b0fc..23a27a33 100644 --- a/plugins/opener/src/lib.rs +++ b/plugins/opener/src/lib.rs @@ -14,6 +14,7 @@ const PLUGIN_IDENTIFIER: &str = "app.tauri.opener"; tauri::ios_plugin_binding!(init_plugin_opener); mod commands; +mod config; mod error; mod open; mod reveal_item_in_dir; @@ -27,12 +28,13 @@ pub use open::{open_path, open_url}; pub use reveal_item_in_dir::reveal_item_in_dir; pub struct Opener { - // we use `fn() -> R` to slicence the unused generic error + // we use `fn() -> R` to silence the unused generic error // while keeping this struct `Send + Sync` without requiring `R` to be #[cfg(not(mobile))] _marker: std::marker::PhantomData R>, #[cfg(mobile)] mobile_plugin_handle: PluginHandle, + require_literal_leading_dot: Option, } impl Opener { @@ -185,19 +187,23 @@ impl Builder { } /// Build and Initializes the plugin. - pub fn build(self) -> TauriPlugin { - let mut builder = tauri::plugin::Builder::new("opener") - .setup(|app, _api| { + pub fn build(self) -> TauriPlugin> { + let mut builder = tauri::plugin::Builder::>::new("opener") + .setup(|app, api| { #[cfg(target_os = "android")] - let handle = _api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?; + let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?; #[cfg(target_os = "ios")] - let handle = _api.register_ios_plugin(init_plugin_opener)?; + let handle = api.register_ios_plugin(init_plugin_opener)?; app.manage(Opener { #[cfg(not(mobile))] _marker: std::marker::PhantomData:: R>, #[cfg(mobile)] mobile_plugin_handle: handle, + require_literal_leading_dot: api + .config() + .as_ref() + .and_then(|c| c.require_literal_leading_dot), }); Ok(()) }) @@ -216,6 +222,6 @@ impl Builder { } /// Initializes the plugin. -pub fn init() -> TauriPlugin { +pub fn init() -> TauriPlugin> { Builder::default().build() } diff --git a/plugins/opener/src/scope.rs b/plugins/opener/src/scope.rs index 22c9787e..275913d1 100644 --- a/plugins/opener/src/scope.rs +++ b/plugins/opener/src/scope.rs @@ -129,7 +129,10 @@ impl<'a, R: Runtime, M: Manager> Scope<'a, R, M> { &tauri::utils::config::FsScope::Scope { allow: self.allowed.iter().filter_map(|e| e.path()).collect(), deny: self.denied.iter().filter_map(|e| e.path()).collect(), - require_literal_leading_dot: None, + require_literal_leading_dot: self + .manager + .state::>() + .require_literal_leading_dot, }, )?;