Skip to content

feat: System tray mode with background health monitoring#268

Merged
laurentiu021 merged 1 commit into
mainfrom
feat/system-tray
May 12, 2026
Merged

feat: System tray mode with background health monitoring#268
laurentiu021 merged 1 commit into
mainfrom
feat/system-tray

Conversation

@laurentiu021

@laurentiu021 laurentiu021 commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary

Adds system tray integration: the app minimizes to tray on close and monitors system health in the background with Windows toast notifications.

Features

  • Minimize-to-tray — closing the window hides it to tray instead of exiting
  • Tray icon — uses the app icon, left-click restores the window
  • Context menu — Show SysManager / Exit (real exit)
  • Tooltip — live CPU load, RAM usage, uptime (updated every 60s)
  • Notifications (with 4h cooldown per type):
    • RAM > 90%: suggests closing unused apps
    • Uptime > 14 days: recommends restart
    • Disk health degraded: suggests backup

Technical

  • Uses \H.NotifyIcon.Wpf 2.2.1\ (modern .NET 8 compatible fork)
  • \ShutdownMode.OnExplicitShutdown\ — app stays alive when window is hidden
  • \TrayIconService\ initialized in \OnSourceInitialized\ (after HWND exists)
  • \DispatcherTimer\ for 60s polling (UI thread safe)
  • Notification cooldown prevents spam (4h between same-type notifications)

Files added

  • \Services/TrayIconService.cs\ — tray icon + monitoring + notifications

Files modified

  • \App.xaml.cs\ — explicit shutdown mode + tray service lifecycle
  • \MainWindow.xaml.cs\ — OnClosing minimize-to-tray + tray init
  • \SysManager.csproj\ — H.NotifyIcon.Wpf package reference

Tests (10 new)

  • \TrayIconServiceTests.cs\ — defaults, dispose safety, notification logic

Docs

  • README.md, ARCHITECTURE.md, CHANGELOG.md updated

Closes #262

Summary by CodeRabbit

Release Notes

  • New Features

    • System Tray mode: minimize to tray on window close instead of exiting
    • Background health monitoring every 60 seconds with CPU/RAM/uptime tooltip
    • Windows notifications for high RAM usage (>90%), extended uptime (>14 days), and disk degradation
    • Right-click context menu with Show/Exit options
  • Tests

    • Added comprehensive test coverage for system tray functionality
  • Documentation

    • Updated documentation to reflect new system tray features

Review Change Stack

- TrayIconService: manages NotifyIcon lifecycle, 60s background polling,
  tooltip with CPU/RAM/uptime, Windows toast notifications
- Minimize-to-tray on window close (ShutdownMode.OnExplicitShutdown)
- Context menu: Show SysManager / Exit
- Notifications with 4h cooldown: RAM > 90%, uptime > 14 days, disk
  health degraded
- App.xaml.cs: tray service init + explicit shutdown mode
- MainWindow.xaml.cs: OnClosing override for minimize-to-tray,
  tray icon init in OnSourceInitialized
- H.NotifyIcon.Wpf 2.2.1 NuGet package added
- 10 new unit tests for service defaults and notification logic
- README, ARCHITECTURE, CHANGELOG updated

Closes #262
@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR implements a complete system tray feature for background health monitoring. The application now minimizes to a tray icon, periodically polls CPU/RAM/uptime, displays the status in a tooltip, triggers Windows notifications when thresholds are exceeded, and provides a context menu for visibility control—all wired into the application and window lifecycle without blocking window close.

Changes

System Tray Feature Implementation

