-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from newmarcel/v1.6.1/user-notifications
Added Support for User Notifications
- Loading branch information
Showing
78 changed files
with
1,497 additions
and
750 deletions.
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
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
16 changes: 16 additions & 0 deletions
16
KYAKit/KYAUserNotificationCenter/Extensions/NSURL+KYAUserNotificationCenter.h
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,16 @@ | ||
// | ||
// NSURL+KYAUserNotificationCenter.h | ||
// KYAKit | ||
// | ||
// Created by Marcel Dierkes on 20.02.21. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSURL (KYAUserNotificationCenter) | ||
@property (class, nonatomic, readonly) NSURL *kya_notificationPreferencesURL; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
18 changes: 18 additions & 0 deletions
18
KYAKit/KYAUserNotificationCenter/Extensions/NSURL+KYAUserNotificationCenter.m
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,18 @@ | ||
// | ||
// NSURL+KYAUserNotificationCenter.m | ||
// KYAKit | ||
// | ||
// Created by Marcel Dierkes on 20.02.21. | ||
// | ||
|
||
#import "NSURL+KYAUserNotificationCenter.h" | ||
#import "KYADefines.h" | ||
|
||
@implementation NSURL (KYAUserNotificationCenter) | ||
|
||
+ (NSURL *)kya_notificationPreferencesURL | ||
{ | ||
return [self URLWithString:@"x-apple.systempreferences:com.apple.preference.notifications"]; | ||
} | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
KYAKit/KYAUserNotificationCenter/Extensions/NSWorkspace+KYAUserNotificationCenter.h
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,23 @@ | ||
// | ||
// NSWorkspace+KYAUserNotificationCenter.h | ||
// KYAKit | ||
// | ||
// Created by Marcel Dierkes on 20.02.21. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
typedef void(^KYAOpenNotificationsCompletionHandler)(NSRunningApplication *_Nullable, | ||
NSError *_Nullable); | ||
|
||
@interface NSWorkspace (KYAUserNotificationCenter) | ||
|
||
/// Opens the notifications pane in System Preferences. | ||
/// @param completionHandler An optional completion handler, called on a private queue | ||
- (void)kya_openNotificationPreferencesWithCompletionHandler:(nullable KYAOpenNotificationsCompletionHandler)completionHandler API_AVAILABLE(macos(11.0)); | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
30 changes: 30 additions & 0 deletions
30
KYAKit/KYAUserNotificationCenter/Extensions/NSWorkspace+KYAUserNotificationCenter.m
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,30 @@ | ||
// | ||
// NSWorkspace+KYAUserNotificationCenter.m | ||
// KYAKit | ||
// | ||
// Created by Marcel Dierkes on 20.02.21. | ||
// | ||
|
||
#import "NSWorkspace+KYAUserNotificationCenter.h" | ||
#import "KYADefines.h" | ||
#import "NSURL+KYAUserNotificationCenter.h" | ||
|
||
@implementation NSWorkspace (KYAUserNotificationCenter) | ||
|
||
- (void)kya_openNotificationPreferencesWithCompletionHandler:(KYAOpenNotificationsCompletionHandler)completionHandler | ||
{ | ||
Auto prefURL = NSURL.kya_notificationPreferencesURL; | ||
Auto config = [NSWorkspaceOpenConfiguration configuration]; | ||
config.addsToRecentItems = NO; | ||
|
||
[self openApplicationAtURL:prefURL | ||
configuration:config | ||
completionHandler:^(NSRunningApplication *app, NSError *error) { | ||
if(completionHandler != nil) | ||
{ | ||
completionHandler(app, error); | ||
} | ||
}]; | ||
} | ||
|
||
@end |
49 changes: 49 additions & 0 deletions
49
KYAKit/KYAUserNotificationCenter/KYAUserNotificationCenter.h
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,49 @@ | ||
// | ||
// KYAUserNotificationCenter.h | ||
// KYAKit | ||
// | ||
// Created by Marcel Dierkes on 13.02.21. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class KYAUserNotification; | ||
|
||
typedef NS_ENUM(NSUInteger, KYAUserNotificationAuthorizationStatus) { | ||
KYAUserNotificationAuthorizationStatusUndetermined = 0, | ||
KYAUserNotificationAuthorizationStatusGranted, | ||
KYAUserNotificationAuthorizationStatusDenied, | ||
}; | ||
|
||
typedef void(^KYAUserNotificationsAuthorizationCompletion)(KYAUserNotificationAuthorizationStatus, NSError *_Nullable); | ||
|
||
API_AVAILABLE(macos(11.0)) | ||
@interface KYAUserNotificationCenter : NSObject | ||
@property (class, nonatomic, readonly) KYAUserNotificationCenter *sharedCenter; | ||
|
||
- (void)getAuthorizationStatusWithCompletion:(void(NS_NOESCAPE ^)(KYAUserNotificationAuthorizationStatus))completion; | ||
- (void)requestAuthorizationWithCompletion:(nullable NS_NOESCAPE KYAUserNotificationsAuthorizationCompletion)completion; | ||
- (void)requestAuthorizationIfUndetermined; | ||
|
||
- (void)postNotification:(__kindof KYAUserNotification *)notification; | ||
- (void)clearAllDeliveredNotifications; | ||
|
||
@end | ||
|
||
API_AVAILABLE(macos(11.0)) | ||
@interface KYAUserNotification : NSObject | ||
@property (copy, nonatomic) NSString *identifier; | ||
@property (copy, nonatomic, nullable) NSString *title; // use the localized setter instead | ||
@property (copy, nonatomic, nullable) NSString *subtitle; // use the localized setter instead | ||
@property (copy, nonatomic, nullable) NSString *bodyText; // use the localized setter instead | ||
@property (copy, nonatomic, nullable) NSDictionary *userInfo; | ||
|
||
- (void)setLocalizedTitleWithKey:(NSString *)key arguments:(nullable NSArray *)arguments; | ||
- (void)setLocalizedSubtitleWithKey:(NSString *)key arguments:(nullable NSArray *)arguments; | ||
- (void)setLocalizedBodyTextWithKey:(NSString *)key arguments:(nullable NSArray *)arguments; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.