Skip to content

feat(wework): prevent sleep while tasks run - #2122

Merged
qdaxb merged 2 commits into
mainfrom
feature/prevent-sleep-running-tasks
Jul 22, 2026
Merged

qdaxb merged 2 commits into
mainfrom
feature/prevent-sleep-running-tasks

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • add a local, default-on Prevent sleep while tasks are running preference in Wework General settings
  • keep a native sleep inhibitor active while one or more tasks are running and release it after the final task settles
  • preserve inhibition after the main WebView is destroyed for tray background execution
  • support macOS (caffeinate), Windows (SetThreadExecutionState), and Linux (systemd-inhibit)
  • document the behavior in Chinese and English
  • extend the real desktop lifecycle E2E to assert the inhibitor is active while running/backgrounded and absent after completion

Why

Long-running local tasks can be interrupted when the computer enters idle sleep. Wework should keep the system awake only for the duration of active work, without changing the user's configured sleep policy or forcing the computer to sleep afterward.

User impact

The new setting is enabled by default. Users can disable it at any time; doing so immediately releases the inhibitor. When all tasks finish, fail, or are interrupted, Wework restores normal system sleep behavior.

Validation

  • pnpm --filter wework test — 194 files, 1933 tests passed
  • pnpm --filter wework exec tsc --noEmit
  • cargo test --manifest-path wework/src-tauri/Cargo.toml --lib — 84 tests passed on latest origin/main
  • pnpm --filter wework e2e:desktop:lifecycle — passed in an isolated real Tauri app
  • pre-push ESLint, TypeScript, and unit-test gates passed
  • reviewed the generated settings and four-step task lifecycle screenshot chain
  • native lifecycle evidence confirmed one inhibitor PID while running and backgrounded, then zero after completion

Summary by CodeRabbit

  • New Features

    • Added a setting to prevent the computer from sleeping while tasks are running.
    • Enabled the option by default, including when the app is minimized to the system tray.
    • Sleep prevention automatically ends when tasks finish, fail, or are interrupted.
    • Added English and Chinese labels, descriptions, and user-guide documentation.
  • Bug Fixes

    • Disabling the option immediately restores the system’s normal sleep behavior.
  • Tests

    • Added coverage for the setting, task lifecycle, and sleep-prevention behavior across supported platforms.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c648664-ef92-48b3-b047-d390be3872d5

📥 Commits

Reviewing files that changed from the base of the PR and between 61e9ae0 and 8018c13.

📒 Files selected for processing (18)
  • docs/en/wegent/user-guide/settings/desktop-app-preferences.md
  • docs/zh/wegent/user-guide/settings/desktop-app-preferences.md
  • wework/e2e/desktop/task-flow.e2e.mjs
  • wework/src-tauri/src/lib.rs
  • wework/src-tauri/src/local_executor.rs
  • wework/src-tauri/src/system_sleep.rs
  • wework/src/components/settings/AppshotsSettingsPage.test.tsx
  • wework/src/components/settings/BrowserSettingsPage.test.tsx
  • wework/src/components/settings/ContextSettingsPage.test.tsx
  • wework/src/components/settings/GeneralSettingsPage.test.tsx
  • wework/src/components/settings/GeneralSettingsPage.tsx
  • wework/src/i18n/locales/en/common.json
  • wework/src/i18n/locales/zh-CN/common.json
  • wework/src/tauri/appPreferences.test.ts
  • wework/src/tauri/appPreferences.ts
  • wework/src/tauri/trayMenuState.test.ts
  • wework/src/tauri/trayMenuState.ts
  • wework/src/tauri/trayNavigation.test.ts

📝 Walkthrough

Walkthrough

Adds a default-enabled “prevent sleep while tasks are running” preference, platform-specific sleep inhibition, active-task tray propagation, executor cleanup, UI controls, tests, macOS E2E verification, and English/Chinese documentation.

Changes

Sleep inhibition during running tasks

Layer / File(s) Summary
Preference contract and settings control
wework/src/tauri/appPreferences.ts, wework/src/components/settings/GeneralSettingsPage.tsx, wework/src/i18n/locales/*, wework/src-tauri/src/lib.rs
Adds the preventSleepWhileTasksRunning preference with a default of true, connects it to desktop startup and updates, and exposes a localized General settings toggle with updated fixtures and assertions.
Tray active-task propagation
wework/src/tauri/trayMenuState.ts, wework/src/tauri/trayNavigation.test.ts, wework/src-tauri/src/lib.rs
Counts running tasks in tray groups, includes activeTaskCount in tray state, and forwards the count to SystemSleepState.
Platform sleep inhibitor state
wework/src-tauri/src/system_sleep.rs, wework/src-tauri/src/lib.rs
Tracks concurrent tasks, filters terminal events, acquires and releases platform-specific inhibitors, and tests settling and default state behavior.
Executor cleanup and lifecycle verification
wework/src-tauri/src/local_executor.rs, wework/e2e/desktop/task-flow.e2e.mjs, docs/*/wegent/user-guide/settings/desktop-app-preferences.md
Handles terminal and stdio shutdown cleanup, verifies macOS inhibitor states through the task/window lifecycle, and documents the preference behavior in English and Chinese.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GeneralSettingsPage
  participant update_app_preferences
  participant SystemSleepState
  participant SleepInhibitor
  GeneralSettingsPage->>update_app_preferences: update preventSleepWhileTasksRunning
  update_app_preferences->>SystemSleepState: set_enabled preference
  SystemSleepState->>SleepInhibitor: acquire while active tasks exist
  SystemSleepState->>SleepInhibitor: release after tasks settle
Loading

Possibly related PRs

Suggested reviewers: micro66, icycrystal4

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/prevent-sleep-running-tasks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qdaxb
qdaxb marked this pull request as ready for review July 22, 2026 09:28
@qdaxb
qdaxb merged commit d673f03 into main Jul 22, 2026
31 checks passed
@qdaxb
qdaxb deleted the feature/prevent-sleep-running-tasks branch July 22, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant