Skip to content

[v3] Notifications API #4098

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

Merged
merged 101 commits into from
Apr 13, 2025
Merged
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
32839bd
initial notification impl
popaprozac Feb 20, 2025
274511c
update log message
popaprozac Feb 21, 2025
f694ad2
service and minor refactor
popaprozac Feb 22, 2025
cc524d7
update example
popaprozac Feb 22, 2025
87f15ce
refactor
popaprozac Feb 22, 2025
91f1704
cleanup
popaprozac Feb 22, 2025
01fa307
windows impl
popaprozac Feb 23, 2025
c7d54e2
remove app event
popaprozac Feb 23, 2025
7757eae
standalone example
popaprozac Feb 23, 2025
9f39577
add comments
popaprozac Feb 23, 2025
47a0977
add overwrite and remove notification category
popaprozac Feb 23, 2025
6d44068
save notification categories to registry
popaprozac Feb 23, 2025
ab9c460
quick fixes
popaprozac Feb 23, 2025
27e512d
add data option to basic notification
popaprozac Feb 23, 2025
f8647ff
update min macos version
popaprozac Feb 23, 2025
c1230d4
update win impl to match
popaprozac Feb 23, 2025
9eab58f
update comments
popaprozac Feb 23, 2025
cc760a1
test data with toast
popaprozac Feb 23, 2025
978a982
don't add title or body quite yet
popaprozac Feb 23, 2025
bf4222c
update example
popaprozac Feb 24, 2025
c904433
update example
popaprozac Feb 24, 2025
983c25f
rw safety
popaprozac Feb 24, 2025
1e3511c
fix deadlock
popaprozac Feb 24, 2025
3dbf058
update comments
popaprozac Feb 24, 2025
be716fc
fix input id
popaprozac Feb 25, 2025
8da9981
for review
popaprozac Feb 25, 2025
e8ad42a
switch to callback style
popaprozac Feb 25, 2025
8bbe381
Merge branch 'v3-alpha' into notifications_darwin
popaprozac Feb 25, 2025
67adc45
update example
popaprozac Feb 25, 2025
253f672
init linux
popaprozac Feb 25, 2025
135defc
init test linux
popaprozac Feb 25, 2025
7bbc275
fix windows
popaprozac Feb 25, 2025
fa498f1
encode user data on windows
popaprozac Feb 25, 2025
050e4ef
fix default complex action
popaprozac Feb 25, 2025
60c1a86
update example
popaprozac Feb 25, 2025
10ae1f6
export config from app
popaprozac Feb 25, 2025
a4c4ab6
add id to macOS payload
popaprozac Feb 25, 2025
acad85e
update example
popaprozac Feb 25, 2025
60ae0c1
test linux userInfo
popaprozac Feb 26, 2025
47e5b10
add debug
popaprozac Feb 26, 2025
5ad3d73
wrangle variants
popaprozac Feb 26, 2025
e86cf68
linux?
popaprozac Feb 26, 2025
db2cab7
grab icon from app for notifications on windows
popaprozac Feb 26, 2025
e216b3e
set icon
popaprozac Feb 26, 2025
207b162
Merge branch 'notifications_darwin' of github.com:popaprozac/wails in…
popaprozac Feb 26, 2025
3bdb3dd
use app icon
popaprozac Feb 26, 2025
a807c26
better interop with obj-c
popaprozac Feb 27, 2025
ad74972
can you tell i'm not a go programmer?
popaprozac Feb 27, 2025
d9af6de
ignore bindings notification callback
popaprozac Mar 3, 2025
833d8ec
refactor macos
popaprozac Mar 5, 2025
e4ec06a
update example
Mar 14, 2025
1e67e94
rename auth func
popaprozac Mar 15, 2025
1fa6894
//
popaprozac Mar 15, 2025
e46abdc
update example
popaprozac Mar 15, 2025
2cb0dac
set default action id on MATE
popaprozac Mar 15, 2025
6d15f08
Merge branch 'v3-alpha' into notifications_darwin
popaprozac Mar 15, 2025
e810d6a
tidy
popaprozac Mar 15, 2025
e4e24a0
clean
popaprozac Mar 19, 2025
b60ef77
coderabbit impr
popaprozac Mar 19, 2025
ee885fe
fix mem crash
popaprozac Mar 19, 2025
4af058b
more cleanup
popaprozac Mar 20, 2025
58b5c10
Merge branch 'v3-alpha' into notifications_darwin
popaprozac Mar 20, 2025
25256f7
allow only one notification service per app
popaprozac Mar 20, 2025
d98f528
Merge branch 'notifications_darwin' of github.com:popaprozac/wails in…
popaprozac Mar 20, 2025
bd85738
fix err message
popaprozac Mar 20, 2025
c58709c
lock registry access/writes
popaprozac Mar 20, 2025
b1db2bb
add missing error
popaprozac Mar 20, 2025
88f1336
reorg platform impl
popaprozac Mar 20, 2025
94f245f
bug fix
popaprozac Mar 20, 2025
e55bf8d
linux bug fix
popaprozac Mar 20, 2025
9adeef2
fix linux and remove dup code
popaprozac Mar 20, 2025
5dc7bd9
refactor/simplify linux
popaprozac Mar 20, 2025
be1da68
avoid deadlock on win
popaprozac Mar 21, 2025
ef3b7d2
pass service options
popaprozac Mar 22, 2025
81b40d2
ensure exactly one delegate created
popaprozac Mar 22, 2025
f6a5bed
windows err handling
popaprozac Mar 22, 2025
b2b8f14
windows err handling
popaprozac Mar 22, 2025
f870dcc
handle notif content errors
popaprozac Mar 23, 2025
9948cee
monitor dbus connection
popaprozac Mar 23, 2025
ace4f70
fix channel cleanup linux
popaprozac Mar 23, 2025
448c78b
rewrite and simplify linux impl
popaprozac Mar 23, 2025
5ddb27f
move chan creation on macos and handle linux shutdown
popaprozac Mar 23, 2025
a683918
remove deadlock
popaprozac Mar 23, 2025
9a45423
follow dbus spec
popaprozac Mar 24, 2025
7f496c9
fix linux note
popaprozac Mar 24, 2025
1f82166
ensure cat id is set for macOS and other rabbit suggestions
popaprozac Mar 24, 2025
b102279
update example
popaprozac Mar 24, 2025
d25f923
wait on dbus
popaprozac Mar 25, 2025
276c653
update example
popaprozac Mar 25, 2025
7d0f7f4
revert linux wait and update payload on win
popaprozac Mar 25, 2025
af5abda
update example
popaprozac Mar 25, 2025
1db65a8
stage docs
popaprozac Mar 27, 2025
743882a
update docs/changelog
popaprozac Mar 27, 2025
1022f47
fix docs
popaprozac Mar 27, 2025
bd5c82e
fix docs
popaprozac Mar 27, 2025
b313f2c
fix docs
popaprozac Mar 27, 2025
9a41b0c
move icon method, impl interface, check compat, don't panic!
popaprozac Mar 30, 2025
75dbe85
remove comptime check
popaprozac Mar 30, 2025
0b546a1
Merge branch 'v3-alpha' into notifications_darwin
leaanthony Apr 12, 2025
be1d500
Update v3/examples/notifications/build/windows/nsis/wails_tools.nsh
leaanthony Apr 12, 2025
a8e91e7
Merge branch 'v3-alpha' into notifications_darwin
leaanthony Apr 12, 2025
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
Prev Previous commit
Next Next commit
grab icon from app for notifications on windows
  • Loading branch information
