Skip to content

Commit

Permalink
Restored the app sandbox.
Browse files Browse the repository at this point in the history
Removed redundant files.
  • Loading branch information
Guy Kaplan committed Nov 1, 2020
1 parent 364c287 commit 57cf072
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 40 deletions.
8 changes: 4 additions & 4 deletions CapsLockNoDelay.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
E1927176254D7F2D00070EA7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1927175254D7F2D00070EA7 /* AppDelegate.swift */; };
E1927178254D7F2D00070EA7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1927177254D7F2D00070EA7 /* ViewController.swift */; };
E192717A254D7F2E00070EA7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E1927179254D7F2E00070EA7 /* Assets.xcassets */; };
E1927191254D8B2400070EA7 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1927190254D8B2400070EA7 /* main.swift */; };
E1927197254D91F100070EA7 /* CapsLockManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1927196254D91F100070EA7 /* CapsLockManager.swift */; };
Expand All @@ -17,7 +16,6 @@
/* Begin PBXFileReference section */
E1927172254D7F2D00070EA7 /* CapsLockNoDelay.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CapsLockNoDelay.app; sourceTree = BUILT_PRODUCTS_DIR; };
E1927175254D7F2D00070EA7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
E1927177254D7F2D00070EA7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
E1927179254D7F2E00070EA7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
E192717E254D7F2E00070EA7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E192717F254D7F2E00070EA7 /* CapsLockNoDelay.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CapsLockNoDelay.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -57,7 +55,6 @@
children = (
E1927196254D91F100070EA7 /* CapsLockManager.swift */,
E1927175254D7F2D00070EA7 /* AppDelegate.swift */,
E1927177254D7F2D00070EA7 /* ViewController.swift */,
E1927179254D7F2E00070EA7 /* Assets.xcassets */,
E192717E254D7F2E00070EA7 /* Info.plist */,
E192717F254D7F2E00070EA7 /* CapsLockNoDelay.entitlements */,
Expand Down Expand Up @@ -134,7 +131,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E1927178254D7F2D00070EA7 /* ViewController.swift in Sources */,
E1927176254D7F2D00070EA7 /* AppDelegate.swift in Sources */,
E1927191254D8B2400070EA7 /* main.swift in Sources */,
E1927197254D91F100070EA7 /* CapsLockManager.swift in Sources */,
Expand Down Expand Up @@ -268,13 +264,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = X822FM39JE;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = CapsLockNoDelay/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = gkpln3.CapsLockNoDelay;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -290,13 +288,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = X822FM39JE;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = CapsLockNoDelay/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = gkpln3.CapsLockNoDelay;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
10 changes: 3 additions & 7 deletions CapsLockNoDelay/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let capsLockManager = CapsLockManager()

func applicationDidFinishLaunching(_ aNotification: Notification) {
if SMLoginItemSetEnabled(Bundle.main.bundleIdentifier! as CFString, true) {
print("Successfully added login item.")
} else {
print("Failed to add login item.")
}

// Request accessability permissions.
if (!capsLockManager.requestAccess()) {
exit(1)
}


// Start listening for events.
self.capsLockManager.registerEventListener()
}

Expand Down
8 changes: 5 additions & 3 deletions CapsLockNoDelay/CapsLockManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cocoa
class CapsLockManager {
var currentState = false

/// Requests accessability permissions to enable capturing of keyboard events.
func requestAccess() -> Bool {
let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String : true]
let accessEnabled = AXIsProcessTrustedWithOptions(options)
Expand All @@ -21,7 +22,8 @@ class CapsLockManager {
}
return true
}


/// Register an event listener and listen for caps-lock presses.
func registerEventListener() {
currentState = self.getCapsLockState()

Expand All @@ -36,14 +38,14 @@ class CapsLockManager {
print("Got state \(self.currentState)")
}
else {
self.toggleCapsLock(!self.currentState)
self.setCapsLockState(!self.currentState)
print("setting state \(!self.currentState)")
}
}
}
}

func toggleCapsLock(_ state: Bool) {
func setCapsLockState(_ state: Bool) {
var ioConnect: io_connect_t = .init(0)
let ioService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass))
IOServiceOpen(ioService, mach_task_self_, UInt32(kIOHIDParamConnectType), &ioConnect)
Expand Down
2 changes: 1 addition & 1 deletion CapsLockNoDelay/CapsLockNoDelay.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>
<false/>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
Expand Down
6 changes: 4 additions & 2 deletions CapsLockNoDelay/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSBackgroundOnly</key>
<true/>
<key>LSMinimumSystemVersion</key>
Expand Down
23 changes: 0 additions & 23 deletions CapsLockNoDelay/ViewController.swift

This file was deleted.

1 change: 1 addition & 0 deletions CapsLockNoDelay/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Cocoa

// Create an app delegate without GUI.
let delegate = AppDelegate()
NSApplication.shared.delegate = delegate
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
Expand Down

0 comments on commit 57cf072

Please sign in to comment.