Repository: moeru-ai/airi
File: apps/stage-tamagotchi/src-tauri/src/lib.rs (Rust)

Code before:
  let window = window;
  let state = window.state::<WindowClickThroughState>();
  let enabled = state.enabled.clone();
  let monitoring_enabled = state.monitoring_enabled.clone();

  // Already monitoring?
  if monitoring_enabled.load(Ordering::Relaxed) {
    return Ok(());
  }

  // Set to true
  state.monitoring_enabled.store(true, Ordering::Relaxed);

  // Then start interval timer for monitoring
  tauri::async_runtime::spawn(async move {
    loop {
      sleep(Duration::from_millis(32)).await; // ~30FPS check rate

      // If monitoring is already stopped, break the loop
      if !monitoring_enabled.load(Ordering::Relaxed) {
        break;
      }

      #[cfg(target_os = "macos")]
      {
        let _ = window.emit("tauri-app:window-click-through:mouse-location-and-window-frame", (get_mouse_location(), get_window_frame(&window)));
      }

      #[cfg(target_os = "windows")]
      {
        let _ = window.emit("tauri-app:window-click-through:mouse-location-and-window-frame", (get_mouse_location(), get_window_frame(&window)));
      }
    }
  });

  Ok(())
}

#[tauri::command]
async fn stop_monitor(window: tauri::Window) -> Result<(), String> {
  let window = window;
  let state = window.state::<WindowClickThroughState>();

  // Set to false
  // Termination will be triggered in the next interval check (tick)
  state.monitoring_enabled.store(false, Ordering::Relaxed);

  Ok(())
}

#[tauri::command]

Review comment (suggestion):
```suggestion
        let _ = window.emit("tauri-app:window-click-through:position-cursor-and-window-frame", (get_mouse_location(), get_window_frame(&window)));
```

Code after:
  let window = window;
  let state = window.state::<WindowClickThroughState>();
  let monitoring_enabled = state.monitoring_enabled.clone();

  // Already monitoring?
  if monitoring_enabled.load(Ordering::Relaxed) {
    return Ok(());
  }

  // Set to true
  state.monitoring_enabled.store(true, Ordering::Relaxed);

  // Then start interval timer for monitoring
  tauri::async_runtime::spawn(async move {
    loop {
      sleep(Duration::from_millis(32)).await; // ~30FPS check rate

      // If monitoring is already stopped, break the loop
      if !monitoring_enabled.load(Ordering::Relaxed) {
        break;
      }

      #[cfg(target_os = "macos")]
      {
        let _ = window.emit("tauri-app:window-click-through:position-cursor-and-window-frame", (get_mouse_location(), get_window_frame(&window)));
      }

      #[cfg(target_os = "windows")]
      {
        let _ = window.emit("tauri-app:window-click-through:position-cursor-and-window-frame", (get_mouse_location(), get_window_frame(&window)));
      }
    }
  });

  Ok(())
}

#[tauri::command]
async fn stop_monitor(window: tauri::Window) -> Result<(), String> {
  let window = window;
  let state = window.state::<WindowClickThroughState>();

  // Set to false
  // Termination will be triggered in the next interval check (tick)
  state.monitoring_enabled.store(false, Ordering::Relaxed);

  Ok(())
}

#[tauri::command]
async fn start_click_through(window: tauri::Window) -> Result<(), String> {