fix: pasting not working on mac

This commit is contained in:
PandaDEV 2024-11-22 00:15:38 +10:00
parent 042d708c4b
commit 3ae0313975
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C

View file

@ -62,7 +62,28 @@ pub async fn write_and_paste<R: Runtime>(
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<R: Runtime>(
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<R: Runtime>(
.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(())
}
}