Skip to content

Reduce tray idle memory by unloading the main WebView#686

Open
F0RLE wants to merge 1 commit into
jlcodes99:mainfrom
F0RLE:codex/destroy-main-webview-in-tray
Open

Reduce tray idle memory by unloading the main WebView#686
F0RLE wants to merge 1 commit into
jlcodes99:mainfrom
F0RLE:codex/destroy-main-webview-in-tray

Conversation

@F0RLE
Copy link
Copy Markdown

@F0RLE F0RLE commented May 5, 2026

Summary

This PR reduces idle memory usage when the main window is closed to the tray.

Instead of hiding the main Tauri window, the app now destroys the main WebView when the close behavior is set to minimize to tray. The Rust backend, tray icon, and background services remain alive, and the main window/WebView is recreated on demand when the user opens the app from the tray or navigates from tray menu actions.

Why

Previously, closing the window to the tray only called hide(), so the React frontend and WebView stayed loaded in memory even while the app appeared closed. This made the tray-only idle state much heavier than necessary.

Changes

  • Destroy the main WebView when closing to tray instead of only hiding it.
  • Keep the Tauri event loop alive after the main window is destroyed, while still allowing explicit Quit actions to exit normally.
  • Recreate the main window from Tauri config when it is shown again.
  • Preserve tray navigation targets across WebView recreation so tray menu actions still land on the requested page.
  • Request platform-specific idle memory trimming after the WebView is destroyed:
    • Windows: EmptyWorkingSet and SetProcessWorkingSetSize
    • Linux/glibc: malloc_trim(0)
    • macOS: malloc_zone_pressure_relief
  • Move macOS-only build/runtime dependencies behind macOS target cfg so Windows builds do not pull Apple-only crates.

Validation

  • npm run typecheck
  • cargo check -p cockpit-tools
  • Manual Windows dev test: closing to tray unloads the frontend/WebView while the backend and tray remain running; opening from tray recreates the frontend window.

Notes

The memory trimming APIs are best-effort requests to the OS/runtime allocator. They reduce the resident working set where possible, but exact idle memory values are still controlled by the operating system.

@F0RLE F0RLE marked this pull request as ready for review May 5, 2026 20:14
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