Skip to content

Commit 51d3032

Browse files
popaprozacleaanthonycoderabbitai[bot]
authored
[v2] Notifications API (#4256)
* init v2 * implement macOS and Windows * minor cleanup * fix segfault * linux * 🐰 * remove windows init * formatting * fix win icon * clean * clean * codesign full path * fix en/decoding and notification types * changelog & docs * fix options and channel fix * update docs * correct docs * Update website/docs/reference/runtime/notification.mdx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * work through rabbit suggestions * nil checks, cleanups, docs * locks * Update v2/internal/frontend/desktop/windows/notifications.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * update js runtime * update docs * second pass of comments * coherent JSON key, icon improv --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent f8595e3 commit 51d3032

24 files changed

Lines changed: 3722 additions & 9 deletions

File tree

v2/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ require (
5151
atomicgo.dev/keyboard v0.2.9 // indirect
5252
atomicgo.dev/schedule v0.1.0 // indirect
5353
dario.cat/mergo v1.0.0 // indirect
54+
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 // indirect
5455
github.com/Microsoft/go-winio v0.6.1 // indirect
5556
github.com/ProtonMail/go-crypto v1.1.5 // indirect
5657
github.com/alecthomas/chroma/v2 v2.14.0 // indirect

v2/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ atomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs=
88
atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU=
99
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
1010
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
11+
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA=
12+
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc=
1113
github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs=
1214
github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8=
1315
github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=

v2/internal/frontend/desktop/darwin/Application.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ void UpdateMenuItem(void* nsmenuitem, int checked);
6969
void RunMainLoop(void);
7070
void ReleaseContext(void *inctx);
7171

72+
/* Notifications */
73+
bool IsNotificationAvailable(void *inctx);
74+
bool CheckBundleIdentifier(void *inctx);
75+
bool EnsureDelegateInitialized(void *inctx);
76+
void RequestNotificationAuthorization(void *inctx, int channelID);
77+
void CheckNotificationAuthorization(void *inctx, int channelID);
78+
void SendNotification(void *inctx, int channelID, const char *identifier, const char *title, const char *subtitle, const char *body, const char *data_json);
79+
void SendNotificationWithActions(void *inctx, int channelID, const char *identifier, const char *title, const char *subtitle, const char *body, const char *categoryId, const char *actions_json);
80+
void RegisterNotificationCategory(void *inctx, int channelID, const char *categoryId, const char *actions_json, bool hasReplyField, const char *replyPlaceholder, const char *replyButtonTitle);
81+
void RemoveNotificationCategory(void *inctx, int channelID, const char *categoryId);
82+
void RemoveAllPendingNotifications(void *inctx);
83+
void RemovePendingNotification(void *inctx, const char *identifier);
84+
void RemoveAllDeliveredNotifications(void *inctx);
85+
void RemoveDeliveredNotification(void *inctx, const char *identifier);
86+
7287
NSString* safeInit(const char* input);
7388

7489
#endif /* Application_h */

v2/internal/frontend/desktop/darwin/Application.m

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,74 @@ void AppendSeparator(void* inMenu) {
367367
}
368368

369369

370+
bool IsNotificationAvailable(void *inctx) {
371+
WailsContext *ctx = (__bridge WailsContext*)inctx;
372+
return [ctx IsNotificationAvailable];
373+
}
374+
375+
bool CheckBundleIdentifier(void *inctx) {
376+
WailsContext *ctx = (__bridge WailsContext*)inctx;
377+
return [ctx CheckBundleIdentifier];
378+
}
379+
380+
bool EnsureDelegateInitialized(void *inctx) {
381+
WailsContext *ctx = (__bridge WailsContext*)inctx;
382+
return [ctx EnsureDelegateInitialized];
383+
}
384+
385+
void RequestNotificationAuthorization(void *inctx, int channelID) {
386+
WailsContext *ctx = (__bridge WailsContext*)inctx;
387+
[ctx RequestNotificationAuthorization:channelID];
388+
}
389+
390+
void CheckNotificationAuthorization(void *inctx, int channelID) {
391+
WailsContext *ctx = (__bridge WailsContext*)inctx;
392+
[ctx CheckNotificationAuthorization:channelID];
393+
}
394+
395+
void SendNotification(void *inctx, int channelID, const char *identifier, const char *title, const char *subtitle, const char *body, const char *data_json) {
396+
WailsContext *ctx = (__bridge WailsContext*)inctx;
397+
[ctx SendNotification:channelID :identifier :title :subtitle :body :data_json];
398+
}
399+
400+
void SendNotificationWithActions(void *inctx, int channelID, const char *identifier, const char *title, const char *subtitle, const char *body, const char *categoryId, const char *actions_json) {
401+
WailsContext *ctx = (__bridge WailsContext*)inctx;
402+
403+
[ctx SendNotificationWithActions:channelID :identifier :title :subtitle :body :categoryId :actions_json];
404+
}
405+
406+
void RegisterNotificationCategory(void *inctx, int channelID, const char *categoryId, const char *actions_json, bool hasReplyField, const char *replyPlaceholder, const char *replyButtonTitle) {
407+
WailsContext *ctx = (__bridge WailsContext*)inctx;
408+
409+
[ctx RegisterNotificationCategory:channelID :categoryId :actions_json :hasReplyField :replyPlaceholder :replyButtonTitle];
410+
}
411+
412+
void RemoveNotificationCategory(void *inctx, int channelID, const char *categoryId) {
413+
WailsContext *ctx = (__bridge WailsContext*)inctx;
414+
415+
[ctx RemoveNotificationCategory:channelID :categoryId];
416+
}
417+
418+
void RemoveAllPendingNotifications(void *inctx) {
419+
WailsContext *ctx = (__bridge WailsContext*)inctx;
420+
[ctx RemoveAllPendingNotifications];
421+
}
422+
423+
void RemovePendingNotification(void *inctx, const char *identifier) {
424+
WailsContext *ctx = (__bridge WailsContext*)inctx;
425+
[ctx RemovePendingNotification:identifier];
426+
}
427+
428+
void RemoveAllDeliveredNotifications(void *inctx) {
429+
WailsContext *ctx = (__bridge WailsContext*)inctx;
430+
[ctx RemoveAllDeliveredNotifications];
431+
}
432+
433+
void RemoveDeliveredNotification(void *inctx, const char *identifier) {
434+
WailsContext *ctx = (__bridge WailsContext*)inctx;
435+
[ctx RemoveDeliveredNotification:identifier];
436+
}
437+
370438

371439
void Run(void *inctx, const char* url) {
372440
WailsContext *ctx = (__bridge WailsContext*) inctx;

v2/internal/frontend/desktop/darwin/WailsContext.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,24 @@ struct Preferences {
9292
- (void) ShowApplication;
9393
- (void) Quit;
9494

95-
-(void) MessageDialog :(NSString*)dialogType :(NSString*)title :(NSString*)message :(NSString*)button1 :(NSString*)button2 :(NSString*)button3 :(NSString*)button4 :(NSString*)defaultButton :(NSString*)cancelButton :(void*)iconData :(int)iconDataLength;
95+
- (void) MessageDialog :(NSString*)dialogType :(NSString*)title :(NSString*)message :(NSString*)button1 :(NSString*)button2 :(NSString*)button3 :(NSString*)button4 :(NSString*)defaultButton :(NSString*)cancelButton :(void*)iconData :(int)iconDataLength;
9696
- (void) OpenFileDialog :(NSString*)title :(NSString*)defaultFilename :(NSString*)defaultDirectory :(bool)allowDirectories :(bool)allowFiles :(bool)canCreateDirectories :(bool)treatPackagesAsDirectories :(bool)resolveAliases :(bool)showHiddenFiles :(bool)allowMultipleSelection :(NSString*)filters;
9797
- (void) SaveFileDialog :(NSString*)title :(NSString*)defaultFilename :(NSString*)defaultDirectory :(bool)canCreateDirectories :(bool)treatPackagesAsDirectories :(bool)showHiddenFiles :(NSString*)filters;
9898

99+
- (bool) IsNotificationAvailable;
100+
- (bool) CheckBundleIdentifier;
101+
- (bool) EnsureDelegateInitialized;
102+
- (void) RequestNotificationAuthorization:(int)channelID;
103+
- (void) CheckNotificationAuthorization:(int)channelID;
104+
- (void) SendNotification:(int)channelID :(const char *)identifier :(const char *)title :(const char *)subtitle :(const char *)body :(const char *)dataJSON;
105+
- (void) SendNotificationWithActions:(int)channelID :(const char *)identifier :(const char *)title :(const char *)subtitle :(const char *)body :(const char *)categoryId :(const char *)actionsJSON;
106+
- (void) RegisterNotificationCategory:(int)channelID :(const char *)categoryId :(const char *)actionsJSON :(bool)hasReplyField :(const char *)replyPlaceholder :(const char *)replyButtonTitle;
107+
- (void) RemoveNotificationCategory:(int)channelID :(const char *)categoryId;
108+
- (void) RemoveAllPendingNotifications;
109+
- (void) RemovePendingNotification:(const char *)identifier;
110+
- (void) RemoveAllDeliveredNotifications;
111+
- (void) RemoveDeliveredNotification:(const char *)identifier;
112+
99113
- (void) loadRequest:(NSString*)url;
100114
- (void) ExecJS:(NSString*)script;
101115
- (NSScreen*) getCurrentScreen;

0 commit comments

Comments
 (0)