mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-01-31 00:45:24 +01:00
feat(opener): Add requireLiteralLeadingDot config (#2762)
This commit is contained in:
6
.changes/opener-require-literal-leading-dot.md
Normal file
6
.changes/opener-require-literal-leading-dot.md
Normal file
@@ -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
plugins/opener/src/config.rs
Normal file
19
plugins/opener/src/config.rs
Normal file
@@ -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,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(())
|
||||
})
|
||||
@@ -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,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user