{"record":{"id":"67349ac347753205","repo":"tonhowtf/omniget","slug":"dictation","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/dictation.rs","lineNumber":383,"sourceCode":"    // Um instante para o usuário soltar o atalho antes de digitar.\n    std::thread::sleep(std::time::Duration::from_millis(150));\n    enigo.text(text).map_err(|e| anyhow!(\"digitar: {}\", e))?;\n    Ok(())\n}\n\n/// Cmd+V / Ctrl+V (o app coloca o texto na área de transferência antes).\npub fn press_paste() -> anyhow::Result<()> {\n    use enigo::{Direction, Enigo, Key, Keyboard, Settings};\n    let mut enigo = Enigo::new(&Settings::default()).map_err(|e| anyhow!(\"teclado: {}\", e))?;\n    std::thread::sleep(std::time::Duration::from_millis(150));\n    let modifier = if cfg!(target_os = \"macos\") {\n        Key::Meta\n    } else {\n        Key::Control\n    };\n    enigo\n        .key(modifier, Direction::Press)\n        .map_err(|e| anyhow!(\"{}\", e))?;\n    enigo\n        .key(Key::Unicode('v'), Direction::Click)\n        .map_err(|e| anyhow!(\"{}\", e))?;\n    enigo\n        .key(modifier, Direction::Release)\n        .map_err(|e| anyhow!(\"{}\", e))?;\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn defaults() {\n        let o = options();\n        assert_eq!(o.model, \"base\");\n        assert_eq!(o.output, \"type\");","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/dictation.rs#L365-L401","documentation":"press_paste() wraps the enigo.key(modifier, Direction::Press) failure with the raw error via anyhow!(\"{}\", e). The Enigo backend failed to press the modifier key (Cmd on macOS, Ctrl elsewhere) needed for the paste shortcut.","triggerScenarios":"enigo.key(Key::Meta or Key::Control, Direction::Press) returns Err after Enigo was constructed successfully.","commonSituations":"Platform backend loses access to the input device mid-session (display sleep, session switch); Wayland rejects synthetic input; intermittent enigo driver failure.","solutions":["Retry press_paste() once — the failure is often transient.","Verify keyboard permissions are still granted (macOS Accessibility).","Ensure the app runs in an active graphical session (not locked/backgrounded).","If persistent on Linux/Wayland, switch to X11 or a different input backend."],"exampleFix":"null","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// retry the whole paste sequence once on failure\nif dictation::press_paste().is_err() {\n    std::thread::sleep(std::time::Duration::from_millis(200));\n    dictation::press_paste()?;\n}","preventionTips":["Retry transient injection failures with a small backoff.","Avoid calling paste while the target window is locked or secure-input is active.","Detect and recover from stuck modifier keys by sending a Release before retrying."],"tags":["keyboard","enigo","paste","input-injection"],"backgroundTag":"invalid-state-transition","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}