From 6e23c0572392457df7ff6395587c9f45f09cf22b Mon Sep 17 00:00:00 2001 From: Theron Tjapkes Date: Wed, 3 Feb 2021 22:46:53 -0500 Subject: [PATCH] A bunch of minor fixes and other polish --- .../project.pbxproj | 37 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 4 +- UnnaturalScrollWheels/AppDelegate.swift | 79 +++- .../{ => Base.lproj}/Main.storyboard | 38 +- UnnaturalScrollWheels/Info.plist | 2 +- UnnaturalScrollWheels/Options.swift | 10 + .../PreferencesViewController.swift | 47 +- UnnaturalScrollWheels/ScrollInterceptor.swift | 28 +- .../UnnaturalScrollWheels.entitlements | 6 +- .../en.lproj/Localizable.strings | 11 + .../en.lproj/Main.storyboard | 400 ++++++++++++++++++ 11 files changed, 601 insertions(+), 61 deletions(-) rename UnnaturalScrollWheels/{ => Base.lproj}/Main.storyboard (94%) create mode 100644 UnnaturalScrollWheels/en.lproj/Localizable.strings create mode 100644 UnnaturalScrollWheels/en.lproj/Main.storyboard diff --git a/UnnaturalScrollWheels.xcodeproj/project.pbxproj b/UnnaturalScrollWheels.xcodeproj/project.pbxproj index f8cf8bf..fbc6ac2 100644 --- a/UnnaturalScrollWheels.xcodeproj/project.pbxproj +++ b/UnnaturalScrollWheels.xcodeproj/project.pbxproj @@ -7,22 +7,25 @@ objects = { /* Begin PBXBuildFile section */ + 914D7D7825C3108C00503565 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 914D7D7A25C3108C00503565 /* Main.storyboard */; }; + 914D7D8225C32FD800503565 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 914D7D8425C32FD800503565 /* Localizable.strings */; }; 91727DB224CCBDDA00432163 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91727DB124CCBDDA00432163 /* PreferencesViewController.swift */; }; 918546AB25C0758700B2AD21 /* MenuBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 918546AA25C0758700B2AD21 /* MenuBarItem.swift */; }; 91C7ECE424CC86B6007E2D4C /* Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91C7ECE324CC86B6007E2D4C /* Options.swift */; }; 91C7ECE624CC8789007E2D4C /* ScrollInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91C7ECE524CC8789007E2D4C /* ScrollInterceptor.swift */; }; - 91C8ABFB24CCA471007E85A9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91C8ABFA24CCA471007E85A9 /* Main.storyboard */; }; 91D8069E24CB37B80092C286 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91D8069D24CB37B80092C286 /* AppDelegate.swift */; }; 91D806A024CB37BD0092C286 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 91D8069F24CB37BD0092C286 /* Assets.xcassets */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 9138880425B0CB2700A3A633 /* UnnaturalScrollWheels-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnnaturalScrollWheels-Bridging-Header.h"; sourceTree = ""; }; + 914D7D7925C3108C00503565 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/Main.storyboard; sourceTree = ""; }; + 914D7D8325C32FD800503565 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; + 914D7D8925C342A900503565 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 91727DB124CCBDDA00432163 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = ""; }; 918546AA25C0758700B2AD21 /* MenuBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarItem.swift; sourceTree = ""; }; 91C7ECE324CC86B6007E2D4C /* Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Options.swift; sourceTree = ""; }; 91C7ECE524CC8789007E2D4C /* ScrollInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollInterceptor.swift; sourceTree = ""; }; - 91C8ABFA24CCA471007E85A9 /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 91D8069A24CB37B80092C286 /* UnnaturalScrollWheels.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UnnaturalScrollWheels.app; sourceTree = BUILT_PRODUCTS_DIR; }; 91D8069D24CB37B80092C286 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 91D8069F24CB37BD0092C286 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -60,12 +63,13 @@ 91D8069C24CB37B80092C286 /* UnnaturalScrollWheels */ = { isa = PBXGroup; children = ( + 914D7D8425C32FD800503565 /* Localizable.strings */, 91D8069D24CB37B80092C286 /* AppDelegate.swift */, 91C7ECE324CC86B6007E2D4C /* Options.swift */, 91727DB124CCBDDA00432163 /* PreferencesViewController.swift */, 91C7ECE524CC8789007E2D4C /* ScrollInterceptor.swift */, 9138880425B0CB2700A3A633 /* UnnaturalScrollWheels-Bridging-Header.h */, - 91C8ABFA24CCA471007E85A9 /* Main.storyboard */, + 914D7D7A25C3108C00503565 /* Main.storyboard */, 91D8069F24CB37BD0092C286 /* Assets.xcassets */, 91D806A424CB37BD0092C286 /* Info.plist */, 91D806A524CB37BD0092C286 /* UnnaturalScrollWheels.entitlements */, @@ -134,7 +138,8 @@ buildActionMask = 2147483647; files = ( 91D806A024CB37BD0092C286 /* Assets.xcassets in Resources */, - 91C8ABFB24CCA471007E85A9 /* Main.storyboard in Resources */, + 914D7D8225C32FD800503565 /* Localizable.strings in Resources */, + 914D7D7825C3108C00503565 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -155,6 +160,26 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXVariantGroup section */ + 914D7D7A25C3108C00503565 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 914D7D7925C3108C00503565 /* en */, + 914D7D8925C342A900503565 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 914D7D8425C32FD800503565 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 914D7D8325C32FD800503565 /* en */, + ); + name = Localizable.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 91D806A624CB37BD0092C286 /* Debug */ = { isa = XCBuildConfiguration; @@ -288,7 +313,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.2.0; + MARKETING_VERSION = 1.2.1; PRODUCT_BUNDLE_IDENTIFIER = com.theron.UnnaturalScrollWheels; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "UnnaturalScrollWheels/UnnaturalScrollWheels-Bridging-Header.h"; @@ -314,7 +339,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.2.0; + MARKETING_VERSION = 1.2.1; PRODUCT_BUNDLE_IDENTIFIER = com.theron.UnnaturalScrollWheels; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "UnnaturalScrollWheels/UnnaturalScrollWheels-Bridging-Header.h"; diff --git a/UnnaturalScrollWheels.xcodeproj/xcuserdata/theron.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/UnnaturalScrollWheels.xcodeproj/xcuserdata/theron.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 88e4440..68513c9 100644 --- a/UnnaturalScrollWheels.xcodeproj/xcuserdata/theron.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/UnnaturalScrollWheels.xcodeproj/xcuserdata/theron.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,8 +14,8 @@ filePath = "UnnaturalScrollWheels/PreferencesViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "20" - endingLineNumber = "20" + startingLineNumber = "21" + endingLineNumber = "21" landmarkName = "PreferencesViewController" landmarkType = "3"> diff --git a/UnnaturalScrollWheels/AppDelegate.swift b/UnnaturalScrollWheels/AppDelegate.swift index 08ea52b..dcfafcd 100644 --- a/UnnaturalScrollWheels/AppDelegate.swift +++ b/UnnaturalScrollWheels/AppDelegate.swift @@ -8,7 +8,6 @@ import Cocoa import Foundation -import IOKit @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate { @@ -16,26 +15,69 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate { private let statusItem = MenuBarItem.shared var prefsWindow: NSWindow? @IBOutlet weak var menu: NSMenu? - //@IBOutlet weak var showMenuBarItem: NSMenuItem? @IBOutlet weak var openAtLoginItem: NSMenuItem? @IBOutlet weak var preferencesMenuItem: NSMenuItem? @IBOutlet weak var quitMenuItem: NSMenuItem? func applicationDidFinishLaunching(_ aNotification: Notification) { - Options.shared.loadOptions() + if Options.shared.firstLaunch { + UserDefaults.standard.set(false, forKey: "FirstLaunch") + } self.statusItem.menu = self.menu + refresh() + if AXIsProcessTrusted() { + ScrollInterceptor.shared.interceptScroll() + } else { + if Options.shared.firstLaunch{ + let alert = NSAlert() + alert.messageText = NSLocalizedString("PermissionsTitle", comment: "") + alert.informativeText = NSLocalizedString("PermissionsMessage", comment: "") + } else { + accessibilityAlert() + } + pollAccessibility() + ScrollInterceptor.shared.interceptScroll() + } + } + + func pollAccessibility() { + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + if AXIsProcessTrusted() { + ScrollInterceptor.shared.interceptScroll() + } else { + self.pollAccessibility() + } + } + } + + func accessibilityAlert() { + let alert = NSAlert() + alert.messageText = NSLocalizedString("PermissionsTitle", comment: "") + alert.informativeText = NSLocalizedString("PermissionsMessage", comment: "") + alert.addButton(withTitle: NSLocalizedString("OpenPreferences", comment: "")) + alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "")) + if alert.runModal() == NSApplication.ModalResponse.alertFirstButtonReturn { + NSWorkspace.shared.open(URL(string:"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!) + } + } + + func refresh() { + Options.shared.loadOptions() statusItem.refreshVisibility() - ScrollInterceptor.shared.interceptScroll() disableMouseAccel() } - + @IBAction func openAtLoginClicked(_ sender: Any) { let url = URL(string: "https://github.com/ther0n/UnnaturalScrollWheels/blob/master/RunAtLogin.md")! NSWorkspace.shared.open(url) } @IBAction func preferencesClicked(_ sender: Any) { - showPreferences() + if AXIsProcessTrusted() { + showPreferences() + } else{ + accessibilityAlert() + } } @IBAction func showAbout(_ sender: Any) { @@ -51,7 +93,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate { let controllerId = NSStoryboard.SceneIdentifier("Preferences") guard let controller = storyboard.instantiateController(withIdentifier: controllerId) as? NSWindowController else { return } guard let window = controller.window else { return } - + window.delegate = self window.center() prefsWindow = window @@ -74,12 +116,23 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate { } func disableMouseAccel() { - if Options.shared.disableMouseAccel { - // Based on https://github.com/apsun/NoMouseAccel - let accelNum: CFNumber = CFNumberCreate(kCFAllocatorDefault, CFNumberType.sInt32Type, &Options.shared.accel) - let client: IOHIDEventSystemClient = IOHIDEventSystemClientCreateSimpleClient(kCFAllocatorDefault) - let mouseAccelerationType: CFString = kIOHIDMouseAccelerationType as NSString - IOHIDEventSystemClientSetProperty(client, mouseAccelerationType, accelNum) + // Based on https://github.com/apsun/NoMouseAccel + + let client: IOHIDEventSystemClient = IOHIDEventSystemClientCreateSimpleClient(kCFAllocatorDefault) + let mouseAccelerationType: CFString = kIOHIDMouseAccelerationType as NSString + + // Get the starting acceleration value + var origAccel: Int32 = 0 + let originalAccelRef: CFTypeRef = IOHIDEventSystemClientCopyProperty(client, mouseAccelerationType)! + CFNumberGetValue((originalAccelRef as! CFNumber), CFNumberType.sInt32Type, &origAccel) + // Only save it if it's not -1 (acceleration off) + if origAccel != -1 { + Options.shared.origAccel = origAccel + UserDefaults.standard.set(origAccel, forKey: "OriginalAccel") } + // Set the mouse acceleration + let accelNum: CFNumber = CFNumberCreate(kCFAllocatorDefault, CFNumberType.sInt32Type, &Options.shared.accel) + IOHIDEventSystemClientSetProperty(client, mouseAccelerationType, accelNum) } } + diff --git a/UnnaturalScrollWheels/Main.storyboard b/UnnaturalScrollWheels/Base.lproj/Main.storyboard similarity index 94% rename from UnnaturalScrollWheels/Main.storyboard rename to UnnaturalScrollWheels/Base.lproj/Main.storyboard index efad0f0..e572716 100644 --- a/UnnaturalScrollWheels/Main.storyboard +++ b/UnnaturalScrollWheels/Base.lproj/Main.storyboard @@ -104,6 +104,9 @@ + + + @@ -130,6 +136,9 @@ + + + @@ -198,6 +207,9 @@ + + + @@ -219,10 +231,13 @@ + + + - + @@ -238,7 +253,7 @@ - + @@ -260,9 +275,6 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +