Skip to content

feat(macos): handle system sleep/wake and screen sleep/wake lifecycle events #1357

@jsmestad

Description

@jsmestad

Summary

The macOS frontend does not respond to system sleep/wake or screen sleep/wake events. This can cause stale state after wake (files changed on disk, LSP connections dropped, git status outdated) and wasted GPU rendering while screens are asleep.

Motivation

  • After waking from sleep, open files may have been modified externally — the editor should detect and handle this
  • LSP connections may have timed out during sleep and need reconnection
  • Git status is likely stale after wake
  • Metal rendering should pause when screens sleep to avoid unnecessary GPU work
  • BEAM heartbeat/timers should be paused during sleep to prevent false timeout detection

Notifications to Handle

Notification Action
NSWorkspace.willSleepNotification Flush unsaved state, pause BEAM heartbeat/timers, notify BEAM of impending sleep
NSWorkspace.didWakeNotification Trigger file staleness checks, reconnect LSP, refresh git status, resume timers
NSWorkspace.screensDidSleepNotification Pause Metal rendering loop (stop setNeedsDisplay / display link)
NSWorkspace.screensDidWakeNotification Resume Metal rendering, force a full re-render

Implementation Notes

  • Register observers on NSWorkspace.shared.notificationCenter (not the default center)
  • willSleep fires before the system actually sleeps — use this window to flush
  • didWake may fire before network is fully available — LSP reconnection should retry with backoff
  • Screen sleep/wake is independent of system sleep — screens can sleep on idle timeout while the system stays awake
  • Consider sending a protocol message to BEAM on sleep/wake so it can pause/resume its own background work

Acceptance Criteria

  • Metal rendering pauses when screens sleep and resumes on wake
  • BEAM is notified of sleep/wake transitions
  • No rendering artifacts or stale frames after wake
  • File modification detection runs after system wake

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: macos-guimacOS native GUI frontend (Swift/Metal)enhancementNew feature or requestepic: macos-guimacOS GUI reaches native app paritypriority: highImportant for usability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions