Skip to content

Commit

Permalink
fix: initial support for macOS 10.14
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Jun 6, 2018
1 parent 9f304e3 commit 41852ff
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 74 deletions.
33 changes: 16 additions & 17 deletions Apptivator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
151CF3AF20876CDE00D6DC91 /* MASShortcut.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 151CF3A820876C7800D6DC91 /* MASShortcut.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
151CF3B120876CE200D6DC91 /* LaunchAtLogin.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 151CF3A620876C6900D6DC91 /* LaunchAtLogin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
151CF3B320876CE500D6DC91 /* AXSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 151CF3A420876C5600D6DC91 /* AXSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
152416AB20C73D0E00A5D7D2 /* APPopoverViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B3B4C2C41E25894B009F8E4E /* APPopoverViewController.xib */; };
152416AC20C73D1300A5D7D2 /* APSequenceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 159ED108207E379D005489ED /* APSequenceViewController.xib */; };
1537F5E1204C8D860056EE50 /* APAppEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1537F5E0204C8D860056EE50 /* APAppEntry.swift */; };
1547AC99208738310088701F /* CleanroomLogger.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1547AC972087382D0088701F /* CleanroomLogger.framework */; };
1547AC9A208738310088701F /* CleanroomLogger.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1547AC972087382D0088701F /* CleanroomLogger.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand All @@ -22,7 +24,6 @@
1561AED2207615AC00C69338 /* UIOverrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1561AED1207615AC00C69338 /* UIOverrides.swift */; };
15673D7020B6140F00542276 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 15673D6F20B6140E00542276 /* README.md */; };
159ED109207E379D005489ED /* APSequenceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159ED107207E379D005489ED /* APSequenceViewController.swift */; };
159ED10A207E379D005489ED /* SequenceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 159ED108207E379D005489ED /* SequenceViewController.xib */; };
159F304C2079A0E5000BD387 /* APAppEntryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159F304B2079A0E5000BD387 /* APAppEntryTests.swift */; };
159F304E2079A111000BD387 /* AppDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159F304D2079A111000BD387 /* AppDelegateTests.swift */; };
159F30502079A12D000BD387 /* PopoverViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159F304F2079A12D000BD387 /* PopoverViewControllerTests.swift */; };
Expand All @@ -32,7 +33,6 @@
15FC8CC8204E2E2C000B5E1E /* APState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15FC8CC7204E2E2C000B5E1E /* APState.swift */; };
B3B4C2C11E25894B009F8E4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B4C2C01E25894B009F8E4E /* AppDelegate.swift */; };
B3B4C2C31E25894B009F8E4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B3B4C2C21E25894B009F8E4E /* Assets.xcassets */; };
B3B4C2C61E25894B009F8E4E /* PreferencesPopover.xib in Resources */ = {isa = PBXBuildFile; fileRef = B3B4C2C41E25894B009F8E4E /* PreferencesPopover.xib */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -75,7 +75,7 @@
1561AED1207615AC00C69338 /* UIOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIOverrides.swift; sourceTree = "<group>"; };
15673D6F20B6140E00542276 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; };
159ED107207E379D005489ED /* APSequenceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APSequenceViewController.swift; sourceTree = "<group>"; };
159ED108207E379D005489ED /* SequenceViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SequenceViewController.xib; sourceTree = "<group>"; };
159ED108207E379D005489ED /* APSequenceViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = APSequenceViewController.xib; sourceTree = "<group>"; };
159F304B2079A0E5000BD387 /* APAppEntryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APAppEntryTests.swift; sourceTree = "<group>"; };
159F304D2079A111000BD387 /* AppDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegateTests.swift; sourceTree = "<group>"; };
159F304F2079A12D000BD387 /* PopoverViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopoverViewControllerTests.swift; sourceTree = "<group>"; };
Expand All @@ -89,7 +89,7 @@
B3B4C2BD1E25894B009F8E4E /* Apptivator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Apptivator.app; sourceTree = BUILT_PRODUCTS_DIR; };
B3B4C2C01E25894B009F8E4E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
B3B4C2C21E25894B009F8E4E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
B3B4C2C51E25894B009F8E4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PreferencesPopover.xib; sourceTree = "<group>"; };
B3B4C2C51E25894B009F8E4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/APPopoverViewController.xib; sourceTree = "<group>"; };
B3B4C2C71E25894B009F8E4E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -131,8 +131,8 @@
isa = PBXGroup;
children = (
B3B4C2C21E25894B009F8E4E /* Assets.xcassets */,
B3B4C2C41E25894B009F8E4E /* PreferencesPopover.xib */,
159ED108207E379D005489ED /* SequenceViewController.xib */,
B3B4C2C41E25894B009F8E4E /* APPopoverViewController.xib */,
159ED108207E379D005489ED /* APSequenceViewController.xib */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -248,13 +248,14 @@
TargetAttributes = {
15B4E86F207994AF0024FDE4 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
TestTargetID = B3B4C2BC1E25894B009F8E4E;
};
B3B4C2BC1E25894B009F8E4E = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = UNR5C68RPX;
LastSwiftMigration = 0920;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -293,8 +294,8 @@
B3B4C2C31E25894B009F8E4E /* Assets.xcassets in Resources */,
155D2C03204F61220087478B /* Credits.rtfd in Resources */,
15673D7020B6140F00542276 /* README.md in Resources */,
B3B4C2C61E25894B009F8E4E /* PreferencesPopover.xib in Resources */,
159ED10A207E379D005489ED /* SequenceViewController.xib in Resources */,
152416AB20C73D0E00A5D7D2 /* APPopoverViewController.xib in Resources */,
152416AC20C73D1300A5D7D2 /* APSequenceViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -354,12 +355,12 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
B3B4C2C41E25894B009F8E4E /* PreferencesPopover.xib */ = {
B3B4C2C41E25894B009F8E4E /* APPopoverViewController.xib */ = {
isa = PBXVariantGroup;
children = (
B3B4C2C51E25894B009F8E4E /* Base */,
);
name = PreferencesPopover.xib;
name = APPopoverViewController.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
Expand Down Expand Up @@ -388,7 +389,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.acheronfail.ApptivatorTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Apptivator.app/Contents/MacOS/Apptivator";
};
name = Debug;
Expand Down Expand Up @@ -416,7 +417,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.acheronfail.ApptivatorTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Apptivator.app/Contents/MacOS/Apptivator";
};
name = Release;
Expand Down Expand Up @@ -552,8 +553,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Apptivator/Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -576,8 +576,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Apptivator/Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
31 changes: 20 additions & 11 deletions Apptivator/APState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import CleanroomLogger
let defaults: UserDefaults = UserDefaults.standard
// A Timer to handle the delay between keypresses in a sequence. When this runs out, then the
// sequence cancels and the user will have to start the sequence from the beginning.
var timer: Timer?
var sequenceTimer: Timer?

// Toggle for dark mode.
var darkModeEnabled = appleInterfaceStyleIsDark()
// On macOS 10.14 and later this isn't used since macOS has a global dark mode.
var darkModeEnabled = mojaveDarkModeSupported() ? false : appleInterfaceStyleIsDark()
// Whether or not the app should launch after login.
private var launchAppAtLogin = LaunchAtLogin.isEnabled
// Don't fire any shortcuts if user is recording a new shortcut.
Expand Down Expand Up @@ -164,8 +165,8 @@ import CleanroomLogger
// if no other shortcuts were hit.
if index > 0 {
let interval = TimeInterval(defaults.float(forKey: "sequentialShortcutDelay"))
timer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { _ in
self.timer = nil
sequenceTimer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { _ in
self.sequenceTimer = nil
self.registerShortcuts(atIndex: 0, last: nil)
Log.debug?.message("Resetting shortcut state.")
}
Expand All @@ -176,7 +177,7 @@ import CleanroomLogger
// will activate the app, otherwise it will just advance the sequence along.
private func keyFired(_ i: Int, _ entry: APAppEntry, _ shortcut: MASShortcut) {
if currentlyRecording { return }
if i > 0 { timer?.invalidate() }
if i > 0 { sequenceTimer?.invalidate() }

// Last shortcut in sequence: apptivate and reset shortcut state.
if i == entry.sequence.count {
Expand Down Expand Up @@ -216,8 +217,10 @@ import CleanroomLogger
// Reset the state before loading from disk.
_currentlyRecording = false
_isEnabled = true
timer = nil
darkModeEnabled = appleInterfaceStyleIsDark()
sequenceTimer = nil

// Default to the current interface style on macOS versions below 10.14.
if !mojaveDarkModeSupported() { darkModeEnabled = appleInterfaceStyleIsDark() }

// Unregister shortcuts and remove all entries.
unregisterShortcuts()
Expand All @@ -242,8 +245,9 @@ import CleanroomLogger
let json = try JSON(data: dataFromString)
for (key, value):(String, JSON) in json {
switch key {
// Only care about dark mode on macOS versions below 10.14.
case "darkModeEnabled":
darkModeEnabled = value.bool ?? false
if !mojaveDarkModeSupported() { darkModeEnabled = value.bool ?? false }
case "appIsEnabled":
_isEnabled = value.bool ?? true
case "entries":
Expand All @@ -253,7 +257,7 @@ import CleanroomLogger
}
}

if APState.shared.defaults.bool(forKey: "matchAppleInterfaceStyle") {
if !mojaveDarkModeSupported() && APState.shared.defaults.bool(forKey: "matchAppleInterfaceStyle") {
darkModeEnabled = appleInterfaceStyleIsDark()
}

Expand All @@ -263,11 +267,16 @@ import CleanroomLogger

// Saves the app state to disk, creating the parent directories if they don't already exist.
func saveToDisk() {
let json: JSON = [
var json: JSON = [
"appIsEnabled": _isEnabled,
"darkModeEnabled": darkModeEnabled,
"entries": APAppEntry.serialiseList(entries: getEntries())
]

// Only bother saving whether dark mode is enabled or not on macOS versions below 10.14.
if !mojaveDarkModeSupported() {
json["darkModeEnabled"].boolValue = darkModeEnabled
}

do {
if let jsonString = json.rawString() {
let configDir = savePath.deletingLastPathComponent()
Expand Down
4 changes: 2 additions & 2 deletions Apptivator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import CleanroomLogger

let ENABLED_INDICATOR_ON = "\(APP_NAME): on"
let ENABLED_INDICATOR_OFF = "\(APP_NAME): off"
let ICON_ON = setupMenuBarIcon(NSImage(named: NSImage.Name(rawValue: "icon-on")))
let ICON_OFF = setupMenuBarIcon(NSImage(named: NSImage.Name(rawValue: "icon-off")))
let ICON_ON = setupMenuBarIcon(NSImage(named: NSImage.Name(stringLiteral: "icon-on")))
let ICON_OFF = setupMenuBarIcon(NSImage(named: NSImage.Name(stringLiteral: "icon-off")))

@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var popover: NSPopover!
Expand Down
2 changes: 1 addition & 1 deletion Apptivator/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 acheronfail</string>
<key>NSMainNibFile</key>
<string>PreferencesPopover</string>
<string>APPopoverViewController</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14269.12" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14109"/>
<capability name="box content view" minToolsVersion="7.0"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14269.12"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -29,7 +29,7 @@
<rect key="frame" x="307" y="0.0" width="143" height="153"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="4d0-dn-f8B">
<rect key="frame" x="0.0" y="0.0" width="143" height="153"/>
<autoresizingMask key="autoresizingMask"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="19" rowSizeStyle="automatic" viewBased="YES" id="Gmb-EW-g1t">
<rect key="frame" x="0.0" y="0.0" width="143" height="153"/>
Expand All @@ -38,7 +38,7 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="" width="140" minWidth="40" maxWidth="1000" id="bNa-qO-wnv">
<tableColumn width="140" minWidth="40" maxWidth="1000" id="bNa-qO-wnv">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="center" title="Shortcut Sequence">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -60,16 +60,17 @@
</tableColumns>
</tableView>
</subviews>
<nil key="backgroundColor"/>
</clipView>
<constraints>
<constraint firstAttribute="width" constant="143" id="bgq-e2-3tv"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="141" id="v6V-Jd-of2"/>
</constraints>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="4rd-lI-n1Z">
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="4rd-lI-n1Z">
<rect key="frame" x="1" y="253" width="139" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="ccB-Ce-q1h">
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="ccB-Ce-q1h">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down Expand Up @@ -117,7 +118,6 @@
</constraints>
</view>
<color key="borderColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="fillColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</box>
<box fixedFrame="YES" boxType="custom" borderType="none" borderWidth="0.0" title="Shortcut Sequence Header" translatesAutoresizingMaskIntoConstraints="NO" id="SjM-wM-ivp">
<rect key="frame" x="307" y="154" width="143" height="24"/>
Expand All @@ -138,7 +138,6 @@
</subviews>
</view>
<color key="borderColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="fillColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</box>
<box horizontalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="2Cl-wK-awa">
<rect key="frame" x="305" y="159" width="5" height="14"/>
Expand Down Expand Up @@ -184,7 +183,7 @@
</constraints>
</view>
<color key="borderColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<color key="fillColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="fillColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
<point key="canvasLocation" x="228" y="270.5"/>
</box>
</objects>
Expand Down

0 comments on commit 41852ff

Please sign in to comment.