fix the paste issue + comment dead code
This commit is contained in:
parent
6b545d3acd
commit
99760ed712
3 changed files with 99 additions and 86 deletions
46
src-tauri/Cargo.lock
generated
46
src-tauri/Cargo.lock
generated
|
|
@ -1649,6 +1649,25 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
|
checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enigo"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0cf6f550bbbdd5fe66f39d429cb2604bcdacbf00dca0f5bbe2e9306a0009b7c6"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation 0.10.0",
|
||||||
|
"core-graphics 0.24.0",
|
||||||
|
"foreign-types-shared 0.3.1",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"objc2",
|
||||||
|
"objc2-app-kit",
|
||||||
|
"objc2-foundation",
|
||||||
|
"windows 0.58.0",
|
||||||
|
"xkbcommon",
|
||||||
|
"xkeysym",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "enum-map"
|
name = "enum-map"
|
||||||
version = "2.7.3"
|
version = "2.7.3"
|
||||||
|
|
@ -2416,6 +2435,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cpal",
|
"cpal",
|
||||||
|
"enigo",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
"rdev",
|
"rdev",
|
||||||
|
|
@ -3426,6 +3446,15 @@ version = "2.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memmap2"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.6.5"
|
version = "0.6.5"
|
||||||
|
|
@ -7735,6 +7764,23 @@ dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xkbcommon"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8d66ca9352cbd4eecbbc40871d8a11b4ac8107cfc528a6e14d7c19c69d0e1ac9"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"memmap2",
|
||||||
|
"xkeysym",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xkeysym"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yoke"
|
name = "yoke"
|
||||||
version = "0.7.5"
|
version = "0.7.5"
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ tokio = "1.43.0"
|
||||||
vad-rs = "0.1.5"
|
vad-rs = "0.1.5"
|
||||||
tauri-plugin-upload = "2"
|
tauri-plugin-upload = "2"
|
||||||
tauri-plugin-stronghold = "2"
|
tauri-plugin-stronghold = "2"
|
||||||
|
enigo = "0.3.0"
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
whisper-rs = { version = "0.13.2", features = ["metal"] }
|
whisper-rs = { version = "0.13.2", features = ["metal"] }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
mod managers;
|
mod managers;
|
||||||
|
|
||||||
|
use enigo::{Enigo, Keyboard, Settings};
|
||||||
use log::info;
|
use log::info;
|
||||||
use managers::audio::AudioRecordingManager;
|
use managers::audio::AudioRecordingManager;
|
||||||
use managers::keybinding::KeyBindingManager;
|
use managers::keybinding::KeyBindingManager;
|
||||||
|
|
@ -12,104 +13,69 @@ use tauri::Manager;
|
||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||||
|
|
||||||
fn try_send_event(event: &EventType) {
|
// fn send_copy() {
|
||||||
if let Err(SimulateError) = simulate(event) {
|
// // Determine the modifier key based on the OS
|
||||||
println!("We could not send {:?}", event);
|
// #[cfg(target_os = "macos")]
|
||||||
}
|
// let modifier_key = Key::MetaLeft; // Command key on macOS
|
||||||
|
// #[cfg(not(target_os = "macos"))]
|
||||||
|
// let modifier_key = Key::ControlLeft; // Control key on other systems
|
||||||
|
|
||||||
|
// // Press both keys
|
||||||
|
// send(EventType::KeyPress(modifier_key));
|
||||||
|
// send(EventType::KeyPress(Key::KeyC));
|
||||||
|
|
||||||
|
// // Release both keys
|
||||||
|
// send(EventType::KeyRelease(Key::KeyC));
|
||||||
|
// send(EventType::KeyRelease(modifier_key));
|
||||||
|
// }
|
||||||
|
|
||||||
|
fn paste(text: String) {
|
||||||
|
let mut enigo = Enigo::new(&Settings::default()).unwrap();
|
||||||
|
enigo.text(&text).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(event: EventType) {
|
// fn get_highlighted_text(app_handle: tauri::AppHandle) -> String {
|
||||||
try_send_event(&event);
|
// let clipboard = app_handle.clipboard();
|
||||||
thread::sleep(time::Duration::from_millis(60));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_paste() {
|
// // save the clipboard content
|
||||||
// Determine the modifier key based on the OS
|
// let clipboard_content = clipboard.read_text().unwrap_or_default();
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
let modifier_key = Key::MetaLeft; // Command key on macOS
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
let modifier_key = Key::ControlLeft; // Control key on other systems
|
|
||||||
|
|
||||||
// Press both keys
|
// // empty the clipboard
|
||||||
send(EventType::KeyPress(modifier_key));
|
// clipboard.write_text("").unwrap();
|
||||||
send(EventType::KeyPress(Key::KeyV));
|
|
||||||
|
|
||||||
// Release both keys
|
// // issue 'copy'
|
||||||
send(EventType::KeyRelease(Key::KeyV));
|
// send_copy();
|
||||||
send(EventType::KeyRelease(modifier_key));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_copy() {
|
// // get the highlighted text
|
||||||
// Determine the modifier key based on the OS
|
// let highlighted_text = clipboard.read_text().unwrap_or_default();
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
let modifier_key = Key::MetaLeft; // Command key on macOS
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
let modifier_key = Key::ControlLeft; // Control key on other systems
|
|
||||||
|
|
||||||
// Press both keys
|
// // restore the clipboard content
|
||||||
send(EventType::KeyPress(modifier_key));
|
// clipboard.write_text(&clipboard_content).unwrap();
|
||||||
send(EventType::KeyPress(Key::KeyC));
|
|
||||||
|
|
||||||
// Release both keys
|
// highlighted_text
|
||||||
send(EventType::KeyRelease(Key::KeyC));
|
// }
|
||||||
send(EventType::KeyRelease(modifier_key));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn paste(text: String, app_handle: tauri::AppHandle) {
|
// const INSTRUCT_SYS: &str = r#"
|
||||||
let clipboard = app_handle.clipboard();
|
// You are a helpful assistant. You will receive voice transcriptions
|
||||||
|
// from a user that may include both a command/question and some
|
||||||
|
// minimal context to help you respond appropriately.
|
||||||
|
|
||||||
// get the current clipboard content
|
// For example, the user might say:
|
||||||
let clipboard_content = clipboard.read_text().unwrap_or_default();
|
// - A direct question with no context: "What is the capital of France?"
|
||||||
|
// - A command with context: "get commit message I fixed the bug in the login system"
|
||||||
|
// "#;
|
||||||
|
|
||||||
clipboard.write_text(&text).unwrap();
|
// const CODE_SYS: &str = r#"
|
||||||
send_paste();
|
// You are a code-only assistant. I will provide you with selected text or clipboard content along with instructions. If I request code, output only the exact code implementation. If I request a terminal command, provide only the valid command syntax. Never use markdown, explanations, or additional text.
|
||||||
|
|
||||||
// restore the clipboard
|
// When I share selected text or clipboard content, use that as context for generating your response. The output should be ready to copy and paste directly, with no formatting or commentary. For terminal commands, ensure they are valid for the specified environment. Note for terminal commands, I typically use lowercase instead of uppercase. You may also be given them directly, but need to translate them into a way that can actually be executed in the terminal because the transcription you are given might be poor.
|
||||||
clipboard.write_text(&clipboard_content).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_highlighted_text(app_handle: tauri::AppHandle) -> String {
|
// Output only:
|
||||||
let clipboard = app_handle.clipboard();
|
// - Raw code implementation when code is requested
|
||||||
|
// - Terminal command syntax when a command is requested
|
||||||
// save the clipboard content
|
// - No markdown, no backticks, no explanations
|
||||||
let clipboard_content = clipboard.read_text().unwrap_or_default();
|
// - No additional text or descriptions
|
||||||
|
// "#;
|
||||||
// empty the clipboard
|
|
||||||
clipboard.write_text("").unwrap();
|
|
||||||
|
|
||||||
// issue 'copy'
|
|
||||||
send_copy();
|
|
||||||
|
|
||||||
// get the highlighted text
|
|
||||||
let highlighted_text = clipboard.read_text().unwrap_or_default();
|
|
||||||
|
|
||||||
// restore the clipboard content
|
|
||||||
clipboard.write_text(&clipboard_content).unwrap();
|
|
||||||
|
|
||||||
highlighted_text
|
|
||||||
}
|
|
||||||
|
|
||||||
const INSTRUCT_SYS: &str = r#"
|
|
||||||
You are a helpful assistant. You will receive voice transcriptions
|
|
||||||
from a user that may include both a command/question and some
|
|
||||||
minimal context to help you respond appropriately.
|
|
||||||
|
|
||||||
For example, the user might say:
|
|
||||||
- A direct question with no context: "What is the capital of France?"
|
|
||||||
- A command with context: "get commit message I fixed the bug in the login system"
|
|
||||||
"#;
|
|
||||||
|
|
||||||
const CODE_SYS: &str = r#"
|
|
||||||
You are a code-only assistant. I will provide you with selected text or clipboard content along with instructions. If I request code, output only the exact code implementation. If I request a terminal command, provide only the valid command syntax. Never use markdown, explanations, or additional text.
|
|
||||||
|
|
||||||
When I share selected text or clipboard content, use that as context for generating your response. The output should be ready to copy and paste directly, with no formatting or commentary. For terminal commands, ensure they are valid for the specified environment. Note for terminal commands, I typically use lowercase instead of uppercase. You may also be given them directly, but need to translate them into a way that can actually be executed in the terminal because the transcription you are given might be poor.
|
|
||||||
|
|
||||||
Output only:
|
|
||||||
- Raw code implementation when code is requested
|
|
||||||
- Terminal command syntax when a command is requested
|
|
||||||
- No markdown, no backticks, no explanations
|
|
||||||
- No additional text or descriptions
|
|
||||||
"#;
|
|
||||||
|
|
||||||
fn register_bindings(manager: &mut KeyBindingManager) {
|
fn register_bindings(manager: &mut KeyBindingManager) {
|
||||||
manager.register(
|
manager.register(
|
||||||
|
|
@ -128,7 +94,7 @@ fn register_bindings(manager: &mut KeyBindingManager) {
|
||||||
match ctx.transcription_manager.transcribe(samples) {
|
match ctx.transcription_manager.transcribe(samples) {
|
||||||
Ok(transcription) => {
|
Ok(transcription) => {
|
||||||
println!("Transcription: {}", transcription);
|
println!("Transcription: {}", transcription);
|
||||||
paste(transcription, ctx.app_handle.clone());
|
paste(transcription);
|
||||||
}
|
}
|
||||||
Err(err) => println!("Transcription error: {}", err),
|
Err(err) => println!("Transcription error: {}", err),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue