Skip to content

Commit

Permalink
✨ add launch at login and fix permission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyruu committed Aug 23, 2024
1 parent 389a5ad commit 6b019d8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 43 deletions.
35 changes: 31 additions & 4 deletions Tabula.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -48,6 +49,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
11C795A92C7875CA00CF3F6A /* LaunchAtLogin in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -123,6 +125,9 @@
dependencies = (
);
name = Tabula;
packageProductDependencies = (
11C795A82C7875CA00CF3F6A /* LaunchAtLogin */,
);
productName = Tabula;
productReference = 11C7956E2C7499F400CF3F6A /* Tabula.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -195,6 +200,9 @@
Base,
);
mainGroup = 11C795652C7499F400CF3F6A;
packageReferences = (
11C795A72C7875CA00CF3F6A /* XCRemoteSwiftPackageReference "LaunchAtLogin-Modern" */,
);
productRefGroup = 11C7956F2C7499F400CF3F6A /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 */;
}
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 7 additions & 11 deletions Tabula/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
59 changes: 34 additions & 25 deletions Tabula/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import AppKit
import SwiftUI
import LaunchAtLogin

struct ContentView: View {
// Define a property using @AppStorage
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tabula/Tabula.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<false/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
Expand Down
2 changes: 0 additions & 2 deletions Tabula/TabulaApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6b019d8

Please sign in to comment.