Cocoa: add system default Sound to notification

This commit is contained in:
rich2014 2024-07-09 22:32:48 +08:00
parent 14d9977fc8
commit caad04b08d
2 changed files with 10 additions and 1 deletions

View File

@ -63,12 +63,17 @@ const
UNAuthorizationOptionCarPlay = 1 shl 3;
type
UNNotificationSound = objcclass external (NSObject)
class function defaultSound: UNNotificationSound; message 'defaultSound';
end;
UNNotificationContent = objcclass external (NSObject)
public
function title: NSString; message 'title';
function subtitle: NSString; message 'subtitle';
function body: NSString; message 'body';
function badge: NSNumber; message 'badge';
function sound: UNNotificationSound; message 'sound';
end;
UNMutableNotificationContent = objcclass external (UNNotificationContent)
@ -76,7 +81,8 @@ type
procedure setTitle( newValue: NSString ); message 'setTitle:';
procedure setSubtitle( newValue: NSString ); message 'setSubtitle:';
procedure setBody( newValue: NSString ); message 'setBody:';
procedure setBadge( newValue: NSNumber); message 'setBadge:';
procedure setBadge( newValue: NSNumber ); message 'setBadge:';
procedure setSound( newValue: UNNotificationSound ); message 'setSound:';
end;
UNNotificationTrigger = objcclass external (NSObject)

View File

@ -179,6 +179,7 @@ begin
message:= UNMutableNotificationContent.new;
message.setTitle( StrToNSString(ATrayIcon.BalloonTitle) );
message.setBody( StrToNSString(ATrayIcon.BalloonHint) );
message.setSound( UNNotificationSound.defaultSound );
request:= UNNotificationRequest.requestWithIdentifier_content_trigger(
NSString.string_, message, trigger );
@ -197,6 +198,8 @@ begin
message:= NSUserNotification.new;
message.setTitle( StrToNSString(ATrayIcon.BalloonTitle) );
message.setInformativeText( StrToNSString(ATrayIcon.BalloonHint) );
if NOT NSApplication(NSApp).isActive then
message.setSoundName( NSUserNotificationDefaultSoundName );
nc:= NSUserNotificationCenter.defaultUserNotificationCenter;
if CocoaConfig.CocoaAlwaysPresentNotification then begin