diff --git a/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.h b/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.h index 0c5bd50..9247407 100644 --- a/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.h +++ b/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.h @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable) IBOutlet SRRecorderControl *decreaseRecorderControl; - (IBAction)saveConfiguration:(nullable id)sender; +- (IBAction)openNotificationPreferences:(nullable id)sender; @end diff --git a/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.mm b/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.mm index 6f4786e..f32bd83 100644 --- a/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.mm +++ b/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.mm @@ -62,6 +62,12 @@ - (void)configureBindings options:nil]; } +- (void)openNotificationPreferences:(id)sender +{ + auto workspace = NSWorkspace.sharedWorkspace; + [workspace dpl_openNotificationPreferencesWithCompletionHandler:nil]; +} + #pragma mark - Save Configuration - (IBAction)saveConfiguration:(id)sender diff --git a/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.xib b/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.xib index e827489..8af0b0d 100644 --- a/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.xib +++ b/DPLPreferences/DPLGeneralPreferencesViewController/DPLGeneralPreferencesViewController.xib @@ -17,10 +17,10 @@ - + - + @@ -85,7 +85,7 @@ - + @@ -93,10 +93,10 @@ - + - + @@ -104,17 +104,17 @@ - + + @@ -135,24 +145,27 @@ - + - + + + + - + diff --git a/Displace.xcodeproj/project.pbxproj b/Displace.xcodeproj/project.pbxproj index fba74f0..36e921f 100644 --- a/Displace.xcodeproj/project.pbxproj +++ b/Displace.xcodeproj/project.pbxproj @@ -14,6 +14,10 @@ DA0DE9FA2597BB6E00FCFE43 /* NSURL+DPLPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = DA0DE9F82597BB6E00FCFE43 /* NSURL+DPLPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA0DE9FB2597BB6E00FCFE43 /* NSURL+DPLPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = DA0DE9F92597BB6E00FCFE43 /* NSURL+DPLPreferences.m */; }; DA2ECE6A259A1800009542DB /* DPLPreferenceItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA2ECE69259A1800009542DB /* DPLPreferenceItem.mm */; }; + DA3BA4FF25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = DA3BA4FD25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DA3BA50025E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3BA4FE25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m */; }; + DA3BA50D25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = DA3BA50B25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DA3BA50E25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3BA50C25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m */; }; DA3DC72B2598907F00275021 /* NSWorkspace+DPLPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = DA3DC7292598907F00275021 /* NSWorkspace+DPLPreferences.m */; }; DA3DC72C2598907F00275021 /* NSWorkspace+DPLPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = DA3DC72A2598907F00275021 /* NSWorkspace+DPLPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA3DC734259890DC00275021 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA3DC733259890DC00275021 /* Cocoa.framework */; }; @@ -137,6 +141,10 @@ DA2ECE69259A1800009542DB /* DPLPreferenceItem.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DPLPreferenceItem.mm; sourceTree = ""; }; DA3314ED259BA6B000B208F6 /* Configuration.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Configuration.xcconfig; sourceTree = SOURCE_ROOT; }; DA384B5425D8025C0052C1AC /* DPLDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DPLDefines.h; sourceTree = ""; }; + DA3BA4FD25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSWorkspace+DPLUserNotificationCenter.h"; sourceTree = ""; }; + DA3BA4FE25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSWorkspace+DPLUserNotificationCenter.m"; sourceTree = ""; }; + DA3BA50B25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSURL+DPLUserNotificationCenter.h"; sourceTree = ""; }; + DA3BA50C25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSURL+DPLUserNotificationCenter.m"; sourceTree = ""; }; DA3DC7292598907F00275021 /* NSWorkspace+DPLPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSWorkspace+DPLPreferences.m"; sourceTree = ""; }; DA3DC72A2598907F00275021 /* NSWorkspace+DPLPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSWorkspace+DPLPreferences.h"; sourceTree = ""; }; DA3DC733259890DC00275021 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; @@ -265,6 +273,17 @@ path = DPLNotificationCenter; sourceTree = ""; }; + DA3BA50425E1706500470E67 /* Extensions */ = { + isa = PBXGroup; + children = ( + DA3BA50B25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h */, + DA3BA50C25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m */, + DA3BA4FD25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h */, + DA3BA4FE25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m */, + ); + path = Extensions; + sourceTree = ""; + }; DA425FE425E100BC007A78BD /* DPLPreferencesContentViewController */ = { isa = PBXGroup; children = ( @@ -333,6 +352,7 @@ children = ( DAAA6B4D25D917F0003BF8E7 /* DPLUserNotificationCenter.h */, DAAA6B4C25D917F0003BF8E7 /* DPLUserNotificationCenter.m */, + DA3BA50425E1706500470E67 /* Extensions */, ); path = DPLUserNotificationCenter; sourceTree = ""; @@ -512,6 +532,8 @@ DAAF054B259789F300ED206F /* DisplaceKit.h in Headers */, DA58DBED25B745B000F9434A /* DPLGraphicsDevice.h in Headers */, DA3DC72C2598907F00275021 /* NSWorkspace+DPLPreferences.h in Headers */, + DA3BA50D25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h in Headers */, + DA3BA4FF25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -693,6 +715,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DA3BA50E25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m in Sources */, DAD639F425DAE72600627839 /* NSApplication+DPLDisplay.m in Sources */, DA58DBEE25B745B000F9434A /* DPLGraphicsDevice.m in Sources */, DA0DE9FB2597BB6E00FCFE43 /* NSURL+DPLPreferences.m in Sources */, @@ -701,6 +724,7 @@ DAAF056C25978AB000ED206F /* DPLAppGroup.m in Sources */, DA3DC72B2598907F00275021 /* NSWorkspace+DPLPreferences.m in Sources */, DAAF056A25978AB000ED206F /* DPLDisplayMode.m in Sources */, + DA3BA50025E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m in Sources */, DAAA6B4E25D917F0003BF8E7 /* DPLUserNotificationCenter.m in Sources */, DAAF056925978AB000ED206F /* DPLPreferences.m in Sources */, DAAF056E25978AB000ED206F /* DPLDisplay.m in Sources */, diff --git a/DisplaceKit/DPLUserNotificationCenter/Extensions/NSURL+DPLUserNotificationCenter.h b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSURL+DPLUserNotificationCenter.h new file mode 100644 index 0000000..1e22ace --- /dev/null +++ b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSURL+DPLUserNotificationCenter.h @@ -0,0 +1,16 @@ +// +// NSURL+DPLUserNotificationCenter.h +// DisplaceKit +// +// Created by Marcel Dierkes on 20.02.21. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSURL (DPLUserNotificationCenter) +@property (class, nonatomic, readonly) NSURL *dpl_notificationPreferencesURL; +@end + +NS_ASSUME_NONNULL_END diff --git a/DisplaceKit/DPLUserNotificationCenter/Extensions/NSURL+DPLUserNotificationCenter.m b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSURL+DPLUserNotificationCenter.m new file mode 100644 index 0000000..a787751 --- /dev/null +++ b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSURL+DPLUserNotificationCenter.m @@ -0,0 +1,18 @@ +// +// NSURL+DPLUserNotificationCenter.m +// DisplaceKit +// +// Created by Marcel Dierkes on 20.02.21. +// + +#import "NSURL+DPLUserNotificationCenter.h" +#import "DPLDefines.h" + +@implementation NSURL (DPLUserNotificationCenter) + ++ (NSURL *)dpl_notificationPreferencesURL +{ + return [self URLWithString:@"x-apple.systempreferences:com.apple.preference.notifications"]; +} + +@end diff --git a/DisplaceKit/DPLUserNotificationCenter/Extensions/NSWorkspace+DPLUserNotificationCenter.h b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSWorkspace+DPLUserNotificationCenter.h new file mode 100644 index 0000000..278775f --- /dev/null +++ b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSWorkspace+DPLUserNotificationCenter.h @@ -0,0 +1,23 @@ +// +// NSWorkspace+DPLUserNotificationCenter.h +// DisplaceKit +// +// Created by Marcel Dierkes on 20.02.21. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef void(^DPLOpenNotificationsCompletionHandler)(NSRunningApplication *_Nullable, + NSError *_Nullable); + +@interface NSWorkspace (DPLUserNotificationCenter) + +/// Opens the notifications pane in System Preferences. +/// @param completionHandler An optional completion handler, called on a private queue +- (void)dpl_openNotificationPreferencesWithCompletionHandler:(nullable DPLOpenNotificationsCompletionHandler)completionHandler; + +@end + +NS_ASSUME_NONNULL_END diff --git a/DisplaceKit/DPLUserNotificationCenter/Extensions/NSWorkspace+DPLUserNotificationCenter.m b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSWorkspace+DPLUserNotificationCenter.m new file mode 100644 index 0000000..ac3dac8 --- /dev/null +++ b/DisplaceKit/DPLUserNotificationCenter/Extensions/NSWorkspace+DPLUserNotificationCenter.m @@ -0,0 +1,30 @@ +// +// NSWorkspace+DPLUserNotificationCenter.m +// DisplaceKit +// +// Created by Marcel Dierkes on 20.02.21. +// + +#import "NSWorkspace+DPLUserNotificationCenter.h" +#import "DPLDefines.h" +#import "NSURL+DPLUserNotificationCenter.h" + +@implementation NSWorkspace (DPLUserNotificationCenter) + +- (void)dpl_openNotificationPreferencesWithCompletionHandler:(DPLOpenNotificationsCompletionHandler)completionHandler +{ + Auto prefURL = NSURL.dpl_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 diff --git a/DisplaceKit/DisplaceKit.h b/DisplaceKit/DisplaceKit.h index 9694831..9433c11 100644 --- a/DisplaceKit/DisplaceKit.h +++ b/DisplaceKit/DisplaceKit.h @@ -23,5 +23,7 @@ FOUNDATION_EXPORT const unsigned char DisplaceKitVersionString[]; #import #import #import +#import +#import #import #import