{"record":{"id":"96158de3eebfd2ee","repo":"tonhowtf/omniget","slug":"configure-e-inicie-uma-vez-pela-tela-antes-de-usar-o-atalho","errorCode":null,"errorMessage":"configure e inicie uma vez pela tela antes de usar o atalho","messagePattern":"configure e inicie uma vez pela tela antes de usar o atalho","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"src-tauri/omniget-core/src/core/tools/autoclick.rs","lineNumber":204,"sourceCode":"        .map_err(|e| {\n            RUNNING.store(false, Ordering::SeqCst);\n            anyhow!(\"thread: {}\", e)\n        })?;\n    Ok(())\n}\n\npub fn stop() {\n    RUNNING.store(false, Ordering::SeqCst);\n}\n\n/// Atalho global: para se estiver rodando, senão começa com as últimas opções.\npub fn toggle() -> anyhow::Result<bool> {\n    if RUNNING.load(Ordering::SeqCst) {\n        stop();\n        return Ok(false);\n    }\n    let opts = last_options()\n        .ok_or_else(|| anyhow!(\"configure e inicie uma vez pela tela antes de usar o atalho\"))?;\n    start(opts)?;\n    Ok(true)\n}\n\npub fn mouse_position() -> Option<(i32, i32)> {\n    let enigo = Enigo::new(&Settings::default()).ok()?;\n    enigo.location().ok()\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn precise_sleep() {\n        let t = Instant::now();\n        sleep_until(t + Duration::from_millis(5));\n        let e = t.elapsed();","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/autoclick.rs#L186-L222","documentation":"toggle() switches the autoclicker on/off using the last saved ClickOptions. If the autoclicker is not running and no options were ever configured via start() (LAST_OPTS is None), it cannot know what to start and returns this error, requiring the user to configure and start once through the UI first.","triggerScenarios":"Pressing the global hotkey (toggle()) before ever calling start() with a valid ClickOptions — last_options() returns None because LAST_OPTS was never populated.","commonSituations":"Fresh install: user immediately presses the hotkey without opening the autoclicker screen; settings lost after app restart if LAST_OPTS is not persisted; another process cleared state.","solutions":["Open the autoclicker screen, configure CPS/options, and click Start once before using the hotkey shortcut.","Persist last options to disk (settings file) so they survive restarts and survive hotkey use after relaunch.","Initialize LAST_OPTS with sensible defaults at startup so toggle() always has something to start.","Catch this error in the hotkey handler and surface a notification telling the user to configure first."],"exampleFix":"// before\nlet opts = last_options()\n    .ok_or_else(|| anyhow!(\"configure e inicie uma vez pela tela antes de usar o atalho\"))?;\n// after\nlet opts = last_options().unwrap_or_else(|| ClickOptions {\n    cps: 10.0,\n    /* defaults de fábrica */\n    ..Default::default()\n});\nstart(opts)?;","handlingStrategy":"validation","validationCode":"fn hotkey_ready() -> bool { autoclicker_running() || last_options().is_some() }","typeGuard":"fn has_saved_options(o: &Option<ClickOptions>) -> bool { o.is_some() }","tryCatchPattern":"match autoclick::toggle() {\n    Ok(started) => update_ui(started),\n    Err(e) if e.to_string().contains(\"configure e inicie\") =>\n        open_autoclicker_screen(), // orientar o usuário\n    Err(e) => show_error(e),\n}","preventionTips":["Initialize defaults for ClickOptions at app startup.","Persist last options to disk so restarts keep hotkey use working.","Show the hotkey hint only after options exist.","In the hotkey handler, catch this error and open the config screen instead of failing silently."],"tags":["rust","autoclicker","hotkey","missing-state"],"backgroundTag":"missing-configuration","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"}