Skip to content

fix: restore MainActor context for notification observation task#86

Merged
sozercan merged 1 commit intomainfrom
fix-notifs
Jan 26, 2026
Merged

fix: restore MainActor context for notification observation task#86
sozercan merged 1 commit intomainfrom
fix-notifs

Conversation

@sozercan
Copy link
Owner

Summary

  • Adds @MainActor annotation to the Task closure in NotificationService.startObserving()
  • Fixes notification observation that broke when nonisolated(unsafe) was added in commit 6f0602d

Root Cause

When nonisolated(unsafe) was added to observationTask to fix Swift 6 deinit warnings, the Task lost its implicit @MainActor context inheritance. This caused the polling loop to not properly observe changes to the @MainActor-isolated playerService.currentTrack property.

Fix

Adding @MainActor to the Task closure ensures proper actor isolation, matching the pattern already used in NetworkMonitor.

// Before (broken):
self.observationTask = Task { [weak self] in

// After (fixed):
self.observationTask = Task { @MainActor [weak self] in

Test plan

  • Play a track and verify notification appears
  • Skip to next track and verify new notification appears
  • Toggle "Show Now Playing Notifications" setting and verify it's respected

🤖 Generated with Claude Code

The Task in startObserving() lost its @mainactor context when
nonisolated(unsafe) was added to observationTask in 6f0602d.
This caused the polling loop to not properly observe changes to
the @MainActor-isolated playerService.currentTrack property.

Adding @mainactor to the Task closure ensures proper actor
isolation, matching the pattern already used in NetworkMonitor.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 26, 2026 07:16
@sozercan sozercan linked an issue Jan 26, 2026 that may be closed by this pull request
1 task
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in notification observation that was inadvertently broken when nonisolated(unsafe) was added to observationTask to resolve Swift 6 deinit warnings. The fix restores proper actor isolation by adding @MainActor to the Task closure, ensuring the polling loop can correctly observe changes to @MainActor-isolated properties.

Changes:

  • Added @MainActor annotation to the Task closure in NotificationService.startObserving()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sozercan sozercan merged commit 0d94049 into main Jan 26, 2026
12 checks passed
@sozercan sozercan deleted the fix-notifs branch February 25, 2026 07:31
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.

[Bug]: Native macOS notifications on track change

2 participants