Skip to content

Commit

Permalink
Open Notification Preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
newmarcel committed Feb 20, 2021
1 parent b11ee86 commit dc8b678
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<view translatesAutoresizingMaskIntoConstraints="NO" id="Daq-z8-Htp">
<rect key="frame" x="0.0" y="0.0" width="450" height="366"/>
<rect key="frame" x="0.0" y="0.0" width="450" height="403"/>
<subviews>
<gridView xPlacement="fill" yPlacement="fill" rowAlignment="firstBaseline" rowSpacing="12" columnSpacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="i53-oP-FEP">
<rect key="frame" x="85" y="172" width="281" height="98"/>
<rect key="frame" x="85" y="212" width="281" height="98"/>
<rows>
<gridRow id="gvt-Mp-5Tf"/>
<gridRow id="Q23-VX-aET"/>
Expand Down Expand Up @@ -85,36 +85,36 @@
</gridCells>
</gridView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="E6N-DG-En9">
<rect key="frame" x="18" y="278" width="133" height="16"/>
<rect key="frame" x="18" y="318" width="133" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Keyboard Shortcuts" id="tWO-UC-goz">
<font key="font" textStyle="headline" name=".SFNS-Bold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Hvd-ip-01E">
<rect key="frame" x="20" y="149" width="410" height="5"/>
<rect key="frame" x="20" y="189" width="410" height="5"/>
</box>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="XJU-MD-fgk">
<rect key="frame" x="18" y="93" width="414" height="14"/>
<rect key="frame" x="18" y="133" width="414" height="14"/>
<textFieldCell key="cell" selectable="YES" title="Filters the list of display resolutions to only contain Retina display resolutions." id="ykW-Rh-h2z">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bMa-8y-ktg">
<rect key="frame" x="18" y="114" width="412" height="18"/>
<rect key="frame" x="18" y="154" width="412" height="18"/>
<buttonCell key="cell" type="check" title="Show Non-Retina Display Resolutions" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="bKn-md-gjk">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Tzp-VF-MKL">
<rect key="frame" x="20" y="70" width="410" height="5"/>
<rect key="frame" x="20" y="110" width="410" height="5"/>
</box>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aeP-5A-RBT">
<rect key="frame" x="190" y="25" width="247" height="32"/>
<rect key="frame" x="190" y="13" width="247" height="32"/>
<buttonCell key="cell" type="push" title="Save Current Display Configuration" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3qY-QY-aRJ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -123,6 +123,16 @@
<action selector="saveConfiguration:" target="-2" id="xgu-Th-D8D"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8dc-Nc-NBF">
<rect key="frame" x="13" y="65" width="217" height="32"/>
<buttonCell key="cell" type="push" title="Open Notification Preferences" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="tny-eB-qCw">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="openNotificationPreferences:" target="-2" id="cgT-x5-aLB"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="bMa-8y-ktg" firstAttribute="top" secondItem="Hvd-ip-01E" secondAttribute="bottom" constant="20" id="1sn-5V-mBv"/>
Expand All @@ -135,24 +145,27 @@
<constraint firstItem="XJU-MD-fgk" firstAttribute="top" secondItem="bMa-8y-ktg" secondAttribute="bottom" constant="8" symbolic="YES" id="LRf-8p-tcp"/>
<constraint firstItem="E6N-DG-En9" firstAttribute="top" secondItem="Cix-C3-8mG" secondAttribute="top" id="MgO-YX-u74"/>
<constraint firstItem="i53-oP-FEP" firstAttribute="centerX" secondItem="Daq-z8-Htp" secondAttribute="centerX" id="OWa-Jr-MJa"/>
<constraint firstItem="aeP-5A-RBT" firstAttribute="top" secondItem="Tzp-VF-MKL" secondAttribute="bottom" constant="20" id="Owd-8u-oaI"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="leading" relation="lessThanOrEqual" secondItem="aeP-5A-RBT" secondAttribute="leading" id="Q1Y-40-qtS"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="8dc-Nc-NBF" secondAttribute="trailing" id="Q56-eA-SH7"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="XJU-MD-fgk" secondAttribute="bottom" id="SDA-20-kZJ"/>
<constraint firstItem="Hvd-ip-01E" firstAttribute="top" secondItem="i53-oP-FEP" secondAttribute="bottom" constant="20" id="SSP-SO-qd8"/>
<constraint firstItem="Tzp-VF-MKL" firstAttribute="leading" secondItem="Daq-z8-Htp" secondAttribute="leading" constant="20" symbolic="YES" id="VAO-uh-yen"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="trailing" secondItem="bMa-8y-ktg" secondAttribute="trailing" id="Wef-r9-qhB"/>
<constraint firstItem="XJU-MD-fgk" firstAttribute="trailing" secondItem="Cix-C3-8mG" secondAttribute="trailing" id="WlV-W0-WDx"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="aeP-5A-RBT" secondAttribute="bottom" constant="20" id="XUy-on-Njj"/>
<constraint firstItem="8dc-Nc-NBF" firstAttribute="top" secondItem="Tzp-VF-MKL" secondAttribute="bottom" constant="20" id="Wlo-lt-aE0"/>
<constraint firstItem="8dc-Nc-NBF" firstAttribute="leading" secondItem="Cix-C3-8mG" secondAttribute="leading" id="XNT-o5-92K"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="bottom" secondItem="aeP-5A-RBT" secondAttribute="bottom" id="XUy-on-Njj"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="E6N-DG-En9" secondAttribute="trailing" constant="20" symbolic="YES" id="bf8-i9-Pre"/>
<constraint firstAttribute="trailing" secondItem="Hvd-ip-01E" secondAttribute="trailing" constant="20" symbolic="YES" id="d4a-Jm-gIA"/>
<constraint firstAttribute="trailing" secondItem="Tzp-VF-MKL" secondAttribute="trailing" constant="20" symbolic="YES" id="fmo-5W-CX3"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="i53-oP-FEP" secondAttribute="trailing" id="jcI-B7-BXA"/>
<constraint firstItem="Cix-C3-8mG" firstAttribute="leading" relation="lessThanOrEqual" secondItem="i53-oP-FEP" secondAttribute="leading" id="jlW-4s-v6j"/>
<constraint firstItem="aeP-5A-RBT" firstAttribute="top" relation="greaterThanOrEqual" secondItem="8dc-Nc-NBF" secondAttribute="bottom" constant="20" id="qJp-fN-zJB"/>
<constraint firstItem="E6N-DG-En9" firstAttribute="leading" secondItem="Daq-z8-Htp" secondAttribute="leading" constant="20" symbolic="YES" id="saf-Yz-ncc"/>
</constraints>
<viewLayoutGuide key="safeArea" id="jMq-yQ-GzE"/>
<viewLayoutGuide key="layoutMargins" id="Cix-C3-8mG"/>
<point key="canvasLocation" x="1" y="144"/>
<point key="canvasLocation" x="1" y="162.5"/>
</view>
</objects>
</document>
24 changes: 24 additions & 0 deletions Displace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -137,6 +141,10 @@
DA2ECE69259A1800009542DB /* DPLPreferenceItem.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DPLPreferenceItem.mm; sourceTree = "<group>"; };
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 = "<group>"; };
DA3BA4FD25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSWorkspace+DPLUserNotificationCenter.h"; sourceTree = "<group>"; };
DA3BA4FE25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSWorkspace+DPLUserNotificationCenter.m"; sourceTree = "<group>"; };
DA3BA50B25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSURL+DPLUserNotificationCenter.h"; sourceTree = "<group>"; };
DA3BA50C25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSURL+DPLUserNotificationCenter.m"; sourceTree = "<group>"; };
DA3DC7292598907F00275021 /* NSWorkspace+DPLPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSWorkspace+DPLPreferences.m"; sourceTree = "<group>"; };
DA3DC72A2598907F00275021 /* NSWorkspace+DPLPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSWorkspace+DPLPreferences.h"; sourceTree = "<group>"; };
DA3DC733259890DC00275021 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -265,6 +273,17 @@
path = DPLNotificationCenter;
sourceTree = "<group>";
};
DA3BA50425E1706500470E67 /* Extensions */ = {
isa = PBXGroup;
children = (
DA3BA50B25E1829300470E67 /* NSURL+DPLUserNotificationCenter.h */,
DA3BA50C25E1829300470E67 /* NSURL+DPLUserNotificationCenter.m */,
DA3BA4FD25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.h */,
DA3BA4FE25E1706100470E67 /* NSWorkspace+DPLUserNotificationCenter.m */,
);
path = Extensions;
sourceTree = "<group>";
};
DA425FE425E100BC007A78BD /* DPLPreferencesContentViewController */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -333,6 +352,7 @@
children = (
DAAA6B4D25D917F0003BF8E7 /* DPLUserNotificationCenter.h */,
DAAA6B4C25D917F0003BF8E7 /* DPLUserNotificationCenter.m */,
DA3BA50425E1706500470E67 /* Extensions */,
);
path = DPLUserNotificationCenter;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NSURL+DPLUserNotificationCenter.h
// DisplaceKit
//
// Created by Marcel Dierkes on 20.02.21.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSURL (DPLUserNotificationCenter)
@property (class, nonatomic, readonly) NSURL *dpl_notificationPreferencesURL;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// NSWorkspace+DPLUserNotificationCenter.h
// DisplaceKit
//
// Created by Marcel Dierkes on 20.02.21.
//

#import <Cocoa/Cocoa.h>

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
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions DisplaceKit/DisplaceKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ FOUNDATION_EXPORT const unsigned char DisplaceKitVersionString[];
#import <DisplaceKit/DPLAppGroup.h>
#import <DisplaceKit/NSURL+DPLPreferences.h>
#import <DisplaceKit/NSWorkspace+DPLPreferences.h>
#import <DisplaceKit/NSURL+DPLUserNotificationCenter.h>
#import <DisplaceKit/NSWorkspace+DPLUserNotificationCenter.h>
#import <DisplaceKit/NSScreen+DPLDisplay.h>
#import <DisplaceKit/NSApplication+DPLDisplay.h>

0 comments on commit dc8b678

Please sign in to comment.