-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathcommands.rs
More file actions
90 lines (80 loc) · 2.19 KB
/
commands.rs
File metadata and controls
90 lines (80 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tauri::{command, image::JsImage, AppHandle, Manager, ResourceId, Runtime, State, Webview};
use crate::{Clipboard, Result};
#[command]
#[cfg(desktop)]
pub(crate) async fn write_text<R: Runtime>(
_app: AppHandle<R>,
clipboard: State<'_, Clipboard<R>>,
text: &str,
#[allow(unused)] label: Option<String>,
) -> Result<()> {
clipboard.write_text(text)
}
#[command]
#[cfg(not(desktop))]
pub(crate) async fn write_text<R: Runtime>(
_app: AppHandle<R>,
clipboard: State<'_, Clipboard<R>>,
text: &str,
#[allow(unused)] label: Option<&str>,
) -> Result<()> {
match label {
Some(label) => clipboard.write_text_with_label(text, label),
None => clipboard.write_text(text),
}
}
#[command]
pub(crate) async fn read_text<R: Runtime>(
_app: AppHandle<R>,
clipboard: State<'_, Clipboard<R>>,
) -> Result<String> {
clipboard.read_text()
}
#[command]
pub(crate) async fn write_image<R: Runtime>(
webview: Webview<R>,
clipboard: State<'_, Clipboard<R>>,
image: JsImage,
) -> Result<()> {
let resources_table = webview.resources_table();
let image = image.into_img(&resources_table)?;
clipboard.write_image(&image)
}
#[command]
pub(crate) async fn read_image<R: Runtime>(
webview: Webview<R>,
clipboard: State<'_, Clipboard<R>>,
) -> Result<ResourceId> {
let image = clipboard.read_image()?.to_owned();
let mut resources_table = webview.resources_table();
let rid = resources_table.add(image);
Ok(rid)
}
#[command]
pub(crate) async fn write_html<R: Runtime>(
_app: AppHandle<R>,
clipboard: State<'_, Clipboard<R>>,
html: &str,
alt_text: Option<&str>,
) -> Result<()> {
clipboard.write_html(html, alt_text)
}
#[command]
pub(crate) async fn clear<R: Runtime>(
_app: AppHandle<R>,
clipboard: State<'_, Clipboard<R>>,
) -> Result<()> {
clipboard.clear()
}
#[command]
#[cfg(desktop)]
pub(crate) async fn write_secret<R: Runtime>(
_app: AppHandle<R>,
clipboard: State<'_, Clipboard<R>>,
text: &str,
) -> Result<()> {
clipboard.write_secret(text)
}