Skip to content

Commit

Permalink
Address app review comments + make app more better (#9)
Browse files Browse the repository at this point in the history
* Add Main Window button to Window menu item

* Add make clean

* More accurately decide if we should open the settings window

* Bump build number to 6

* Exclude main window from Window menu so it can be manually added

This is being done to comply with an App Review requirement

* Bump build number to 7

* Bump version to 1.1.1 and build number to 9
  • Loading branch information
hisaac authored Apr 29, 2023
1 parent 6480ee9 commit 2fcabfd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
8 changes: 4 additions & 4 deletions CenterMouse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 9;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = F2J52QJQ9Y;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -403,7 +403,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = software.level.CenterMouse;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -419,7 +419,7 @@
CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 9;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = F2J52QJQ9Y;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -432,7 +432,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = software.level.CenterMouse;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
13 changes: 10 additions & 3 deletions CenterMouse/Resources/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -329,13 +329,20 @@
<action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
<menuItem isSeparatorItem="YES" id="tCf-wr-CME"/>
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
<menuItem title="CenterMouse" id="nKL-96-cSG">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="windowMenuMainWindowItemActivated:" target="Voe-Tx-rLC" id="IpI-CD-UCE"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
Expand Down
44 changes: 19 additions & 25 deletions CenterMouse/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

private var eventMonitor = EventMonitor()

/// Whether or not the app is relaunching after it has been launched and quit before
///
/// We track this to know whether or not to open the Settings window. If this is a
/// fresh relaunch, we _don't_ want to open the Settings window right away.
private var isRelaunch = false

func applicationWillFinishLaunching(_ notification: Notification) {
if Defaults[.firstTimeAppLaunched] {
Defaults[.firstTimeAppLaunched] = false
} else {
isRelaunch = true
}
}

func applicationDidFinishLaunching(_ notification: Notification) {
window = NSWindow(
contentRect: NSZeroRect,
Expand All @@ -33,12 +19,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
)

window.title = "CenterMouse"

// Excluding this from the Window menu so that it can be manually added.
// This is being done to comply with an App Review requirement.
window.isExcludedFromWindowsMenu = true

window.contentView = NSHostingView(rootView: SettingsView())
windowController = NSWindowController(window: window)

if launchedAsLogInItem == false {
openSettingsWindow()
}
}

func applicationDidBecomeActive(_ notification: Notification) {
openSettingsWindow()
private var launchedAsLogInItem: Bool {
// source: https://stackoverflow.com/a/19890943/4118208
guard let event = NSAppleEventManager.shared().currentAppleEvent else { return false }
return
event.eventID == kAEOpenApplication &&
event.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
Expand All @@ -50,6 +49,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
openSettingsWindow()
}

@IBAction func windowMenuMainWindowItemActivated(_ sender: NSMenuItem) {
openSettingsWindow()
}

func openSettingsWindow() {
// Works around an annoyance where the app always comes to the foreground when
// being previewed in Xcode's SwiftUI Canvas.
Expand All @@ -59,15 +62,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
return
}

// We only need to check whether this is a relaunch the first time this method
// is called (by `applicationDidBecomeActive(_:)`). After that, we'll want to
// open the Settings window whenever this method is called, so we set the value
// to `false`.
guard isRelaunch == false else {
isRelaunch = false
return
}

windowController.window?.center()
windowController.showWindow(self)
NSApp.activate(ignoringOtherApps: true)
Expand Down
1 change: 0 additions & 1 deletion CenterMouse/Sources/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Defaults
extension Defaults.Keys {
static let hideDockIcon = Key<Bool>("hideDockIcon", default: false)
static let monitorSystemEvents = Key<Bool>("monitorSystemEvents", default: true)
static let firstTimeAppLaunched = Key<Bool>("firstTimeAppLaunched", default: true)
}

enum Settings {
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ build:
@echo "Building project..."
@$(scripts_dir)build.sh
.PHONY: build

clean:
rm -rf $(project_dir)DerivedData
.PHONY: clean

0 comments on commit 2fcabfd

Please sign in to comment.