{
+ await invoke('plugin:clipboard-manager|write_secret', { text })
+}
+
+export {
+ writeText,
+ readText,
+ writeHtml,
+ clear,
+ readImage,
+ writeImage,
+ writeSecret
+}
diff --git a/plugins/clipboard-manager/permissions/autogenerated/commands/write_secret.toml b/plugins/clipboard-manager/permissions/autogenerated/commands/write_secret.toml
new file mode 100644
index 0000000000..6c28172a0a
--- /dev/null
+++ b/plugins/clipboard-manager/permissions/autogenerated/commands/write_secret.toml
@@ -0,0 +1,13 @@
+# Automatically generated - DO NOT EDIT!
+
+"$schema" = "../../schemas/schema.json"
+
+[[permission]]
+identifier = "allow-write-secret"
+description = "Enables the write_secret command without any pre-configured scope."
+commands.allow = ["write_secret"]
+
+[[permission]]
+identifier = "deny-write-secret"
+description = "Denies the write_secret command without any pre-configured scope."
+commands.deny = ["write_secret"]
diff --git a/plugins/clipboard-manager/permissions/autogenerated/reference.md b/plugins/clipboard-manager/permissions/autogenerated/reference.md
index 98a7fa961f..d4c2430ff2 100644
--- a/plugins/clipboard-manager/permissions/autogenerated/reference.md
+++ b/plugins/clipboard-manager/permissions/autogenerated/reference.md
@@ -148,6 +148,32 @@ Denies the write_image command without any pre-configured scope.
|
+`clipboard-manager:allow-write-secret`
+
+ |
+
+
+Enables the write_secret command without any pre-configured scope.
+
+ |
+
+
+
+|
+
+`clipboard-manager:deny-write-secret`
+
+ |
+
+
+Denies the write_secret command without any pre-configured scope.
+
+ |
+
+
+
+|
+
`clipboard-manager:allow-write-text`
|
diff --git a/plugins/clipboard-manager/permissions/schemas/schema.json b/plugins/clipboard-manager/permissions/schemas/schema.json
index 891c6f0d8d..ee24470338 100644
--- a/plugins/clipboard-manager/permissions/schemas/schema.json
+++ b/plugins/clipboard-manager/permissions/schemas/schema.json
@@ -354,6 +354,18 @@
"const": "deny-write-image",
"markdownDescription": "Denies the write_image command without any pre-configured scope."
},
+ {
+ "description": "Enables the write_secret command without any pre-configured scope.",
+ "type": "string",
+ "const": "allow-write-secret",
+ "markdownDescription": "Enables the write_secret command without any pre-configured scope."
+ },
+ {
+ "description": "Denies the write_secret command without any pre-configured scope.",
+ "type": "string",
+ "const": "deny-write-secret",
+ "markdownDescription": "Denies the write_secret command without any pre-configured scope."
+ },
{
"description": "Enables the write_text command without any pre-configured scope.",
"type": "string",
diff --git a/plugins/clipboard-manager/src/commands.rs b/plugins/clipboard-manager/src/commands.rs
index a8dd94ac06..0d5ac6d214 100644
--- a/plugins/clipboard-manager/src/commands.rs
+++ b/plugins/clipboard-manager/src/commands.rs
@@ -78,3 +78,13 @@ pub(crate) async fn clear(
) -> Result<()> {
clipboard.clear()
}
+
+#[command]
+#[cfg(desktop)]
+pub(crate) async fn write_secret(
+ _app: AppHandle,
+ clipboard: State<'_, Clipboard>,
+ text: &str,
+) -> Result<()> {
+ clipboard.write_secret(text)
+}
diff --git a/plugins/clipboard-manager/src/desktop.rs b/plugins/clipboard-manager/src/desktop.rs
index f3570cc0c7..2b220a4503 100644
--- a/plugins/clipboard-manager/src/desktop.rs
+++ b/plugins/clipboard-manager/src/desktop.rs
@@ -8,6 +8,9 @@ use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime};
use std::{borrow::Cow, sync::Mutex};
+#[cfg(desktop)]
+use crate::secret::ExcludeSecret;
+
pub fn init(
app: &AppHandle,
_api: PluginApi,
@@ -120,4 +123,21 @@ impl Clipboard {
clipboard.lock().unwrap().take();
}
}
+
+ /// This is the same as write_text but it will set hints using [`arboard::SetExtLinux`], [`arboard::SetExtWindows`], or [`arboard::SetExtApple`] depending on the platform.
+ #[cfg(desktop)]
+ pub fn write_secret<'a, T: Into>>(&self, text: T) -> crate::Result<()> {
+ match &self.clipboard {
+ Ok(clipboard) => clipboard
+ .lock()
+ .unwrap()
+ .as_mut()
+ .unwrap()
+ .set()
+ .exclude_secret()
+ .text(text)
+ .map_err(Into::into),
+ Err(e) => Err(crate::Error::Clipboard(e.to_string())),
+ }
+ }
}
diff --git a/plugins/clipboard-manager/src/lib.rs b/plugins/clipboard-manager/src/lib.rs
index 0cbb4e41ec..4f0400901d 100644
--- a/plugins/clipboard-manager/src/lib.rs
+++ b/plugins/clipboard-manager/src/lib.rs
@@ -22,6 +22,9 @@ mod mobile;
mod commands;
mod error;
+#[cfg(desktop)]
+mod secret;
+
pub use error::{Error, Result};
#[cfg(desktop)]
@@ -49,7 +52,9 @@ pub fn init() -> TauriPlugin {
commands::read_image,
commands::write_image,
commands::write_html,
- commands::clear
+ commands::clear,
+ #[cfg(desktop)]
+ commands::write_secret,
])
.setup(|app, api| {
#[cfg(mobile)]
diff --git a/plugins/clipboard-manager/src/secret.rs b/plugins/clipboard-manager/src/secret.rs
new file mode 100644
index 0000000000..78c3484f3e
--- /dev/null
+++ b/plugins/clipboard-manager/src/secret.rs
@@ -0,0 +1,45 @@
+#[cfg(all(
+ unix,
+ not(any(target_os = "macos", target_os = "android", target_os = "emscripten")),
+))]
+use arboard::SetExtLinux;
+
+#[cfg(windows)]
+use arboard::SetExtWindows;
+
+#[cfg(target_os = "macos")]
+use arboard::SetExtApple;
+
+/// Trait to expose exclude from history functionality from [`arboard`] crate's `SetExt*` extensions.
+/// On Linux, it calls [`arboard::SetExtLinux::exclude_from_history`]
+/// On MacOS, it calls [`arboard::SetExtApple::exclude_from_history`]
+/// On Windows, it calls [`arboard::SetExtWindows::exclude_from_history`], [`arboard::SetExtWindows::exclude_from_cloud`], and [`arboard::SetExtWindows::exclude_from_monitoring`]
+pub trait ExcludeSecret<'clipboard> {
+ fn exclude_secret(self) -> arboard::Set<'clipboard>;
+}
+
+#[cfg(all(
+ unix,
+ not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
+))]
+impl<'clipboard> ExcludeSecret<'clipboard> for arboard::Set<'clipboard> {
+ fn exclude_secret(self) -> arboard::Set<'clipboard> {
+ self.exclude_from_history()
+ }
+}
+
+#[cfg(windows)]
+impl<'clipboard> ExcludeSecret<'clipboard> for arboard::Set<'clipboard> {
+ fn exclude_secret(self) -> arboard::Set<'clipboard> {
+ self.exclude_from_history()
+ .exclude_from_cloud()
+ .exclude_from_monitoring()
+ }
+}
+
+#[cfg(target_os = "macos")]
+impl<'clipboard> ExcludeSecret<'clipboard> for arboard::Set<'clipboard> {
+ fn exclude_secret(self) -> arboard::Set<'clipboard> {
+ self.exclude_from_history()
+ }
+}