Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit b4f5bfc

Browse files
committed
Add Global Shortcut Key
- Notarized
1 parent ba9d0ad commit b4f5bfc

File tree

14 files changed

+181
-80
lines changed

14 files changed

+181
-80
lines changed

Dynamic.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@
326326
CreatedOnToolsVersion = 10.0;
327327
LastSwiftMigration = 1000;
328328
SystemCapabilities = {
329+
com.apple.HardenedRuntime = {
330+
enabled = 1;
331+
};
329332
com.apple.Push = {
330333
enabled = 0;
331334
};
@@ -336,6 +339,11 @@
336339
};
337340
52C3511720CC57B60073F0CA = {
338341
CreatedOnToolsVersion = 10.0;
342+
SystemCapabilities = {
343+
com.apple.HardenedRuntime = {
344+
enabled = 1;
345+
};
346+
};
339347
};
340348
};
341349
};
@@ -409,13 +417,15 @@
409417
);
410418
inputPaths = (
411419
"${PODS_ROOT}/Target Support Files/Pods-Dynamic/Pods-Dynamic-frameworks.sh",
420+
"${BUILT_PRODUCTS_DIR}/MASShortcut/MASShortcut.framework",
412421
"${BUILT_PRODUCTS_DIR}/Schedule/Schedule.framework",
413422
"${BUILT_PRODUCTS_DIR}/Solar/Solar.framework",
414423
"${BUILT_PRODUCTS_DIR}/LetsMove/LetsMove.framework",
415424
"${PODS_ROOT}/Sparkle/Sparkle.framework",
416425
);
417426
name = "[CP] Embed Pods Frameworks";
418427
outputPaths = (
428+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MASShortcut.framework",
419429
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Schedule.framework",
420430
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Solar.framework",
421431
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LetsMove.framework",
@@ -625,6 +635,7 @@
625635
CODE_SIGN_STYLE = Automatic;
626636
COMBINE_HIDPI_IMAGES = YES;
627637
DEVELOPMENT_TEAM = KZ7D8X3PRK;
638+
ENABLE_HARDENED_RUNTIME = YES;
628639
INFOPLIST_FILE = "$(SRCROOT)/Dynamic/Supporting Files/Info.plist";
629640
LD_RUNPATH_SEARCH_PATHS = (
630641
"$(inherited)",
@@ -651,6 +662,7 @@
651662
CODE_SIGN_STYLE = Automatic;
652663
COMBINE_HIDPI_IMAGES = YES;
653664
DEVELOPMENT_TEAM = KZ7D8X3PRK;
665+
ENABLE_HARDENED_RUNTIME = YES;
654666
INFOPLIST_FILE = "$(SRCROOT)/Dynamic/Supporting Files/Info.plist";
655667
LD_RUNPATH_SEARCH_PATHS = (
656668
"$(inherited)",
@@ -676,6 +688,7 @@
676688
CODE_SIGN_STYLE = Automatic;
677689
COMBINE_HIDPI_IMAGES = YES;
678690
DEVELOPMENT_TEAM = KZ7D8X3PRK;
691+
ENABLE_HARDENED_RUNTIME = YES;
679692
INFOPLIST_FILE = DynamicLauncher/Info.plist;
680693
LD_RUNPATH_SEARCH_PATHS = (
681694
"$(inherited)",
@@ -698,6 +711,7 @@
698711
CODE_SIGN_STYLE = Automatic;
699712
COMBINE_HIDPI_IMAGES = YES;
700713
DEVELOPMENT_TEAM = KZ7D8X3PRK;
714+
ENABLE_HARDENED_RUNTIME = YES;
701715
INFOPLIST_FILE = DynamicLauncher/Info.plist;
702716
LD_RUNPATH_SEARCH_PATHS = (
703717
"$(inherited)",
@@ -776,6 +790,7 @@
776790
CODE_SIGN_STYLE = Automatic;
777791
COMBINE_HIDPI_IMAGES = YES;
778792
DEVELOPMENT_TEAM = KZ7D8X3PRK;
793+
ENABLE_HARDENED_RUNTIME = YES;
779794
INFOPLIST_FILE = "$(SRCROOT)/Dynamic/Supporting Files/Info.plist";
780795
LD_RUNPATH_SEARCH_PATHS = (
781796
"$(inherited)",
@@ -815,6 +830,7 @@
815830
CODE_SIGN_STYLE = Automatic;
816831
COMBINE_HIDPI_IMAGES = YES;
817832
DEVELOPMENT_TEAM = KZ7D8X3PRK;
833+
ENABLE_HARDENED_RUNTIME = YES;
818834
INFOPLIST_FILE = DynamicLauncher/Info.plist;
819835
LD_RUNPATH_SEARCH_PATHS = (
820836
"$(inherited)",
@@ -899,6 +915,7 @@
899915
CODE_SIGN_STYLE = Automatic;
900916
COMBINE_HIDPI_IMAGES = YES;
901917
DEVELOPMENT_TEAM = KZ7D8X3PRK;
918+
ENABLE_HARDENED_RUNTIME = YES;
902919
INFOPLIST_FILE = "$(SRCROOT)/Dynamic/Supporting Files/Info.plist";
903920
LD_RUNPATH_SEARCH_PATHS = (
904921
"$(inherited)",
@@ -938,6 +955,7 @@
938955
CODE_SIGN_STYLE = Automatic;
939956
COMBINE_HIDPI_IMAGES = YES;
940957
DEVELOPMENT_TEAM = KZ7D8X3PRK;
958+
ENABLE_HARDENED_RUNTIME = YES;
941959
INFOPLIST_FILE = DynamicLauncher/Info.plist;
942960
LD_RUNPATH_SEARCH_PATHS = (
943961
"$(inherited)",

Dynamic/Supporting Files/Credits.rtf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@
88
\f0\fs24 \cf0 # Acknowledgements\
99
This application makes use of the following third party libraries:\
1010
\
11+
## MASShortcut\
12+
\
13+
Copyright (c) 2012-2013, Vadim Shpakovski\
14+
All rights reserved.\
15+
\
16+
Redistribution and use in source and binary forms, with or without\
17+
modification, are permitted provided that the following conditions are met:\
18+
\
19+
1. Redistributions of source code must retain the above copyright notice, this\
20+
list of conditions and the following disclaimer.\
21+
2. Redistributions in binary form must reproduce the above copyright notice,\
22+
this list of conditions and the following disclaimer in the documentation\
23+
and/or other materials provided with the distribution.\
24+
\
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\
26+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\
27+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\
28+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\
29+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\
30+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\
31+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\
32+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\
33+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\
34+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\
35+
\
36+
\
1137
## Schedule\
1238
\
1339
MIT License\

Dynamic/Utilities/Brightness/ScreenBrightnessObserver.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ final class ScreenBrightnessObserver: NSObject {
3030

3131
@objc private func updateForBrightnessChange() {
3232
let brightness = NSScreen.brightness
33-
#if DEBUG
34-
print("Brightness Changed to \(brightness)")
35-
#else
36-
os_log("Brightness Changed")
37-
#endif
3833
let threshold = preferences.brightnessThreshold
3934
switch brightness {
4035
case 0..<threshold:
@@ -76,11 +71,6 @@ final class ScreenBrightnessObserver: NSObject {
7671
change: [NSKeyValueChangeKey : Any]?,
7772
context: UnsafeMutableRawPointer?) {
7873
let isDarkModeOn = AppleInterfaceStyle.isDark
79-
#if DEBUG
80-
print("User Defaults Turned Dark Mode \(isDarkModeOn ? "On" : "Off")")
81-
#else
82-
os_log("Dynamic - User Defaults Changed")
83-
#endif
8474
guard #available(OSX 10.14, *) else { return }
8575
let styleName: NSAppearance.Name = isDarkModeOn ? .aqua : .darkAqua
8676
NSAppearance.current = NSAppearance(named: styleName)

Dynamic/Utilities/Localizations.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ enum LocalizedString {
3737
value: "Nautical",
3838
comment: "Nautical"
3939
)
40-
static let astronimical = NSLocalizedString(
41-
"SunsetSunrise.Astronimical",
42-
value: "Astronimical",
43-
comment: "Astronimical"
40+
static let astronomical = NSLocalizedString(
41+
"SunsetSunrise.Astronomical",
42+
value: "Astronomical",
43+
comment: "Astronomical"
4444
)
4545
static let customRange = NSLocalizedString(
4646
"SunsetSunrise.CustomRange",

Dynamic/Utilities/Preferences.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Cocoa
1010
import CoreLocation
1111
import ServiceManagement
12+
import MASShortcut
1213

1314
enum Sandbox {
1415
public static var isOn: Bool {
@@ -21,7 +22,18 @@ enum Sandbox {
2122
typealias Preferences = UserDefaults
2223
public let preferences = NSUserDefaultsController.shared.defaults
2324

24-
extension UserDefaults {
25+
extension Preferences {
26+
public static func setup() {
27+
preferences.adjustForBrightness = true
28+
preferences.brightnessThreshold = 0.5
29+
preferences.scheduleZenithType = .official
30+
preferences.scheduled = true
31+
preferences.opensAtLogin = true
32+
preferences.settingsStyle = .rightClick
33+
}
34+
}
35+
36+
extension Preferences {
2537
private static var handles: [NSKeyValueObservation] = []
2638

2739
public static func removeObservers() {
@@ -247,4 +259,8 @@ extension UserDefaults {
247259
rawSettingsStyle = newValue.rawValue
248260
}
249261
}
262+
263+
var toggleShortcutKey: String {
264+
return "toggleShortcut"
265+
}
250266
}

Dynamic/Utilities/Scheduler.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import CoreLocation
1010
import UserNotifications
1111
import Solar
1212
import Schedule
13+
import os.log
1314

1415
public final class Scheduler: NSObject, CLLocationManagerDelegate {
1516
public static let shared = Scheduler()
@@ -68,7 +69,7 @@ public final class Scheduler: NSObject, CLLocationManagerDelegate {
6869
preferences.scheduleEnd = scheduledDate
6970
}
7071
}
71-
return task = Schedule.at(scheduledDate).do(onElapse: schedule)
72+
return task = Plan.at(scheduledDate).do(onElapse: schedule)
7273
}
7374
if preferences.scheduleZenithType != .custom {
7475
preferences.scheduleZenithType = .custom
@@ -98,7 +99,7 @@ public final class Scheduler: NSObject, CLLocationManagerDelegate {
9899
bySettingHour: end.hour!, minute: end.minute!, second: 0, of: tomorrow
99100
)
100101
}
101-
task = Schedule.at(scheduledDate).do(onElapse: schedule)
102+
task = Plan.at(scheduledDate).do(onElapse: schedule)
102103
}
103104

104105
public func cancel() {
@@ -116,7 +117,11 @@ public final class Scheduler: NSObject, CLLocationManagerDelegate {
116117
public func locationManager(_ manager: CLLocationManager,
117118
didChangeAuthorization status: CLAuthorizationStatus) {
118119
if status != .authorizedAlways {
119-
print("denied")
120+
#if DEBUG
121+
print("Denied Location Access")
122+
#else
123+
os_log(.fault, "Dynamic - Can't Access Location")
124+
#endif
120125
scheduleAtCachedLocation()
121126
}
122127
}
@@ -167,7 +172,7 @@ public enum Zenith: Int, CaseIterable {
167172
case official
168173
case civil
169174
case nautical
170-
case astronimical
175+
case astronomical
171176
case custom
172177
}
173178

@@ -182,7 +187,7 @@ extension Solar {
182187
return (civilSunrise!, civilSunset!)
183188
case .nautical:
184189
return (nauticalSunrise!, nauticalSunset!)
185-
case .astronimical:
190+
case .astronomical:
186191
return (astronomicalSunrise!, astronomicalSunset!)
187192
}
188193
}

Dynamic/View Controller/AppDelegate.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import AppKit
1010
import UserNotifications
11-
import os.log
12-
import ServiceManagement
11+
import MASShortcut
1312
#if canImport(LetsMove)
1413
import LetsMove
1514
#endif
@@ -18,8 +17,8 @@ import LetsMove
1817
class AppDelegate: NSObject, NSApplicationDelegate {
1918
private lazy var statusBarItem = NSStatusBar.system
2019
.statusItem(withLength: NSStatusItem.squareLength)
21-
private var token: NSKeyValueObservation?
22-
20+
private var settingsStyleObservation: NSKeyValueObservation?
21+
2322
func applicationDidFinishLaunching(_ aNotification: Notification) {
2423
#if canImport(LetsMove) && !DEBUG
2524
PFMoveToApplicationsFolderIfNecessary()
@@ -31,12 +30,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3130
NSUserNotificationCenter.default.delegate = Scheduler.shared
3231
}
3332

33+
// Command-Shift-T
34+
let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [.command, .shift], timestamp: 0, windowNumber: 0, context: nil, characters: "T", charactersIgnoringModifiers: "t", isARepeat: false, keyCode: UInt16(kVK_ANSI_T))
35+
let shortcut = MASShortcut(event: event)
36+
let shortcuts = [preferences.toggleShortcutKey: shortcut!]
37+
MASShortcutBinder.shared()?.registerDefaultShortcuts(shortcuts)
38+
MASShortcutBinder.shared()?.bindShortcut(
39+
withDefaultsKey: preferences.toggleShortcutKey,
40+
toAction: toggleInterfaceStyle
41+
)
42+
3443
// MARK: - Menu Bar Item Setup
3544

3645
statusBarItem.button?.image = #imageLiteral(resourceName: "status_bar_icon")
3746
statusBarItem.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])
3847
statusBarItem.button?.action = #selector(handleEvent)
39-
token = preferences.observe(\.rawSettingsStyle, options: [.initial, .new])
48+
settingsStyleObservation = preferences.observe(\.rawSettingsStyle, options: [.initial, .new])
4049
{ [weak self] _, change in
4150
guard let self = self else { return }
4251
if change.newValue == 1 {
@@ -58,15 +67,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
5867
}
5968
}
6069

61-
func buildMenu() -> NSMenu {
70+
private func buildMenu() -> NSMenu {
6271
let menu = NSMenu()
6372
let toggleItem = NSMenuItem(
6473
title: NSLocalizedString(
6574
"Menu.toggle",
6675
value: "Toggle Dark Mode",
6776
comment: "Action item to toggle in from menu bar"),
6877
action: #selector(toggleInterfaceStyle),
69-
keyEquivalent: "\u{000d}" // return
78+
keyEquivalent: ""
7079
)
7180
menu.addItem(toggleItem)
7281
menu.addItem(.separator())
@@ -126,7 +135,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
126135
}
127136

128137
func applicationWillTerminate(_ notification: Notification) {
129-
token?.invalidate()
138+
settingsStyleObservation?.invalidate()
130139
Preferences.removeObservers()
131140
Scheduler.shared.cancel()
132141
}

0 commit comments

Comments
 (0)