tonhowtf/omniget · warning · anyhow::Error

ja esta rodando

Error message

ja esta rodando

What it means

start() refuses to run the autoclicker when it is already active. It atomically swaps the RUNNING flag to true first; if the previous value was already true, another instance is running, so it returns this error instead of spawning a second clicking thread.

Solutions

  1. Call stop() (or check RUNNING) before starting again, or use toggle() which handles the running case.
  2. Catch this error in the UI and treat it as a no-op/status refresh rather than a failure.
  3. Fix any code path that calls start() while holding a stale RUNNING=true (e.g. after a thread panicked without resetting the flag).
  4. Expose RUNNING state to the UI so the Start control is disabled while active.

Example fix

// before
if RUNNING.load(Ordering::SeqCst) { stop(); }
start(opts)?;
// after
if RUNNING.load(Ordering::SeqCst) {
    stop(); // já está rodando: apenas interrompe
} else {
    start(opts)?;
}
Defensive patterns

Strategy: type-guard

Validate before calling

fn can_start() -> bool { !RUNNING.load(Ordering::SeqCst) }

Type guard

fn autoclicker_idle() -> bool { !RUNNING.load(Ordering::SeqCst) }

Try / catch

match autoclick::start(opts) {
    Ok(()) => set_ui_running(true),
    Err(e) if e.to_string() == "ja esta rodando" => { /* já ativo: apenas sincronizar UI */ }
    Err(e) => show_error(e),
}

Prevention

When it happens

Trigger: Calling start() (directly or via toggle()) while RUNNING is true — i.e. the autoclicker thread from a previous start() is still alive and hasn't finished/stopped.

Common situations: User clicks Start twice; a global hotkey toggle races with the UI Start button; a previous run's thread is still winding down (e.g. sleeping between clicks) when start() is called again.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/6212a78f8b0b6cc9. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/autoclick.rs:103

        if left > Duration::from_micros(1500) {
            std::thread::sleep(left - Duration::from_micros(1200));
        } else {
            std::hint::spin_loop();
        }
    }
}

fn button_of(name: &str) -> Button {
    match name {
        "right" => Button::Right,
        "middle" => Button::Middle,
        _ => Button::Left,
    }
}

pub fn start(opts: ClickOptions) -> anyhow::Result<()> {
    if RUNNING.swap(true, Ordering::SeqCst) {
        return Err(anyhow!("ja esta rodando"));
    }
    if !(0.1..=1000.0).contains(&opts.cps) {
        RUNNING.store(false, Ordering::SeqCst);
        return Err(anyhow!("CPS fora de 0,1 a 1000"));
    }
    *LAST_OPTS.lock().unwrap_or_else(|e| e.into_inner()) = Some(opts.clone());
    *ERROR.lock().unwrap_or_else(|e| e.into_inner()) = None;
    CLICKS.store(0, Ordering::SeqCst);
    *STARTED.lock().unwrap_or_else(|e| e.into_inner()) = Some(Instant::now());

    std::thread::Builder::new()
        .name("omniget-autoclick".into())
        .spawn(move || {
            let mut enigo = match Enigo::new(&Settings::default()) {
                Ok(e) => e,
                Err(e) => {
                    *ERROR.lock().unwrap_or_else(|e| e.into_inner()) = Some(format!("nao consegui controlar o mouse: {} (macOS: Ajustes → Privacidade → Acessibilidade)", e));
                    RUNNING.store(false, Ordering::SeqCst);

View on GitHub (pinned to 8600b91f42)