Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
Clipboard.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Wire methods: clipboard operations via `nativeHost:*Clipboard*`.
4//! Backed by `arboard` for cross-platform text clipboard access.
5//! Binary clipboard (`readClipboardBuffer`, `writeClipboardBuffer`) returns
6//! empty/null - binary clipboard is rarely used by VS Code core.
7
8use serde_json::{Value, json};
9
10pub async fn NativeReadClipboardText(_Arguments:Vec<Value>) -> Result<Value, String> {
11	match arboard::Clipboard::new() {
12		Ok(mut Cb) => Ok(json!(Cb.get_text().unwrap_or_default())),
13		Err(_) => Ok(json!("")),
14	}
15}
16
17pub async fn NativeWriteClipboardText(Arguments:Vec<Value>) -> Result<Value, String> {
18	let Text = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
19	if let Ok(mut Cb) = arboard::Clipboard::new() {
20		let _ = Cb.set_text(Text);
21	}
22	Ok(Value::Null)
23}
24
25/// macOS has a separate find pasteboard; reuse the general clipboard for
26/// parity with VS Code on Linux/Windows.
27pub async fn NativeReadClipboardFindText(_Arguments:Vec<Value>) -> Result<Value, String> {
28	match arboard::Clipboard::new() {
29		Ok(mut Cb) => Ok(json!(Cb.get_text().unwrap_or_default())),
30		Err(_) => Ok(json!("")),
31	}
32}
33
34pub async fn NativeWriteClipboardFindText(Arguments:Vec<Value>) -> Result<Value, String> {
35	let Text = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
36	if let Ok(mut Cb) = arboard::Clipboard::new() {
37		let _ = Cb.set_text(Text);
38	}
39	Ok(Value::Null)
40}
41
42pub async fn NativeReadClipboardBuffer(_Arguments:Vec<Value>) -> Result<Value, String> { Ok(json!([])) }
43
44pub async fn NativeWriteClipboardBuffer(_Arguments:Vec<Value>) -> Result<Value, String> { Ok(Value::Null) }
45
46pub async fn NativeHasClipboard(_Arguments:Vec<Value>) -> Result<Value, String> { Ok(json!(false)) }
47
48/// Trigger a paste operation. On Tauri 2.x there is no direct `paste` API;
49/// return false so callers fall through to the OS's native paste shortcut.
50pub async fn NativeTriggerPaste(_Arguments:Vec<Value>) -> Result<Value, String> { Ok(json!(false)) }
51
52/// Read an image from the clipboard. Binary clipboard is not yet
53/// implemented - return an empty array so callers get a safe fallback.
54pub async fn NativeReadImage(_Arguments:Vec<Value>) -> Result<Value, String> { Ok(json!([])) }