feat(opener): Add requireLiteralLeadingDot config (#2762)

pull/2766/head
Fabian-Lars 1 month ago committed by GitHub
parent 106e46ed51
commit ce9888a2d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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); tauri::ios_plugin_binding!(init_plugin_opener);
mod commands; mod commands;
mod config;
mod error; mod error;
mod open; mod open;
mod reveal_item_in_dir; 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 use reveal_item_in_dir::reveal_item_in_dir;
pub struct Opener<R: Runtime> { 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 // while keeping this struct `Send + Sync` without requiring `R` to be
#[cfg(not(mobile))] #[cfg(not(mobile))]
_marker: std::marker::PhantomData<fn() -> R>, _marker: std::marker::PhantomData<fn() -> R>,
#[cfg(mobile)] #[cfg(mobile)]
mobile_plugin_handle: PluginHandle<R>, mobile_plugin_handle: PluginHandle<R>,
require_literal_leading_dot: Option<bool>,
} }
impl<R: Runtime> Opener<R> { impl<R: Runtime> Opener<R> {
@ -185,19 +187,23 @@ impl Builder {
} }
/// Build and Initializes the plugin. /// Build and Initializes the plugin.
pub fn build<R: Runtime>(self) -> TauriPlugin<R> { pub fn build<R: Runtime>(self) -> TauriPlugin<R, Option<config::Config>> {
let mut builder = tauri::plugin::Builder::new("opener") let mut builder = tauri::plugin::Builder::<R, Option<config::Config>>::new("opener")
.setup(|app, _api| { .setup(|app, api| {
#[cfg(target_os = "android")] #[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")] #[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 { app.manage(Opener {
#[cfg(not(mobile))] #[cfg(not(mobile))]
_marker: std::marker::PhantomData::<fn() -> R>, _marker: std::marker::PhantomData::<fn() -> R>,
#[cfg(mobile)] #[cfg(mobile)]
mobile_plugin_handle: handle, mobile_plugin_handle: handle,
require_literal_leading_dot: api
.config()
.as_ref()
.and_then(|c| c.require_literal_leading_dot),
}); });
Ok(()) Ok(())
}) })
@ -216,6 +222,6 @@ impl Builder {
} }
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
Builder::default().build() Builder::default().build()
} }

@ -129,7 +129,10 @@ impl<'a, R: Runtime, M: Manager<R>> Scope<'a, R, M> {
&tauri::utils::config::FsScope::Scope { &tauri::utils::config::FsScope::Scope {
allow: self.allowed.iter().filter_map(|e| e.path()).collect(), allow: self.allowed.iter().filter_map(|e| e.path()).collect(),
deny: self.denied.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