fix: improve app activation and fix icon attachment#4
Conversation
…tachment - Use NSRunningApplication.activate() for already-running apps instead of NSWorkspace.open(url), which is unreliable for bringing apps to foreground - Copy icon file to a temporary directory before creating UNNotificationAttachment, since the system moves (consumes) the file into its data store, deleting the original Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR improves macnotifier’s click behavior and notification icon handling on macOS by making app activation more reliable for already-running apps and preventing icon attachments from consuming the original file.
Changes:
- Activate already-running apps via
NSRunningApplicationinstead of re-opening viaNSWorkspace.open. - Copy the icon file to a per-notification temporary location before creating a
UNNotificationAttachmentto avoid the original being moved/consumed.
Comments suppressed due to low confidence (1)
Sources/main.swift:98
- This creates a unique temp directory for each notification icon but never removes it. Even if the system moves the attachment file away, the empty UUID directory will accumulate under the temp folder over repeated runs. Consider cleaning up the temporary directory (e.g., with
deferafter the attachment is created, or aftercenter.addcompletes).
return
}
let content = UNMutableNotificationContent()
content.title = params.title
content.body = params.message
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
UNUserNotificationCenterDelegate callbacks are not guaranteed to run on the main thread, but NSRunningApplication/AppKit APIs require it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
NSRunningApplication.activate()for already-running apps instead ofNSWorkspace.open(url), which is unreliable for bringing apps to the foregroundUNNotificationAttachment, since the system moves (consumes) the original file into its data store, causing subsequent notifications to fail with "Failed to move attachment file into data store"Test plan
macnotifier -m "test" -a com.github.wez.weztermactivates WezTerm reliablymacnotifier -m "test" --icon path/to/icon.pngshows icon--iconall display the icon (original file is preserved)./scripts/test.shpasses (15/15)🤖 Generated with Claude Code