Skip to content

fix: improve app activation and fix icon attachment#4

Merged
send merged 5 commits intomainfrom
fix/activate-and-icon-attachment
Mar 1, 2026
Merged

fix: improve app activation and fix icon attachment#4
send merged 5 commits intomainfrom
fix/activate-and-icon-attachment

Conversation

@send
Copy link
Copy Markdown
Owner

@send send commented Mar 1, 2026

Summary

  • activate: Use NSRunningApplication.activate() for already-running apps instead of NSWorkspace.open(url), which is unreliable for bringing apps to the foreground
  • icon: Copy icon file to a temporary directory before creating UNNotificationAttachment, 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.wezterm activates WezTerm reliably
  • macnotifier -m "test" --icon path/to/icon.png shows icon
  • Repeated notifications with --icon all display the icon (original file is preserved)
  • ./scripts/test.sh passes (15/15)

🤖 Generated with Claude Code

…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>
Copy link
Copy Markdown

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 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 NSRunningApplication instead of re-opening via NSWorkspace.open.
  • Copy the icon file to a per-notification temporary location before creating a UNNotificationAttachment to 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 defer after the attachment is created, or after center.add completes).
            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>
Copy link
Copy Markdown

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

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.

Copy link
Copy Markdown

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

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>
Copy link
Copy Markdown

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

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.

@send send merged commit 443ee34 into main Mar 1, 2026
7 checks passed
@send send deleted the fix/activate-and-icon-attachment branch March 1, 2026 09:46
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.

2 participants