Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions desktop/src-tauri/src/prevent_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tauri::{AppHandle, Emitter};
#[derive(Default)]
pub struct PreventSleepState {
assertion_id: Option<u32>,
timer_abort: Option<tokio::task::AbortHandle>,
timer_handle: Option<tauri::async_runtime::JoinHandle<()>>,
}

// ── macOS implementation ────────────────────────────────────────────────────
Expand Down Expand Up @@ -111,12 +111,12 @@ pub fn acquire(
if guard.assertion_id.is_some() {
let handle = app_handle.clone();
let timer_state = Arc::clone(state);
let timer_task = tokio::spawn(async move {
let timer_task = tauri::async_runtime::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(CAP_SECONDS)).await;
release(&timer_state);
let _ = handle.emit("prevent-sleep-expired", ());
});
guard.timer_abort = Some(timer_task.abort_handle());
guard.timer_handle = Some(timer_task);
}

Ok(())
Expand All @@ -129,8 +129,8 @@ pub fn release(state: &Arc<Mutex<PreventSleepState>>) {
Err(_) => return,
};

if let Some(abort) = guard.timer_abort.take() {
abort.abort();
if let Some(handle) = guard.timer_handle.take() {
handle.abort();
}

#[cfg(target_os = "macos")]
Expand Down
8 changes: 4 additions & 4 deletions desktop/src/features/agents/usePreventSleep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ function usePreventSleepInternal() {
[agents],
);

const active = enabled && hasRunningAgents;
// Listen for 4-hour expiry
const [expired, setExpired] = React.useState(false);

const active = enabled && hasRunningAgents && !expired;

const setEnabled = React.useCallback((value: boolean) => {
writePreference(value);
Expand All @@ -67,9 +70,6 @@ function usePreventSleepInternal() {
React.useEffect(() => {
void setPreventSleepActive(active);
}, [active]);

// Listen for 4-hour expiry
const [expired, setExpired] = React.useState(false);
React.useEffect(() => {
const unlisten = listen("prevent-sleep-expired", () => {
setExpired(true);
Expand Down