Skip to content

Commit ce9888a

Browse files
authored
feat(opener): Add requireLiteralLeadingDot config (#2762)
1 parent 106e46e commit ce9888a

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
opener: minor
3+
opener-js: minor
4+
---
5+
6+
Similar to the `fs` plugin the `opener` plugin now supports a `requireLiteralLeadingDot` configuration in `tauri.conf.json`.

plugins/opener/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use serde::Deserialize;
6+
7+
#[derive(Deserialize)]
8+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
9+
pub struct Config {
10+
/// Whether or not paths that contain components that start with a `.`
11+
/// will require that `.` appears literally in the pattern; `*`, `?`, `**`,
12+
/// or `[...]` will not match. This is useful because such files are
13+
/// conventionally considered hidden on Unix systems and it might be
14+
/// desirable to skip them when listing files.
15+
///
16+
/// Defaults to `true` on Unix systems and `false` on Windows
17+
// dotfiles are not supposed to be exposed by default on unix
18+
pub require_literal_leading_dot: Option<bool>,
19+
}

plugins/opener/src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const PLUGIN_IDENTIFIER: &str = "app.tauri.opener";
1414
tauri::ios_plugin_binding!(init_plugin_opener);
1515

1616
mod commands;
17+
mod config;
1718
mod error;
1819
mod open;
1920
mod reveal_item_in_dir;
@@ -27,12 +28,13 @@ pub use open::{open_path, open_url};
2728
pub use reveal_item_in_dir::reveal_item_in_dir;
2829

2930
pub struct Opener<R: Runtime> {
30-
// we use `fn() -> R` to slicence the unused generic error
31+
// we use `fn() -> R` to silence the unused generic error
3132
// while keeping this struct `Send + Sync` without requiring `R` to be
3233
#[cfg(not(mobile))]
3334
_marker: std::marker::PhantomData<fn() -> R>,
3435
#[cfg(mobile)]
3536
mobile_plugin_handle: PluginHandle<R>,
37+
require_literal_leading_dot: Option<bool>,
3638
}
3739

3840
impl<R: Runtime> Opener<R> {
@@ -185,19 +187,23 @@ impl Builder {
185187
}
186188

187189
/// Build and Initializes the plugin.
188-
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
189-
let mut builder = tauri::plugin::Builder::new("opener")
190-
.setup(|app, _api| {
190+
pub fn build<R: Runtime>(self) -> TauriPlugin<R, Option<config::Config>> {
191+
let mut builder = tauri::plugin::Builder::<R, Option<config::Config>>::new("opener")
192+
.setup(|app, api| {
191193
#[cfg(target_os = "android")]
192-
let handle = _api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?;
194+
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?;
193195
#[cfg(target_os = "ios")]
194-
let handle = _api.register_ios_plugin(init_plugin_opener)?;
196+
let handle = api.register_ios_plugin(init_plugin_opener)?;
195197

196198
app.manage(Opener {
197199
#[cfg(not(mobile))]
198200
_marker: std::marker::PhantomData::<fn() -> R>,
199201
#[cfg(mobile)]
200202
mobile_plugin_handle: handle,
203+
require_literal_leading_dot: api
204+
.config()
205+
.as_ref()
206+
.and_then(|c| c.require_literal_leading_dot),
201207
});
202208
Ok(())
203209
})
@@ -216,6 +222,6 @@ impl Builder {
216222
}
217223

218224
/// Initializes the plugin.
219-
pub fn init<R: Runtime>() -> TauriPlugin<R> {
225+
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
220226
Builder::default().build()
221227
}

plugins/opener/src/scope.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ impl<'a, R: Runtime, M: Manager<R>> Scope<'a, R, M> {
129129
&tauri::utils::config::FsScope::Scope {
130130
allow: self.allowed.iter().filter_map(|e| e.path()).collect(),
131131
deny: self.denied.iter().filter_map(|e| e.path()).collect(),
132-
require_literal_leading_dot: None,
132+
require_literal_leading_dot: self
133+
.manager
134+
.state::<crate::Opener<R>>()
135+
.require_literal_leading_dot,
133136
},
134137
)?;
135138

0 commit comments

Comments
 (0)