From 6b019d82da65d6f4486c06779e3e326368c347bb Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 23 Aug 2024 11:40:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20launch=20at=20login=20and=20f?= =?UTF-8?q?ix=20permission=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tabula.xcodeproj/project.pbxproj | 35 +++++++++-- .../xcshareddata/swiftpm/Package.resolved | 15 +++++ Tabula/AppDelegate.swift | 18 +++--- Tabula/ContentView.swift | 59 +++++++++++-------- Tabula/Tabula.entitlements | 2 +- Tabula/TabulaApp.swift | 2 - 6 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 Tabula.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/Tabula.xcodeproj/project.pbxproj b/Tabula.xcodeproj/project.pbxproj index e8f1165..c835f7c 100644 --- a/Tabula.xcodeproj/project.pbxproj +++ b/Tabula.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 11C7957B2C7499F500CF3F6A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 11C7957A2C7499F500CF3F6A /* Preview Assets.xcassets */; }; 11C795A32C7611C100CF3F6A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C795A22C7611C100CF3F6A /* ContentView.swift */; }; 11C795A52C7620A100CF3F6A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C795A42C7620A100CF3F6A /* AppDelegate.swift */; }; + 11C795A92C7875CA00CF3F6A /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 11C795A82C7875CA00CF3F6A /* LaunchAtLogin */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -48,6 +49,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 11C795A92C7875CA00CF3F6A /* LaunchAtLogin in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -123,6 +125,9 @@ dependencies = ( ); name = Tabula; + packageProductDependencies = ( + 11C795A82C7875CA00CF3F6A /* LaunchAtLogin */, + ); productName = Tabula; productReference = 11C7956E2C7499F400CF3F6A /* Tabula.app */; productType = "com.apple.product-type.application"; @@ -195,6 +200,9 @@ Base, ); mainGroup = 11C795652C7499F400CF3F6A; + packageReferences = ( + 11C795A72C7875CA00CF3F6A /* XCRemoteSwiftPackageReference "LaunchAtLogin-Modern" */, + ); productRefGroup = 11C7956F2C7499F400CF3F6A /* Products */; projectDirPath = ""; projectRoot = ""; @@ -404,7 +412,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1.1.0; + CURRENT_PROJECT_VERSION = 1.2.0; DEVELOPMENT_ASSET_PATHS = "\"Tabula/Preview Content\""; DEVELOPMENT_TEAM = 3S6Q428WC7; ENABLE_HARDENED_RUNTIME = YES; @@ -417,7 +425,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.2.0; PRODUCT_BUNDLE_IDENTIFIER = de.keyruu.Tabula; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -434,7 +442,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1.1.0; + CURRENT_PROJECT_VERSION = 1.2.0; DEVELOPMENT_ASSET_PATHS = "\"Tabula/Preview Content\""; DEVELOPMENT_TEAM = 3S6Q428WC7; ENABLE_HARDENED_RUNTIME = YES; @@ -447,7 +455,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.2.0; PRODUCT_BUNDLE_IDENTIFIER = de.keyruu.Tabula; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -563,6 +571,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 11C795A72C7875CA00CF3F6A /* XCRemoteSwiftPackageReference "LaunchAtLogin-Modern" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sindresorhus/LaunchAtLogin-Modern"; + requirement = { + branch = main; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 11C795A82C7875CA00CF3F6A /* LaunchAtLogin */ = { + isa = XCSwiftPackageProductDependency; + package = 11C795A72C7875CA00CF3F6A /* XCRemoteSwiftPackageReference "LaunchAtLogin-Modern" */; + productName = LaunchAtLogin; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 11C795662C7499F400CF3F6A /* Project object */; } diff --git a/Tabula.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Tabula.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..827d44a --- /dev/null +++ b/Tabula.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,15 @@ +{ + "originHash" : "aae61040c30e63b9cf0f5455365680cfeabef0aac829c0941d4d6f6180010fc9", + "pins" : [ + { + "identity" : "launchatlogin-modern", + "kind" : "remoteSourceControl", + "location" : "https://github.com/sindresorhus/LaunchAtLogin-Modern", + "state" : { + "branch" : "main", + "revision" : "a04ec1c363be3627734f6dad757d82f5d4fa8fcc" + } + } + ], + "version" : 3 +} diff --git a/Tabula/AppDelegate.swift b/Tabula/AppDelegate.swift index 9c5dcd9..9ee6d06 100644 --- a/Tabula/AppDelegate.swift +++ b/Tabula/AppDelegate.swift @@ -13,18 +13,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { private var flagsMonitor: Any? func applicationDidFinishLaunching(_ notification: Notification) { - let key: String = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String - let options = [key: true] - let enabled = AXIsProcessTrustedWithOptions(options as CFDictionary) + let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] + let enabled = AXIsProcessTrustedWithOptions(options) if !enabled { - let alert = NSAlert() - alert.messageText = "Accessibility Permission is not granted" - alert.informativeText = "For this app to work it needs to have accessibility permission granted in Security & Privacy. You need to start the app again after you allowed the permission." - alert.addButton(withTitle: "OK") - alert.alertStyle = .warning - alert.runModal() - NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!) - NSApp.terminate(nil) + CGEvent(scrollWheelEvent2Source: nil, units: .pixel, wheelCount: 2, wheel1: 0, wheel2: 0, wheel3: 0)?.post(tap: CGEventTapLocation.cghidEventTap) + UserDefaults.standard.setValue(true, forKey: "needsPermission") + return + } else { + UserDefaults.standard.setValue(false, forKey: "needsPermission") } var mouseMonitor: Any? diff --git a/Tabula/ContentView.swift b/Tabula/ContentView.swift index b03fd99..cb94801 100644 --- a/Tabula/ContentView.swift +++ b/Tabula/ContentView.swift @@ -7,6 +7,7 @@ import AppKit import SwiftUI +import LaunchAtLogin struct ContentView: View { // Define a property using @AppStorage @@ -15,35 +16,43 @@ struct ContentView: View { @AppStorage("naturalScrolling") private var naturalScrolling = true @AppStorage("xEnabled") private var xEnabled = true @AppStorage("yEnabled") private var yEnabled = true + @AppStorage("needsPermission") private var needsPermission = false var body: some View { VStack { - Form { - Picker("Modifier:", selection: $modifier) { - Text("Option \(Image(systemName: "option"))").tag("option") - Text("Control \(Image(systemName: "control"))").tag("control") - Text("Command \(Image(systemName: "command"))").tag("command") - Text("Shift \(Image(systemName: "shift"))").tag("shift") - Text("Function \(Image(systemName: "globe"))").tag("function") - } - LabeledContent("Scroll Direction:") { - Toggle("Natural Scrolling", isOn: $naturalScrolling) - } - HStack { - Toggle("X", isOn: $xEnabled) - Toggle("Y", isOn: $yEnabled) - } - VStack { - Slider(value: $scrollSpeed, in: 5...200, step: 5) { - Text("Scroll Speed:") - } minimumValueLabel: { - Text("5") - } maximumValueLabel: { - Text("200") + if needsPermission { + Text("This app needs accessbility access! Please restart the app after you've given the permission.") + } else { + Form { + LabeledContent("General:") { + LaunchAtLogin.Toggle() } - } - Text("\(scrollSpeed, specifier: "%.0f")") - }.multilineTextAlignment(.leading) + Picker("Modifier:", selection: $modifier) { + Text("Option \(Image(systemName: "option"))").tag("option") + Text("Control \(Image(systemName: "control"))").tag("control") + Text("Command \(Image(systemName: "command"))").tag("command") + Text("Shift \(Image(systemName: "shift"))").tag("shift") + Text("Function \(Image(systemName: "globe"))").tag("function") + } + LabeledContent("Scroll Direction:") { + Toggle("Natural Scrolling", isOn: $naturalScrolling) + } + HStack { + Toggle("X", isOn: $xEnabled) + Toggle("Y", isOn: $yEnabled) + } + VStack { + Slider(value: $scrollSpeed, in: 5...200, step: 5) { + Text("Scroll Speed:") + } minimumValueLabel: { + Text("5") + } maximumValueLabel: { + Text("200") + } + } + Text("\(scrollSpeed, specifier: "%.0f")") + }.multilineTextAlignment(.leading) + } Divider() Button("Quit", action: { NSApplication.shared.terminate(nil) }) }.padding(10) diff --git a/Tabula/Tabula.entitlements b/Tabula/Tabula.entitlements index 18aff0c..311b32b 100644 --- a/Tabula/Tabula.entitlements +++ b/Tabula/Tabula.entitlements @@ -3,7 +3,7 @@ com.apple.security.app-sandbox - + com.apple.security.files.user-selected.read-only diff --git a/Tabula/TabulaApp.swift b/Tabula/TabulaApp.swift index 81c7631..2d7ec47 100644 --- a/Tabula/TabulaApp.swift +++ b/Tabula/TabulaApp.swift @@ -9,8 +9,6 @@ import SwiftUI @main struct TabulaApp: App { - @AppStorage("accessibilityDenied") private var accessiblity = false - @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene {