-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Native notifications for Windows, Linux and OSX #3389
Closed
Closed
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
22d8d98
!F Porting FreeDesktop NotificationManager from PR
pr8x 4e58a51
!T Cleaning up the notification page
pr8x 39ea180
!B Fixing About and Exit commands
pr8x 964d28e
!F Adding support for Win10NotificationManager
pr8x fee7617
!F OSX Notification COM implementation
pr8x ba3f4b6
!F Adding CreateNotificationManager hook to IAvaloniaNativeFactory
pr8x 9efd362
!F Implementing NativeNotificationManager
pr8x 51b53a2
!T Reverting to .NET Core 2
pr8x 291a274
Merge branch 'master' into native_notifications_win_linux_osx
pr8x d7463f1
Merge branch 'master' into native_notifications_win_linux_osx
danwalmsley da4422c
!T Reverting to ReactiveCommand
pr8x a4e3230
Merge branch 'master' into native_notifications_win_linux_osx
pr8x 05ea283
!R Installing shortcut and appUserModlId in AfterSetup.
pr8x 4c4e4ab
Merge branch 'native_notifications_win_linux_osx' of https://github.c…
pr8x 70978d7
!R Making INotificationManager.Show async
pr8x e171730
Merge branch 'master' into native_notifications_win_linux_osx
pr8x 8db0b4d
!R Using ValueTask
pr8x a937b2c
!T Don't create notifier every time notification is requested
pr8x 7c76b26
!T Removing duplicate package
pr8x c9913df
!R Fallback to null when FreeDesktopNotificationManager fails to init…
pr8x 625faf9
!R Moving AfterSetup() into Win32Platform
pr8x 7323816
!T Removing service check
pr8x 62d3953
Merge branch 'master' into native_notifications_win_linux_osx
pr8x 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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...e/Avalonia.Native/src/OSX/KeyTransform.mm → .../Avalonia.Native/src/OSX/key_transform.mm
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
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,83 @@ | ||
#include "common.h" | ||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface NotificationCenterDelegate : NSObject<NSUserNotificationCenterDelegate> | ||
@property AvnNotificationActionCallback ActionCallback; | ||
@property AvnNotificationCloseCallback CloseCallback; | ||
@end | ||
|
||
@implementation NotificationCenterDelegate | ||
|
||
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification | ||
{ | ||
// Force notifications to be always displayed even when running in foreground | ||
return YES; | ||
} | ||
|
||
-(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification | ||
{ | ||
if (notification.activationType != NSUserNotificationActivationTypeContentsClicked && | ||
notification.activationType != NSUserNotificationActivationTypeActionButtonClicked) { | ||
return; | ||
} | ||
|
||
[self ActionCallback]([notification.identifier intValue]); | ||
} | ||
@end | ||
|
||
class NotificationManager : public ComSingleObject<IAvnNotificationManager, &IID_IAvnNotificationManager> | ||
{ | ||
NotificationCenterDelegate* _notificationCenterDelegate; | ||
|
||
public: | ||
FORWARD_IUNKNOWN() | ||
|
||
NotificationManager() { | ||
_notificationCenterDelegate = [NotificationCenterDelegate new]; | ||
} | ||
|
||
virtual bool ShowNotification(AvnNotification* notification) override { | ||
|
||
NSUserNotificationCenter* notificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter]; | ||
notificationCenter.delegate = _notificationCenterDelegate; | ||
|
||
NSUserNotification* cocoaNotification = [NSUserNotification new]; | ||
|
||
int notificationId = notification->identifier; | ||
cocoaNotification.identifier = [NSString stringWithFormat:@"%i", notificationId]; | ||
cocoaNotification.title = [NSString stringWithUTF8String:notification->TitleUtf8]; | ||
cocoaNotification.informativeText = [NSString stringWithUTF8String:notification->TextUtf8]; | ||
|
||
[notificationCenter deliverNotification:cocoaNotification]; | ||
|
||
if (notification->durationMs != 0) { | ||
unsigned long long durationNs = notification->durationMs * NSEC_PER_MSEC; | ||
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, durationNs), dispatch_get_main_queue(), ^{ | ||
[notificationCenter removeDeliveredNotification:cocoaNotification]; | ||
|
||
//TODO: HACK: I can't find a global close event... Might be missing something. | ||
_notificationCenterDelegate.CloseCallback(notificationId); | ||
}); | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
virtual void SetCloseCallback(AvnNotificationCloseCallback callback) override { | ||
_notificationCenterDelegate.CloseCallback = callback; | ||
} | ||
|
||
virtual void SetActionCallback(AvnNotificationActionCallback callback) override { | ||
_notificationCenterDelegate.ActionCallback = callback; | ||
} | ||
|
||
}; | ||
|
||
extern IAvnNotificationManager* CreateNotificationManager() | ||
{ | ||
@autoreleasepool | ||
{ | ||
return new NotificationManager(); | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
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
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.
We should add an option to configure that with
AvaloniaNativeMacOptions
and fall back to"com.avaloniaui.apps."+Assembly.GetEntryAssembly().Name
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.
This probably should also somehow interact with bundle identifier from Info.plist if the app is running from an actual app bundle.
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.
I guess we should check the
[[NSBundle mainBundle] bundleIdentifier]
and only install the fake bundle identifier when there is no mainBundle identifier.