Layer / File(s) Summary
TrayIconService Core Implementation
SysManager/SysManager/Services/TrayIconService.cs
TrayIconService creates a system tray icon with a 60-second polling timer, updates tooltip with CPU/RAM/uptime, evaluates notification triggers (high RAM >90%, uptime >14 days, disk health), tracks per-condition cooldowns, displays Windows notifications, and provides window visibility helpers with exception handling and safe disposal.
Application Startup and Lifecycle Wiring
SysManager/SysManager/App.xaml.cs, SysManager/SysManager/SysManager.csproj
App creates a shared TrayIconService during OnStartup with SystemInfoService, sets ShutdownMode to OnExplicitShutdown to prevent immediate exit on window close, disposes the service during OnExit, and exposes a public TrayService property. H.NotifyIcon.Wpf 2.2.1 is added as a NuGet dependency.
Window Minimize-to-Tray and Initialization
SysManager/SysManager/MainWindow.xaml.cs
MainWindow calls TrayService.Initialize during source initialization to wire up the tray icon, overrides OnClosing to cancel close, hide the window, and minimize to tray when MinimizeToTray is enabled, or fallback to base closing when disabled.
TrayIconService Test Suite
SysManager/SysManager.Tests/TrayIconServiceTests.cs
Tests verify constructor and property defaults (MinimizeToTray and NotificationsEnabled both true), property disabling, safe multi-call disposal, and CheckAndNotify behavior for low RAM, high RAM, high uptime, and unhealthy disk scenarios with a SystemSnapshot test helper.
Feature Documentation
ARCHITECTURE.md, CHANGELOG.md, README.md
ARCHITECTURE.md documents TrayIconService in the Services section. CHANGELOG.md adds System Tray mode details under Unreleased including minimize-to-tray, 60s polling, tooltip, notification conditions, context menu, and NuGet dependency. README.md extends System health section with new System Tray capability description.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰 A tray icon twinkles in the corner so neat,
Background heartbeats at sixty-second beat,
RAM warnings chirp, uptime bells ring loud,
While the window hides—no fuss, no crowd!
Minimize, monitor, notify with care—
The system breathes freely in tray's cool air! 🌙

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: System tray mode with background health monitoring' clearly and accurately summarizes the main change: adding system tray functionality with background health monitoring.
Linked Issues check ✅ Passed All coding requirements from issue #262 are met: minimize-to-tray behavior implemented, tooltip with RAM/CPU/uptime added, Windows notifications with cooldown policy for disk/battery/uptime conditions, and H.NotifyIcon.Wpf library integrated.
Out of Scope Changes check ✅ Passed All changes are directly related to system tray mode implementation and documentation. No unrelated modifications to other features or systems were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/system-tray

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

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 32.71028% with 72 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
SysManager/SysManager/Services/TrayIconService.cs 36.84% 58 Missing and 2 partials ⚠️
SysManager/SysManager/MainWindow.xaml.cs 0.00% 8 Missing ⚠️
SysManager/SysManager/App.xaml.cs 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment on lines +178 to +187
foreach (var disk in snapshot.Disks)
{
if (disk.HealthStatus != "Healthy" && now - _lastDiskNotification > NotificationCooldown)
{
_lastDiskNotification = now;
ShowNotification("Disk Health Warning",
$"{disk.FriendlyName} reports status: {disk.HealthStatus}. Consider backing up important data.");
break;
}
}
@laurentiu021
laurentiu021 merged commit 1c36e1c into main May 12, 2026
4 of 5 checks passed
@laurentiu021
laurentiu021 deleted the feat/system-tray branch May 12, 2026 11:56
laurentiu021 added a commit that referenced this pull request May 22, 2026
## What changed

Startup folder entries (shortcuts in the shell Startup folder) can now
be properly disabled/enabled.

## Root cause

Entries from the shell Startup folder were incorrectly tagged as
`StartupSource.RegistryCurrentUser`. When toggling, the disable blob was
written to `StartupApproved\Run` instead of
`StartupApproved\StartupFolder`, so Windows never saw the change.

## Fix

- Added `StartupFolder` to the `StartupSource` enum
- `ReadStartupFolder` now sets `Source = StartupSource.StartupFolder`
- `ApplyApprovedState` reads `StartupApproved\StartupFolder` for folder
entries
- `SetEnabled` writes to `StartupApproved\StartupFolder` for folder
entries

## Files changed

- `Models/StartupEntry.cs` — added `StartupFolder` enum value
- `Services/StartupService.cs` — corrected source assignment and
approved key routing

Closes #268

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
laurentiu021 added a commit that referenced this pull request May 22, 2026
Add CHANGELOG entries for the 4 bug-fix releases from today's session:

- **v0.21.3** — buttons grayed out on focus loss (#252, #251, #248,
#245)
- **v0.21.4** — tab name consistency + log hover (#267, #247)
- **v0.21.5** — startup manager disable (#268)
- **v0.21.6** — speed test panel states + auto-trace (#257, #239)

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
laurentiu021 added a commit that referenced this pull request May 22, 2026
- TrayIconService: manages NotifyIcon lifecycle, 60s background polling,
  tooltip with CPU/RAM/uptime, Windows toast notifications
- Minimize-to-tray on window close (ShutdownMode.OnExplicitShutdown)
- Context menu: Show SysManager / Exit
- Notifications with 4h cooldown: RAM > 90%, uptime > 14 days, disk
  health degraded
- App.xaml.cs: tray service init + explicit shutdown mode
- MainWindow.xaml.cs: OnClosing override for minimize-to-tray,
  tray icon init in OnSourceInitialized
- H.NotifyIcon.Wpf 2.2.1 NuGet package added
- 10 new unit tests for service defaults and notification logic
- README, ARCHITECTURE, CHANGELOG updated

Closes #262

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
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.

[Enhancement]: System tray mode with background health monitoring

3 participants