Skip to content

Commit cf175b2

Browse files
committed
feat(clipboard-manager): add support for writing secrets
add `write_secret` command that writes a text into the clipboard and hints clipboard managers to not save the text. uses `arboard`'s `SetExtLinux`, `SetExtWindows`, and `SetExtApple` extensions for each platform.
1 parent 2e5bcdf commit cf175b2

13 files changed

Lines changed: 169 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/capabilities/desktop.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"global-shortcut:allow-register",
1212
"global-shortcut:allow-unregister-all",
1313
{ "identifier": "fs:allow-watch", "allow": ["*", "**/*"] },
14-
"fs:allow-unwatch"
14+
"fs:allow-unwatch",
15+
"clipboard-manager:allow-write-secret"
1516
]
1617
}

examples/api/src/views/Clipboard.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
}
3737
}
3838
39+
function writeSecret() {
40+
clipboard.writeSecret(text).then(() => {
41+
onMessage("Wrote secret to the clipboard")
42+
})
43+
.catch(onMessage)
44+
}
45+
3946
async function read() {
4047
try {
4148
const image = await clipboard.readImage()
@@ -64,6 +71,7 @@
6471
bind:value={text}
6572
/>
6673
<button class="btn" type="button" on:click={writeText}>Write</button>
74+
<button class="btn" type="button" on:click={writeSecret}>Write Secret</button>
6775
<button class="btn" type="button" on:click={writeImage}>Pick Image</button>
6876
<button class="btn" type="button" on:click={read}>Read</button>
6977
</div>

plugins/clipboard-manager/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/clipboard-manager/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const COMMANDS: &[&str] = &[
99
"read_image",
1010
"write_html",
1111
"clear",
12+
"write_secret",
1213
];
1314

1415
fn main() {

plugins/clipboard-manager/guest-js/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,22 @@ async function clear(): Promise<void> {
148148
await invoke('plugin:clipboard-manager|clear')
149149
}
150150

151-
export { writeText, readText, writeHtml, clear, readImage, writeImage }
151+
/**
152+
* Writes text to clipboard and sets hints for clipboard managers to exclude it
153+
* from history
154+
*
155+
* @returns A promise indicating the success or failure of the operation.
156+
*/
157+
async function writeSecret(text: string): Promise<void> {
158+
await invoke('plugin:clipboard-manager|write_secret', { text })
159+
}
160+
161+
export {
162+
writeText,
163+
readText,
164+
writeHtml,
165+
clear,
166+
readImage,
167+
writeImage,
168+
writeSecret
169+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-write-secret"
7+
description = "Enables the write_secret command without any pre-configured scope."
8+
commands.allow = ["write_secret"]
9+
10+
[[permission]]
11+
identifier = "deny-write-secret"
12+
description = "Denies the write_secret command without any pre-configured scope."
13+
commands.deny = ["write_secret"]

plugins/clipboard-manager/permissions/autogenerated/reference.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,32 @@ Denies the write_image command without any pre-configured scope.
148148
<tr>
149149
<td>
150150

151+
`clipboard-manager:allow-write-secret`
152+
153+
</td>
154+
<td>
155+
156+
Enables the write_secret command without any pre-configured scope.
157+
158+
</td>
159+
</tr>
160+
161+
<tr>
162+
<td>
163+
164+
`clipboard-manager:deny-write-secret`
165+
166+
</td>
167+
<td>
168+
169+
Denies the write_secret command without any pre-configured scope.
170+
171+
</td>
172+
</tr>
173+
174+
<tr>
175+
<td>
176+
151177
`clipboard-manager:allow-write-text`
152178

153179
</td>

plugins/clipboard-manager/permissions/schemas/schema.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,18 @@
354354
"const": "deny-write-image",
355355
"markdownDescription": "Denies the write_image command without any pre-configured scope."
356356
},
357+
{
358+
"description": "Enables the write_secret command without any pre-configured scope.",
359+
"type": "string",
360+
"const": "allow-write-secret",
361+
"markdownDescription": "Enables the write_secret command without any pre-configured scope."
362+
},
363+
{
364+
"description": "Denies the write_secret command without any pre-configured scope.",
365+
"type": "string",
366+
"const": "deny-write-secret",
367+
"markdownDescription": "Denies the write_secret command without any pre-configured scope."
368+
},
357369
{
358370
"description": "Enables the write_text command without any pre-configured scope.",
359371
"type": "string",

plugins/clipboard-manager/src/commands.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,13 @@ pub(crate) async fn clear<R: Runtime>(
7878
) -> Result<()> {
7979
clipboard.clear()
8080
}
81+
82+
#[command]
83+
#[cfg(desktop)]
84+
pub(crate) async fn write_secret<R: Runtime>(
85+
_app: AppHandle<R>,
86+
clipboard: State<'_, Clipboard<R>>,
87+
text: &str,
88+
) -> Result<()> {
89+
clipboard.write_secret(text)
90+
}

0 commit comments

Comments
 (0)