popaprozac committed Feb 26, 2025
commit db2cab7b7cfd3101e03cc0485a29b01000b55753
39 changes: 25 additions & 14 deletions v3/pkg/services/notifications/notifications_windows.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"

"git.sr.ht/~jackmordaunt/go-toast/v2"
@@ -39,9 +38,6 @@ func New() *Service {
// Sets an activation callback to emit an event when notifications are interacted with.
func (ns *Service) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
appName := application.Get().Config().Name
icon := application.Get().Config().Icon

println(icon)

guid, err := getGUID(appName)
if err != nil {
@@ -51,7 +47,7 @@ func (ns *Service) ServiceStartup(ctx context.Context, options application.Servi
toast.SetAppData(toast.AppData{
AppID: appName,
GUID: guid,
IconPath: "C:\\Users\\Zach\\Development\\notifications_demo\\build\\appicon.ico",
IconPath: filepath.Join(os.TempDir(), appName+guid+".png"),
})

toast.SetActivationCallback(func(args string, data []toast.UserData) {
@@ -105,11 +101,14 @@ func (ns *Service) CheckNotificationAuthorization() bool {
// SendNotification sends a basic notification with a name, title, and body. All other options are ignored on Windows.
// (subtitle and category id are only available on macOS)
func (ns *Service) SendNotification(options NotificationOptions) error {
if err := saveIconToDir(); err != nil {
fmt.Printf("Error saving icon: %v\n", err)
}

n := toast.Notification{
Title: options.Title,
Body: options.Body,
ActivationArguments: DefaultActionIdentifier,
Audio: toast.IM,
}

if options.Data != nil {
@@ -127,6 +126,10 @@ func (ns *Service) SendNotification(options NotificationOptions) error {
// If a NotificationCategory is not registered a basic notification will be sent.
// (subtitle and category id are only available on macOS)
func (ns *Service) SendNotificationWithActions(options NotificationOptions) error {
if err := saveIconToDir(); err != nil {
fmt.Printf("Error saving icon: %v\n", err)
}

NotificationLock.RLock()
nCategory := NotificationCategories[options.CategoryID]
NotificationLock.RUnlock()
@@ -135,7 +138,6 @@ func (ns *Service) SendNotificationWithActions(options NotificationOptions) erro
Title: options.Title,
Body: options.Body,
ActivationArguments: DefaultActionIdentifier,
Audio: toast.IM,
}

for _, action := range nCategory.Actions {
@@ -273,18 +275,27 @@ func parseNotificationResponse(response string) (action string, data string) {
return actionID, ""
}

// Is there a better way for me to grab this from the Wails config?
func getExeName() string {
executable, err := os.Executable()
func saveIconToDir() error {
options := application.Get().Config()
appName := options.Name
icon := options.Icon

if len(icon) == 0 {
return fmt.Errorf("failed to retrieve icon from application")
}

guid, err := getGUID(appName)
if err != nil {
return ""
return fmt.Errorf("failed to retrieve application guid from registry")
}

return strings.TrimSuffix(filepath.Base(executable), filepath.Ext(executable))
iconPath := filepath.Join(os.TempDir(), appName+guid+".png")

return os.WriteFile(iconPath, icon, 0644)
}

func saveCategoriesToRegistry() error {
appName := getExeName()
appName := application.Get().Config().Name
if appName == "" {
return fmt.Errorf("failed to save categories to registry: empty executable name")
}
@@ -311,7 +322,7 @@ func saveCategoriesToRegistry() error {
}

func loadCategoriesFromRegistry() error {
appName := getExeName()
appName := application.Get().Config().Name
if appName == "" {
return fmt.Errorf("failed to save categories to registry: empty executable name")
}