feat(opener): Add requireLiteralLeadingDot config

pull/2762/head
FabianLars 1 month ago
parent 106e46ed51
commit cf90fcac95
No known key found for this signature in database

@ -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`.

@ -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<bool>,
}

@ -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<R: Runtime> {
// 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<fn() -> R>,
#[cfg(mobile)]
mobile_plugin_handle: PluginHandle<R>,
require_literal_leading_dot: Option<bool>,
}
impl<R: Runtime> Opener<R> {
@ -185,9 +187,9 @@ impl Builder {
}
/// Build and Initializes the plugin.
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
let mut builder = tauri::plugin::Builder::new("opener")
.setup(|app, _api| {
pub fn build<R: Runtime>(self) -> TauriPlugin<R, Option<config::Config>> {
let mut builder = tauri::plugin::Builder::<R, Option<config::Config>>::new("opener")
.setup(|app, api| {
#[cfg(target_os = "android")]
let handle = _api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?;
#[cfg(target_os = "ios")]
@ -198,6 +200,10 @@ impl Builder {
_marker: std::marker::PhantomData::<fn() -> 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<R: Runtime>() -> TauriPlugin<R> {
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
Builder::default().build()
}

@ -129,7 +129,10 @@ impl<'a, R: Runtime, M: Manager<R>> 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::<crate::Opener<R>>()
.require_literal_leading_dot,
},
)?;

Loading…
Cancel
Save