-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c5f1d0
commit 4d3b2b4
Showing
37 changed files
with
3,200 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
KeyPopper.xcodeproj/project.xcworkspace/xcuserdata | ||
KeyPopper.xcodeproj/project.xcworkspace/xcuserdata | ||
/KeyPopper Installer/build | ||
KeyPopper.xcodeproj/xcuserdata/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>sh.linus.keypopper.KettleCornSerivce</string> | ||
<key>Program</key> | ||
<string>/Library/PreferencePanes/KeyPopper\ PrefPane.prefPane/Contents/XPCServices/KettleCornService</string> | ||
<key>MachServices</key> | ||
<dict> | ||
<key>sh.linus.keypopper.KettleCornService.mach</key> | ||
<true/> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.automation.apple-events</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// KettleCornService.swift | ||
// KettleCornService | ||
// | ||
// Created by Linus Skucas on 8/3/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SoundState { | ||
private let userDefaults = UserDefaults.init(suiteName: "sh.linus.keypopper")! | ||
|
||
var sound: PoppingSounds { | ||
get { | ||
let soundInt = userDefaults.integer(forKey: "sound") | ||
let sound = PoppingSounds(rawValue: soundInt)! | ||
return sound | ||
} | ||
set { | ||
userDefaults.set(newValue.rawValue, forKey: "sound") | ||
} | ||
} | ||
var enabled: Bool { | ||
get { | ||
let enabled = userDefaults.bool(forKey: "enabled") | ||
return enabled | ||
} | ||
set { | ||
userDefaults.set(newValue, forKey: "enabled") | ||
} | ||
} | ||
static var shared: SoundState = SoundState() | ||
} | ||
|
||
@objc class KettleCornService: NSObject, KettleCornServiceProtocol { | ||
// func hello(_ text: String, withReply reply: @escaping (String) -> Void) { | ||
// reply("Hello, \(text)!") | ||
// } | ||
|
||
var connection: NSXPCConnection! | ||
var service: PoppingServiceProtocol! | ||
|
||
override init() { | ||
super.init() | ||
connection = NSXPCConnection(machServiceName: "sh.linus.keypopper.PoppingService.mach") | ||
connection.remoteObjectInterface = NSXPCInterface(with: PoppingServiceProtocol.self) | ||
connection.resume() | ||
|
||
service = connection.remoteObjectProxyWithErrorHandler { error in | ||
fatalError("Error: \(error.localizedDescription)") | ||
} as! PoppingServiceProtocol | ||
} | ||
|
||
func changeSoundTo(_ soundInt: Int) { | ||
let sound = PoppingSounds(rawValue: soundInt)! | ||
// Store sound | ||
NSLog("Change sound") | ||
SoundState.shared.sound = sound | ||
} | ||
|
||
func changeSoundState(shouldPlaySound: Bool) { | ||
NSLog("Change state") | ||
SoundState.shared.enabled = shouldPlaySound | ||
} | ||
|
||
func boop() { | ||
guard SoundState.shared.enabled else { return } | ||
|
||
switch SoundState.shared.sound { | ||
case .pop: | ||
service.pop() | ||
NSLog("POP") | ||
case .frog: | ||
service.frog() | ||
NSLog("Frog") | ||
case .moo: | ||
service.moo() | ||
NSLog("Moo") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// KettleCornServiceDelegate.swift | ||
// KettleCornService | ||
// | ||
// Created by Linus Skucas on 8/3/21. | ||
// | ||
|
||
import Foundation | ||
|
||
class KettleCornServiceDelegate: NSObject, NSXPCListenerDelegate { | ||
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool { | ||
let exportedObject = KettleCornService() | ||
newConnection.exportedInterface = NSXPCInterface(with: KettleCornServiceProtocol.self) | ||
newConnection.exportedObject = exportedObject | ||
|
||
newConnection.resume() | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// KettleCornServiceProtocol.swift | ||
// KettleCornService | ||
// | ||
// Created by Linus Skucas on 8/3/21. | ||
// | ||
|
||
import Foundation | ||
|
||
@objc(KettleCornServiceProtocol) protocol KettleCornServiceProtocol { | ||
// func hello(_ text: String, withReply reply: @escaping (String) -> Void) | ||
func changeSoundTo(_ soundInt: Int) | ||
func changeSoundState(shouldPlaySound: Bool) | ||
func boop() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// main.swift | ||
// KettleCornService | ||
// | ||
// Created by Linus Skucas on 8/3/21. | ||
// | ||
|
||
import Foundation | ||
|
||
let delegate = KettleCornServiceDelegate() | ||
let listener = NSXPCListener(machServiceName: "sh.linus.keypopper.KettleCornService.mach") | ||
listener.delegate = delegate | ||
listener.resume() | ||
RunLoop.main.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// AppDelegate.swift | ||
// KeyPopper Catcher | ||
// | ||
// Created by Linus Skucas on 8/13/21. | ||
// | ||
|
||
import Cocoa | ||
|
||
@main | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
// var connection: NSXPCConnection! | ||
// var service: KettleCornServiceProtocol! | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
// Insert code here to initialize your application | ||
|
||
// connection = NSXPCConnection(machServiceName: "sh.linus.keypopper.KettleCornService.mach") | ||
// connection.remoteObjectInterface = NSXPCInterface(with: KettleCornServiceProtocol.self) | ||
// connection.resume() | ||
// | ||
// service = connection.remoteObjectProxyWithErrorHandler { error in | ||
// fatalError("Error: \(error.localizedDescription)") | ||
// } as! KettleCornServiceProtocol | ||
|
||
let eventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue) | ||
NSLog("gggp") | ||
func cgEventCallback(proxy: CGEventTapProxy, type: CGEventType, event: CGEvent, refcon: UnsafeMutableRawPointer?) -> Unmanaged<CGEvent>? { | ||
let connection = NSXPCConnection(machServiceName: "sh.linus.keypopper.KettleCornService.mach") | ||
connection.remoteObjectInterface = NSXPCInterface(with: KettleCornServiceProtocol.self) | ||
connection.resume() | ||
|
||
let service = connection.remoteObjectProxyWithErrorHandler { error in | ||
fatalError("Error: \(error.localizedDescription)") | ||
} as! KettleCornServiceProtocol | ||
service.boop() | ||
return nil | ||
} | ||
|
||
guard let eventTap = CGEvent.tapCreate(tap: .cgAnnotatedSessionEventTap, place: .headInsertEventTap, options: .listenOnly, eventsOfInterest: CGEventMask(eventMask), callback: cgEventCallback, userInfo: nil) else { | ||
DispatchQueue.main.async { | ||
NSLog("faileddddddddd") | ||
} | ||
return | ||
} | ||
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0) | ||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes) | ||
CGEvent.tapEnable(tap: eventTap, enable: true) | ||
CFRunLoopRun() | ||
} | ||
|
||
func applicationWillTerminate(_ aNotification: Notification) { | ||
// Insert code here to tear down your application | ||
// connection.invalidate() | ||
} | ||
|
||
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { | ||
return true | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
KeyPopper Catcher/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
KeyPopper Catcher/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Oops, something went wrong.