-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[client] Keep the UI running when the notification service fails to start #6959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lixmal
wants to merge
2
commits into
main
Choose a base branch
from
ui-notifications-nonfatal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−8
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| //go:build !android && !ios && !freebsd && !js | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "sync/atomic" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
| "github.com/wailsapp/wails/v3/pkg/application" | ||
| "github.com/wailsapp/wails/v3/pkg/services/notifications" | ||
| ) | ||
|
|
||
| var errNotificationsUnavailable = errors.New("notifications unavailable") | ||
|
|
||
| // Notifier wraps the Wails notification service so an unavailable backend | ||
| // disables notifications instead of aborting the app. Startup fails for | ||
| // environment reasons (a bare unbundled binary on macOS has no bundle | ||
| // identifier, a headless Linux session has no D-Bus session bus), and Wails | ||
| // treats a service startup error as fatal. After a failed startup every call | ||
| // is a no-op: on macOS, touching UNUserNotificationCenter without a bundle | ||
| // identifier raises an Objective-C exception that recover() cannot catch. | ||
| type Notifier struct { | ||
| inner *notifications.NotificationService | ||
| available atomic.Bool | ||
| } | ||
|
|
||
| func newNotifier() *Notifier { | ||
| return &Notifier{inner: notifications.New()} | ||
| } | ||
|
|
||
| // ServiceName implements the Wails service-name hook for startup logs. | ||
| func (n *Notifier) ServiceName() string { | ||
| return n.inner.ServiceName() | ||
| } | ||
|
|
||
| // ServiceStartup starts the platform notifier, downgrading failure to a | ||
| // warning so the app keeps running without notifications. | ||
| func (n *Notifier) ServiceStartup(ctx context.Context, options application.ServiceOptions) error { | ||
| if err := n.inner.ServiceStartup(ctx, options); err != nil { | ||
| log.Warnf("notifications disabled: %v", err) | ||
| return nil | ||
| } | ||
| n.available.Store(true) | ||
| return nil | ||
| } | ||
|
|
||
| func (n *Notifier) ServiceShutdown() error { | ||
| if !n.available.Load() { | ||
| return nil | ||
| } | ||
| return n.inner.ServiceShutdown() | ||
| } | ||
|
|
||
| func (n *Notifier) CheckNotificationAuthorization() (bool, error) { | ||
| if !n.available.Load() { | ||
| return false, errNotificationsUnavailable | ||
| } | ||
| return n.inner.CheckNotificationAuthorization() | ||
| } | ||
|
|
||
| func (n *Notifier) RequestNotificationAuthorization() (bool, error) { | ||
| if !n.available.Load() { | ||
| return false, errNotificationsUnavailable | ||
| } | ||
| return n.inner.RequestNotificationAuthorization() | ||
| } | ||
|
|
||
| // SendNotification delivers a notification, silently dropping it when the | ||
| // backend never started (notifications are best-effort everywhere). | ||
| func (n *Notifier) SendNotification(options notifications.NotificationOptions) error { | ||
| if !n.available.Load() { | ||
| log.Debugf("notifications disabled, dropping %q", options.ID) | ||
| return nil | ||
| } | ||
| return n.inner.SendNotification(options) | ||
| } | ||
|
|
||
| func (n *Notifier) SendNotificationWithActions(options notifications.NotificationOptions) error { | ||
| if !n.available.Load() { | ||
| log.Debugf("notifications disabled, dropping %q", options.ID) | ||
| return nil | ||
| } | ||
| return n.inner.SendNotificationWithActions(options) | ||
| } | ||
|
|
||
| func (n *Notifier) RegisterNotificationCategory(category notifications.NotificationCategory) error { | ||
| if !n.available.Load() { | ||
| return nil | ||
| } | ||
| return n.inner.RegisterNotificationCategory(category) | ||
| } | ||
|
|
||
| // OnNotificationResponse registers the response callback. Pure Go state, so | ||
| // it is safe (and simply inert) when the backend never started. | ||
| // | ||
| //wails:ignore | ||
| func (n *Notifier) OnNotificationResponse(callback func(result notifications.NotificationResult)) { | ||
| n.inner.OnNotificationResponse(callback) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 965
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 39965
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 5010
🌐 Web query:
github.com wailsapp wails v3.0.0-alpha2.117 notifications Service NotificationService UpdateNotification RemoveNotification💡 Result:
In Wails v3 (including version v3.0.0-alpha2.117), the
NotificationServiceis part of thegithub.com/wailsapp/wails/v3/pkg/services/notificationspackage [1][2][3]. This service provides a cross-platform interface for managing system notifications [2]. The requested methods function as follows: - UpdateNotification: This method updates an existing, in-flight notification using its uniqueID[2][4]. When calling this method, you provideNotificationOptionscontaining the updated content [2]. On platforms like macOS and Linux, this typically replaces the notification in place, while on Windows, it may redeliver the notification [4]. - RemoveNotification: TheNotificationServicesupports removing notifications, generally identified by the uniqueIDprovided in the original notification options [2][5]. While specific API availability can vary by platform—for instance, macOS offers more granular control throughUNUserNotificationCentermethods likeRemoveDeliveredNotificationandRemovePendingNotification—theNotificationServiceabstraction is designed to handle notification lifecycle management [2][4][5]. To use the service, you initialize it vianotifications.New()and register it within your application'sServiceoptions [2][6]: import "github.com/wailsapp/wails/v3/pkg/application" import "github.com/wailsapp/wails/v3/pkg/services/notifications" // Create the service notifier:= notifications.New // Register the service with the application app:= application.New(application.Options{ Services: []application.Service{ application.NewService(notifier), }, }) For detailed implementation, refer to the official Wails v3 documentation [2][7] or the source code in thev3/pkg/services/notificationsdirectory [1][3].Citations:
🌐 Web query:
pkg.go.dev github.com/wailsapp/wails v3/pkg/services/notifications NotificationService💡 Result:
The NotificationService in the Wails v3 framework is a cross-platform service located in the github.com/wailsapp/wails/v3/pkg/services/notifications package [1][2]. It is designed to provide desktop applications with the ability to display native system notifications, including basic alerts, interactive notifications with actions, and categorized notification configurations [3][2]. Key aspects of the NotificationService include: Integration: To use the service, you typically create an instance using notifications.New and register it with your Wails application during initialization within the application.Options struct [3][4]. Functional Capabilities: The service supports methods such as SendNotification and SendNotificationWithActions, allowing developers to handle notifications consistently across macOS, Windows, and Linux [3][5][2]. Callback System: NotificationService provides an OnNotificationResponse method, which registers a callback function. This function is invoked when a user interacts with a notification (e.g., clicking a button or responding), allowing the application to process the resulting NotificationResult [1][4][5]. Internal Implementation: The service uses a platform-specific implementation (darwin, linux, or windows) under the hood [6][5]. These implementations manage the platform's native notification APIs and thread-safely bridge interaction events back to the main service, which then triggers the registered user callback [1][6][5]. For detailed usage, developers are encouraged to consult the official Wails v3 documentation [3] or the package documentation on pkg.go.dev [2].
Citations:
🌐 Web query:
github.com wailsapp wails v3.0.0-alpha2.117 notifications.go UpdateNotification RemoveNotification RemoveAllPendingNotifications RemoveAllDeliveredNotifications💡 Result:
In Wails v3.0.0-alpha2.117, the notification management methods you identified—UpdateNotification, RemoveNotification, RemoveAllPendingNotifications, and RemoveAllDeliveredNotifications—are part of the cross-platform notifications service defined in github.com/wailsapp/wails/v3/pkg/services/notifications [1][2]. Key details regarding these methods include: UpdateNotification: This method is used to update an existing "in-flight" notification by its ID [3]. RemoveNotification: In the macOS implementation (notifications_darwin.go), this method exists as a stub that returns nil [4]. The documentation explicitly advises against using it, directing developers to use more specific methods for pending or delivered notifications instead [4]. RemoveAllPendingNotifications and RemoveAllDeliveredNotifications: These are specific management methods for removing notifications from their respective states (pending or delivered) [4]. General Usage: These methods are part of the NotificationService struct [1][2]. Because Wails v3 supports different operating systems (macOS, Windows, and Linux), the underlying implementation handles platform-specific differences [1][2]. For instance, the macOS implementation provides concrete functions for removing notifications by state (pending or delivered) [4]. Note: Ensure you are referencing the v3-specific documentation at https://v3.wails.io/features/notifications/overview/ rather than the v2 runtime documentation, as the API structure differs between versions [5][3][6].
Citations:
🌐 Web query:
github.com wailsapp/wails/blob/3ec88c12/v3/pkg/services/notifications/notifications.go💡 Result:
The file located at v3/pkg/services/notifications/notifications.go is part of the Wails v3 framework, which provides a cross-platform service for displaying native system notifications [1][2][3]. Key characteristics and functionality of this package include: Cross-Platform Support: It supports macOS, Windows, and Linux by abstracting platform-specific differences while exposing a unified Go API [1][2]. Core Functionality: - Basic notifications: Supports titles, subtitles, and body text [1][4]. - Interactive notifications: Allows defining categories with actionable buttons [1][2]. - Callback System: Provides a unified response system via OnNotificationResponse to handle user interaction with notifications [2][5]. - Configuration: Uses a NotificationOptions struct for flexible configuration, including unique IDs, data payloads, and interruption levels [1][4]. Usage: To use the service, you must instantiate it (notifications.New) and register it with the Wails application during setup [4][5]. Note that for platform-specific features (such as on macOS), applications may need to be correctly packaged and signed to function as expected [6]. The package path has been standardized to github.com/wailsapp/wails/v3/pkg/services/notifications in recent versions to ensure correct compilation [7].
Citations:
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 44794
Preserve the full Wails notification service API on
Notifier.*Notifiernow replacesnotifications.NotificationServiceatclient/ui/main.go:330, but it only forwards a subset of methods. WailsNotificationServicealso exposesUpdateNotification,RemoveNotificationCategory,RemoveAllPendingNotifications,RemovePendingNotification,RemoveAllDeliveredNotifications,RemoveDeliveredNotification, andRemoveNotification; omitting these changes the generated frontend contract. Add availability-gated forwarding for the full surface, or treat this change as intentional and update callers/frontend-generated APIs accordingly.🤖 Prompt for AI Agents
Source: MCP tools