diff --git a/src-tauri/src/api/clipboard.rs b/src-tauri/src/api/clipboard.rs index c587cb4..3150c58 100644 --- a/src-tauri/src/api/clipboard.rs +++ b/src-tauri/src/api/clipboard.rs @@ -62,7 +62,28 @@ pub async fn write_and_paste( IS_PROGRAMMATIC_PASTE.store(true, Ordering::SeqCst); - simulate_paste(); + thread::spawn(|| { + thread::sleep(Duration::from_millis(100)); + + #[cfg(target_os = "macos")] + let modifier_key = Key::MetaLeft; + #[cfg(not(target_os = "macos"))] + let modifier_key = Key::ControlLeft; + + let events = vec![ + EventType::KeyPress(modifier_key), + EventType::KeyPress(Key::KeyV), + EventType::KeyRelease(Key::KeyV), + EventType::KeyRelease(modifier_key), + ]; + + for event in events { + if let Err(e) = simulate(&event) { + println!("Simulation error: {:?}", e); + } + thread::sleep(Duration::from_millis(20)); + } + }); tokio::spawn(async { tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; @@ -72,22 +93,6 @@ pub async fn write_and_paste( Ok(()) } -fn simulate_paste() { - let mut events = vec![ - EventType::KeyPress(Key::ControlLeft), - EventType::KeyPress(Key::KeyV), - EventType::KeyRelease(Key::KeyV), - EventType::KeyRelease(Key::ControlLeft), - ]; - - thread::sleep(Duration::from_millis(100)); - - for event in events.drain(..) { - simulate(&event).unwrap(); - thread::sleep(Duration::from_millis(20)); - } -} - #[tauri::command] pub fn get_image_path(app_handle: tauri::AppHandle, filename: String) -> String { let app_data_dir = app_handle @@ -246,6 +251,8 @@ async fn insert_content_if_not_exists( .bind(favicon_base64) .execute(&pool) .await; + + let _ = app_handle.emit("clipboard-content-updated", ()); } } @@ -302,4 +309,4 @@ pub fn start_monitor(app_handle: AppHandle) -> Result<(), String> { .emit("plugin:clipboard://clipboard-monitor/status", true) .map_err(|e| e.to_string())?; Ok(()) -} \ No newline at end of file +}