Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/opener-require-literal-leading-dot.md
Original file line number Diff line number Diff line change
@@ -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`.
19 changes: 19 additions & 0 deletions plugins/opener/src/config.rs
Original file line number Diff line number Diff line change
@@ -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>,
}
20 changes: 13 additions & 7 deletions plugins/opener/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> {
Expand Down Expand Up @@ -185,19 +187,23 @@ 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")?;
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::<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(())
})
Expand All @@ -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()
}
5 changes: 4 additions & 1 deletion plugins/opener/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)?;

Expand Down
Loading