Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1787,20 +1787,22 @@ extension Ghostty {

// Note the callback may be executed on a background thread as documented
// so we need @MainActor since we're reading/writing view state.
Task { @MainActor in
// We use [weak self] here because we don't want to extend the surface's
// lifetime when a notification is triggered right before the surface closes.
Task { @MainActor [weak self] in
do {
try await UNUserNotificationCenter.current().add(request)

// We need to keep track of this notification so we can remove it
// under certain circumstances
notificationIdentifiers.insert(uuid)
self?.notificationIdentifiers.insert(uuid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe guard let self ... here to simplify the rest of this block's calling patterns? Everything afterward is dependent on self being available.

@bo2themax bo2themax Aug 13, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We still need to remove the notification using uuid 3s later. I would imagine at least copy the check twice🙈

@jparise jparise Aug 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If that's the case, then isn't the if self?.focused == true condition going to fail and prevent the UUID-based removal from running anyway?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh yeah, you are right


// If we're focused then we schedule to remove the notification
// after a few seconds. If we gain focus we automatically remove it
// in focusDidChange.
if self.focused {
if self?.focused == true {
try await Task.sleep(for: .seconds(3))
notificationIdentifiers.remove(uuid)
self?.notificationIdentifiers.remove(uuid)
UNUserNotificationCenter.current()
.removeDeliveredNotifications(withIdentifiers: [uuid])
}
Expand Down
Loading