remove cruft

This commit is contained in:
CJ Pais 2025-05-06 11:19:23 -07:00
parent 09475c12e5
commit 2f38e407a5
4 changed files with 40 additions and 153 deletions

View file

@ -5,10 +5,9 @@ use managers::audio::AudioRecordingManager;
use managers::keybinding::KeyBindingManager;
use managers::transcription::TranscriptionManager;
use rdev::{simulate, EventType, Key, SimulateError};
use rig::{completion::Prompt, providers::anthropic};
use std::sync::{Arc, Mutex};
use std::{thread, time};
use tauri::Manager;
use tauri::{Emitter, Manager};
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_clipboard_manager::ClipboardExt;
@ -39,22 +38,6 @@ fn send_paste() {
send(EventType::KeyRelease(modifier_key));
}
fn send_copy() {
// Determine the modifier key based on the OS
#[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, app_handle: tauri::AppHandle) {
let clipboard = app_handle.clipboard();
@ -68,49 +51,6 @@ fn paste(text: String, app_handle: tauri::AppHandle) {
clipboard.write_text(&clipboard_content).unwrap();
}
fn get_highlighted_text(app_handle: tauri::AppHandle) -> String {
let clipboard = app_handle.clipboard();
// save the clipboard content
let clipboard_content = clipboard.read_text().unwrap_or_default();
// 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) {
manager.register(
"ctrl-meta".to_string(),
@ -136,93 +76,6 @@ fn register_bindings(manager: &mut KeyBindingManager) {
}))
},
);
// Register LLM Call after Transcription
// manager.register(
// "shift-alt".to_string(),
// vec![Key::ShiftLeft, Key::Alt],
// |ctx| {
// info!("Shift+Alt pressed!");
// ctx.recording_manager.try_start_recording("shift-alt");
// None
// },
// |ctx| {
// info!("release being called from shift-alt");
// let ctx = ctx.clone();
// Some(tauri::async_runtime::spawn(async move {
// if let Some(samples) = ctx.recording_manager.stop_recording("shift-alt") {
// if let Ok(transcription) = ctx.transcription_manager.transcribe(samples) {
// println!("Transcription: {}", transcription);
// let instruct = ctx
// .anthropic
// .agent(anthropic::CLAUDE_3_5_SONNET)
// .preamble(INSTRUCT_SYS)
// .temperature(0.5)
// .build();
// let highlighted_text = get_highlighted_text(ctx.app_handle.clone());
// println!("Highlighted Text: {}", highlighted_text);
// let prompt = format!("{}\n\ncontext:{}\n", transcription, highlighted_text);
// match instruct.prompt(prompt).await {
// Ok(response) => {
// println!("Sonnet response: {}", response);
// paste(response, ctx.app_handle.clone());
// }
// Err(err) => println!("Sonnet error: {}", err),
// }
// }
// }
// }))
// },
// );
// manager.register(
// "ctrl-alt-meta".to_string(),
// vec![Key::ControlLeft, Key::Alt, Key::MetaLeft],
// |ctx| {
// info!("Ctrl+Alt+Meta pressed!");
// ctx.recording_manager.try_start_recording("ctrl-alt-meta");
// None
// },
// |ctx| {
// info!("release being called from ctrl-alt-meta");
// let ctx = ctx.clone();
// Some(tauri::async_runtime::spawn(async move {
// if let Some(samples) = ctx.recording_manager.stop_recording("ctrl-alt-meta") {
// let samples: Vec<f32> = samples; // explicit type annotation
// match ctx.transcription_manager.transcribe(samples) {
// Ok(transcription) => {
// println!("Transcription: {}", transcription);
// let code = ctx
// .anthropic
// .agent(anthropic::CLAUDE_3_5_SONNET)
// .preamble(CODE_SYS)
// .temperature(0.5)
// .build();
// let highlighted_text = get_highlighted_text(ctx.app_handle.clone());
// let prompt =
// format!("{}\n\ncontext:{}\n", transcription, highlighted_text);
// match code.prompt(prompt).await {
// Ok(response) => {
// println!("Sonnet response: {}", response);
// paste(response, ctx.app_handle.clone());
// }
// Err(err) => println!("Sonnet error: {}", err),
// }
// }
// Err(err) => println!("Transcription error: {}", err),
// }
// } else {
// println!("No samples recorded");
// }
// }))
// },
// );
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
@ -230,9 +83,9 @@ pub fn run() {
env_logger::init();
tauri::Builder::default()
.plugin(tauri_plugin_stronghold::Builder::new(|pass| todo!()).build())
.plugin(tauri_plugin_stronghold::Builder::new(|_pass| todo!()).build())
.plugin(tauri_plugin_upload::init())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
// .plugin(tauri_plugin_global_shortcut::Builder::new().build())
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
@ -287,6 +140,40 @@ pub fn run() {
})
.unwrap();
});
#[cfg(desktop)]
{
use tauri_plugin_global_shortcut::{Code, Modifiers, ShortcutState};
app.handle().plugin(
tauri_plugin_global_shortcut::Builder::new()
.with_shortcuts(["ctrl+d", "alt+space"])?
.with_handler(|app, shortcut, event| {
if event.state == ShortcutState::Pressed {
if shortcut.matches(Modifiers::CONTROL, Code::KeyD) {
let _ = app.emit("shortcut-event", "Ctrl+D triggered");
println!("Ctrl+D triggered");
}
if shortcut.matches(Modifiers::ALT, Code::Space) {
let _ = app.emit("shortcut-event", "Alt+Space triggered");
println!("Alt+Space triggered");
}
}
if event.state == ShortcutState::Released {
if shortcut.matches(Modifiers::CONTROL, Code::KeyD) {
let _ = app.emit("shortcut-event", "Ctrl+D released");
println!("Ctrl+D released");
}
if shortcut.matches(Modifiers::ALT, Code::Space) {
let _ = app.emit("shortcut-event", "Alt+Space released");
println!("Alt+Space released");
}
}
})
.build(),
)?;
}
Ok(())
})
.on_window_event(|app, event| match event {

View file

@ -3,7 +3,7 @@ use rubato::{FftFixedIn, Resampler};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::vec::Vec;
use vad_rs::{Vad, VadStatus};
use vad_rs::Vad;
#[derive(Clone, Debug)]
pub enum RecordingState {
@ -81,7 +81,7 @@ impl AudioRecordingManager {
if let Ok(mut vad) = vad_clone.lock() {
// println!("VAD lock acquired");
match vad.compute(&chunk) {
Ok(mut result) => {
Ok(result) => {
if result.prob > 0.15 {
let mut buffer =
buffer_clone.lock().unwrap();

View file

@ -1,7 +1,6 @@
use super::audio::AudioRecordingManager;
use super::transcription::TranscriptionManager;
use rdev::{EventType, Key};
use rig::providers::anthropic;
use std::collections::HashSet;
use std::sync::{Arc, Mutex};

View file

@ -5,6 +5,7 @@ import {
checkAccessibilityPermissions,
requestAccessibilityPermissions,
} from "tauri-plugin-macos-permissions-api";
import { register } from "@tauri-apps/plugin-global-shortcut";
function App() {
const [hasAccessibility, setHasAccessibility] = useState(false);