-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[v3] Notifications API #4098
Open
popaprozac
wants to merge
98
commits into
wailsapp:v3-alpha
Choose a base branch
from
popaprozac:notifications_darwin
base: v3-alpha
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.
Open
[v3] Notifications API #4098
Changes from 94 commits
Commits
Show all changes
98 commits
Select commit
Hold shift + click to select a range
32839bd
initial notification impl
popaprozac 274511c
update log message
popaprozac f694ad2
service and minor refactor
popaprozac cc524d7
update example
popaprozac 87f15ce
refactor
popaprozac 91f1704
cleanup
popaprozac 01fa307
windows impl
popaprozac c7d54e2
remove app event
popaprozac 7757eae
standalone example
popaprozac 9f39577
add comments
popaprozac 47a0977
add overwrite and remove notification category
popaprozac 6d44068
save notification categories to registry
popaprozac ab9c460
quick fixes
popaprozac 27e512d
add data option to basic notification
popaprozac f8647ff
update min macos version
popaprozac c1230d4
update win impl to match
popaprozac 9eab58f
update comments
popaprozac cc760a1
test data with toast
popaprozac 978a982
don't add title or body quite yet
popaprozac bf4222c
update example
popaprozac c904433
update example
popaprozac 983c25f
rw safety
popaprozac 1e3511c
fix deadlock
popaprozac 3dbf058
update comments
popaprozac be716fc
fix input id
popaprozac 8da9981
for review
popaprozac e8ad42a
switch to callback style
popaprozac 8bbe381
Merge branch 'v3-alpha' into notifications_darwin
popaprozac 67adc45
update example
popaprozac 253f672
init linux
popaprozac 135defc
init test linux
popaprozac 7bbc275
fix windows
popaprozac fa498f1
encode user data on windows
popaprozac 050e4ef
fix default complex action
popaprozac 60c1a86
update example
popaprozac 10ae1f6
export config from app
popaprozac a4c4ab6
add id to macOS payload
popaprozac acad85e
update example
popaprozac 60ae0c1
test linux userInfo
popaprozac 47e5b10
add debug
popaprozac 5ad3d73
wrangle variants
popaprozac e86cf68
linux?
popaprozac db2cab7
grab icon from app for notifications on windows
popaprozac e216b3e
set icon
popaprozac 207b162
Merge branch 'notifications_darwin' of github.com:popaprozac/wails in…
popaprozac 3bdb3dd
use app icon
popaprozac a807c26
better interop with obj-c
popaprozac ad74972
can you tell i'm not a go programmer?
popaprozac d9af6de
ignore bindings notification callback
popaprozac 833d8ec
refactor macos
popaprozac e4ec06a
update example
1e67e94
rename auth func
popaprozac 1fa6894
//
popaprozac e46abdc
update example
popaprozac 2cb0dac
set default action id on MATE
popaprozac 6d15f08
Merge branch 'v3-alpha' into notifications_darwin
popaprozac e810d6a
tidy
popaprozac e4e24a0
clean
popaprozac b60ef77
coderabbit impr
popaprozac ee885fe
fix mem crash
popaprozac 4af058b
more cleanup
popaprozac 58b5c10
Merge branch 'v3-alpha' into notifications_darwin
popaprozac 25256f7
allow only one notification service per app
popaprozac d98f528
Merge branch 'notifications_darwin' of github.com:popaprozac/wails in…
popaprozac bd85738
fix err message
popaprozac c58709c
lock registry access/writes
popaprozac b1db2bb
add missing error
popaprozac 88f1336
reorg platform impl
popaprozac 94f245f
bug fix
popaprozac e55bf8d
linux bug fix
popaprozac 9adeef2
fix linux and remove dup code
popaprozac 5dc7bd9
refactor/simplify linux
popaprozac be1da68
avoid deadlock on win
popaprozac ef3b7d2
pass service options
popaprozac 81b40d2
ensure exactly one delegate created
popaprozac f6a5bed
windows err handling
popaprozac b2b8f14
windows err handling
popaprozac f870dcc
handle notif content errors
popaprozac 9948cee
monitor dbus connection
popaprozac ace4f70
fix channel cleanup linux
popaprozac 448c78b
rewrite and simplify linux impl
popaprozac 5ddb27f
move chan creation on macos and handle linux shutdown
popaprozac a683918
remove deadlock
popaprozac 9a45423
follow dbus spec
popaprozac 7f496c9
fix linux note
popaprozac 1f82166
ensure cat id is set for macOS and other rabbit suggestions
popaprozac b102279
update example
popaprozac d25f923
wait on dbus
popaprozac 276c653
update example
popaprozac 7d0f7f4
revert linux wait and update payload on win
popaprozac af5abda
update example
popaprozac 1db65a8
stage docs
popaprozac 743882a
update docs/changelog
popaprozac 1022f47
fix docs
popaprozac bd5c82e
fix docs
popaprozac b313f2c
fix docs
popaprozac 9a41b0c
move icon method, impl interface, check compat, don't panic!
popaprozac 75dbe85
remove comptime check
popaprozac 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 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 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,304 @@ | ||
--- | ||
title: Notifications | ||
--- | ||
|
||
import { Tabs, TabItem } from "@astrojs/starlight/components"; | ||
|
||
## Introduction | ||
|
||
Wails provides a comprehensive cross-platform notification system for desktop applications. This service allows you to display native system notifications, with support for interactive elements like action buttons and text input fields. | ||
|
||
## Basic Usage | ||
|
||
### Creating the Service | ||
|
||
First, initialize the notifications service: | ||
|
||
```go | ||
import "github.com/wailsapp/wails/v3/pkg/application" | ||
import "github.com/wailsapp/wails/v3/services/notifications" | ||
|
||
// Create a new notification service | ||
notifier := notifications.New() | ||
|
||
//Register the service with the application | ||
app := application.New(application.Options{ | ||
Services: []application.Service{ | ||
application.NewService(notifier), | ||
}, | ||
}) | ||
``` | ||
|
||
## Notification Authorization | ||
|
||
Notifications on macOS require user authorization. Request and check authorization: | ||
|
||
```go | ||
authorized, err := notifier.CheckNotificationAuthorization() | ||
if err != nil { | ||
// Handle authorization error | ||
} | ||
if authorized { | ||
// Send notifications | ||
} else { | ||
// Request authorization | ||
authorized, err = notifier.RequestNotificationAuthorization() | ||
} | ||
``` | ||
On Windows and Linux this always returns `true`. | ||
|
||
## Notification Types | ||
|
||
### Basic Notifications | ||
|
||
Send a basic notification with a unique id, title, optional subtitle (macOS and Linux), and body text to users: | ||
|
||
```go | ||
notifier.SendNotification(notifications.NotificationOptions{ | ||
ID: "unique-id", | ||
Title: "New Calendar Invite", | ||
Subtitle: "From: Jane Doe", // Optional | ||
Body: "Tap to view the event" | ||
}) | ||
|
||
``` | ||
|
||
### Interactive Notifications | ||
Send a notification with action buttons and text inputs. These notifications require a notification category to be resgistered first: | ||
|
||
```go | ||
// Define a unique category id | ||
categoryID := "unique-category-id" | ||
|
||
// Define a category with actions | ||
category := notifications.NotificationCategory{ | ||
ID: categoryID, | ||
Actions: []notifications.NotificationAction{ | ||
{ | ||
ID: "OPEN", | ||
Title: "Open", | ||
}, | ||
{ | ||
ID: "ARCHIVE", | ||
Title: "Archive", | ||
Destructive: true, /* macOS-specific */ | ||
}, | ||
}, | ||
HasReplyField: true, | ||
ReplyPlaceholder: "message...", | ||
ReplyButtonTitle: "Reply", | ||
} | ||
|
||
// Register the category | ||
notifier.RegisterNotificationCategory(category) | ||
|
||
// Send an interactive notification with the actions registered in the provided category | ||
notifier.SendNotificationWithActions(notifications.NotificationOptions{ | ||
ID: "unique-id", | ||
Title: "New Message", | ||
Subtitle: "From: Jane Doe", | ||
Body: "Are you able to make it?", | ||
CategoryID: categoryID, | ||
}) | ||
``` | ||
|
||
## Notification Responses | ||
|
||
Process user interactions with notifications: | ||
|
||
```go | ||
notifier.OnNotificationResponse(func(result notifications.NotificationResult) { | ||
response := result.Response | ||
fmt.Printf("Notification %s was actioned with: %s\n", response.ID, response.ActionIdentifier) | ||
|
||
if response.ActionIdentifier == "TEXT_REPLY" { | ||
fmt.Printf("User replied: %s\n", response.UserText) | ||
} | ||
|
||
if data, ok := response.UserInfo["sender"].(string); ok { | ||
fmt.Printf("Original sender: %s\n", data) | ||
} | ||
|
||
// Emit an event to the frontend | ||
app.EmitEvent("notification", result.Response) | ||
}) | ||
``` | ||
|
||
## Notification Customisation | ||
|
||
### Custom Metadata | ||
|
||
Basic and interactive notifications can include custom data: | ||
|
||
```go | ||
notifier.SendNotification(notifications.NotificaionOptions{ | ||
ID: "unique-id", | ||
Title: "New Calendar Invite", | ||
Subtitle: "From: Jane Doe", // Optional | ||
Body: "Tap to view the event" | ||
Data: map[string]interface{}{ | ||
"sender": "[email protected]", | ||
"timestamp": "2025-03-10T15:30:00Z", | ||
} | ||
}) | ||
|
||
``` | ||
|
||
## Platform Considerations | ||
|
||
<Tabs> | ||
<TabItem label="macOS" icon="fa-brands:apple"> | ||
|
||
On macOS, notifications: | ||
|
||
- Require user authorization | ||
- Require the app to be notorized for distribution | ||
- Use system-standard notification appearances | ||
- Support `subtitle` | ||
- Support user text input | ||
- Support the `Destructive` action option | ||
- Automatically handle dark/light mode | ||
|
||
</TabItem> | ||
|
||
<TabItem label="Windows" icon="fa-brands:windows"> | ||
|
||
On Windows, notifications: | ||
|
||
- Use Windows system toast styles | ||
- Adapt to Windows theme settings | ||
- Support user text input | ||
- Support high DPI displays | ||
- Do not support `subtitle` | ||
|
||
</TabItem> | ||
|
||
<TabItem label="Linux" icon="fa-brands:linux"> | ||
|
||
On Linux, dialog behaviour depends on the desktop environment: | ||
|
||
- Use native notifications when available | ||
- Follow desktop environment theme | ||
- Position according to desktop environment rules | ||
- Support `subtitle` | ||
- Do not support user text input | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## Best Practices | ||
|
||
1. Check and request for authorization: | ||
- macOS requires user authorization | ||
|
||
2. Provide clear and concise notifications: | ||
- Use descriptive titles, subtitles, text, and action titles | ||
|
||
3. Handle dialog responses appropriately: | ||
- Check for errors in notification responses | ||
- Provide feedback for user actions | ||
|
||
4. Consider platform conventions: | ||
- Follow platform-specific notification patterns | ||
- Respect system settings | ||
|
||
## Examples | ||
|
||
Explore this example: | ||
|
||
- [Notifications](/examples/notifications) | ||
|
||
## API Reference | ||
|
||
### Service Management | ||
| Method | Description | | ||
|--------------------------------------------|-------------------------------------------------------| | ||
| `New()` | Creates a new notifications service | | ||
|
||
### Notification Authorization | ||
| Method | Description | | ||
|----------------------------------------------|------------------------------------------------------------| | ||
| `RequestNotificationAuthorization()` | Requests permission to display notifications (macOS) | | ||
| `CheckNotificationAuthorization()` | Checks current notification authorization status (macOS) | | ||
|
||
### Sending Notifications | ||
| Method | Description | | ||
|------------------------------------------------------------|---------------------------------------------------| | ||
| `SendNotification(options NotificationOptions)` | Sends a basic notification | | ||
| `SendNotificationWithActions(options NotificationOptions)` | Sends an interactive notification with actions | | ||
|
||
### Notification Categories | ||
| Method | Description | | ||
|---------------------------------------------------------------|---------------------------------------------------| | ||
| `RegisterNotificationCategory(category NotificationCategory)` | Registers a reusable notification category | | ||
| `RemoveNotificationCategory(categoryID string)` | Removes a previously registered category | | ||
|
||
### Managing Notifications | ||
| Method | Description | | ||
|-------------------------------------------------|---------------------------------------------------------------------| | ||
| `RemoveAllPendingNotifications()` | Removes all pending notifications (macOS and Linux only) | | ||
| `RemovePendingNotification(identifier string)` | Removes a specific pending notification (macOS and Linux only) | | ||
| `RemoveAllDeliveredNotifications()` | Removes all delivered notifications (macOS and Linux only) | | ||
| `RemoveDeliveredNotification(identifier string)`| Removes a specific delivered notification (macOS and Linux only) | | ||
| `RemoveNotification(identifier string)` | Removes a notification (Linux-specific) | | ||
|
||
### Event Handling | ||
| Method | Description | | ||
|--------------------------------------------------------------------|-------------------------------------------------| | ||
| `OnNotificationResponse(callback func(result NotificationResult))` | Registers a callback for notification responses | | ||
|
||
### Structs and Types | ||
|
||
#### NotificationOptions | ||
```go | ||
type NotificationOptions struct { | ||
ID string // Unique identifier for the notification | ||
Title string // Main notification title | ||
Subtitle string // Subtitle text (macOS and Linux only) | ||
Body string // Main notification content | ||
CategoryID string // Category identifier for interactive notifications | ||
Data map[string]interface{} // Custom data to associate with the notification | ||
} | ||
``` | ||
|
||
#### NotificationCategory | ||
```go | ||
type NotificationCategory struct { | ||
ID string // Unique identifier for the category | ||
Actions []NotificationAction // Button actions for the notification | ||
HasReplyField bool // Whether to include a text input field | ||
ReplyPlaceholder string // Placeholder text for the input field | ||
ReplyButtonTitle string // Text for the reply button | ||
} | ||
``` | ||
|
||
#### NotificationAction | ||
```go | ||
type NotificationAction struct { | ||
ID string // Unique identifier for the action | ||
Title string // Button text | ||
Destructive bool // Whether the action is destructive (macOS-specific) | ||
} | ||
``` | ||
|
||
#### NotificationResponse | ||
```go | ||
type NotificationResponse struct { | ||
ID string // Notification identifier | ||
ActionIdentifier string // Action that was triggered | ||
CategoryID string // Category of the notification | ||
Title string // Title of the notification | ||
Subtitle string // Subtitle of the notification | ||
Body string // Body text of the notification | ||
UserText string // Text entered by the user | ||
UserInfo map[string]interface{} // Custom data from the notification | ||
} | ||
``` | ||
|
||
#### NotificationResult | ||
```go | ||
type NotificationResult struct { | ||
Response NotificationResponse // Response data | ||
Error error // Any error that occurred | ||
} | ||
``` |
This file contains 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,59 @@ | ||
# Welcome to Your New Wails3 Project! | ||
|
||
Congratulations on generating your Wails3 application! This README will guide you through the next steps to get your project up and running. | ||
|
||
## Getting Started | ||
|
||
1. Navigate to your project directory in the terminal. | ||
|
||
2. To run your application in development mode, use the following command: | ||
|
||
``` | ||
wails3 dev | ||
``` | ||
|
||
This will start your application and enable hot-reloading for both frontend and backend changes. | ||
|
||
3. To build your application for production, use: | ||
|
||
``` | ||
wails3 build | ||
``` | ||
|
||
This will create a production-ready executable in the `build` directory. | ||
|
||
## Exploring Wails3 Features | ||
|
||
Now that you have your project set up, it's time to explore the features that Wails3 offers: | ||
|
||
1. **Check out the examples**: The best way to learn is by example. Visit the `examples` directory in the `v3/examples` directory to see various sample applications. | ||
|
||
2. **Run an example**: To run any of the examples, navigate to the example's directory and use: | ||
|
||
``` | ||
go run . | ||
``` | ||
|
||
Note: Some examples may be under development during the alpha phase. | ||
|
||
3. **Explore the documentation**: Visit the [Wails3 documentation](https://v3.wails.io/) for in-depth guides and API references. | ||
|
||
4. **Join the community**: Have questions or want to share your progress? Join the [Wails Discord](https://discord.gg/JDdSxwjhGf) or visit the [Wails discussions on GitHub](https://github.com/wailsapp/wails/discussions). | ||
|
||
## Project Structure | ||
|
||
Take a moment to familiarize yourself with your project structure: | ||
|
||
- `frontend/`: Contains your frontend code (HTML, CSS, JavaScript/TypeScript) | ||
- `main.go`: The entry point of your Go backend | ||
- `app.go`: Define your application structure and methods here | ||
- `wails.json`: Configuration file for your Wails project | ||
|
||
## Next Steps | ||
|
||
1. Modify the frontend in the `frontend/` directory to create your desired UI. | ||
2. Add backend functionality in `main.go`. | ||
3. Use `wails3 dev` to see your changes in real-time. | ||
4. When ready, build your application with `wails3 build`. | ||
|
||
Happy coding with Wails3! If you encounter any issues or have questions, don't hesitate to consult the documentation or reach out to the Wails community. |
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.
💡 Verification agent
🧩 Analysis chain
Double-check documentation URL.
The URL points to the Wails3 documentation which is still in development. Verify that this URL will be valid when the PR is merged.
🌐 Web query:
💡 Result:
The URL https://v3.wails.io/ does not appear to be valid or referenced in the official Wails v3 documentation. Based on search results, the correct URL for Wails v3 documentation is https://v3alpha.wails.io/, which is actively maintained and referenced in multiple guides and release notes[1][4][7][10][13].
This distinction is important because:
v3alpha
subdomain[1][4][7]v3alpha
prefix reflects the alpha status of the current v3 release[1][6]v3alpha
URLs[16][17]For developers working with Wails v3, the valid documentation URL is https://v3alpha.wails.io/. This aligns with the project's current pre-release status and matches all official references in March 2025 documentation[1][4][13].
Citations:
Update Documentation URL
The documentation link in
v3/examples/notifications/README.md
(line 39) currently points tohttps://v3.wails.io/
, which is not valid for Wails v3. Please update it tohttps://v3alpha.wails.io/
to align with the official, maintained documentation references.