Skip to content

Commit 4d3b2b4

Browse files
committed
Finish everything else
1 parent 5c5f1d0 commit 4d3b2b4

37 files changed

+3200
-15
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
2-
KeyPopper.xcodeproj/project.xcworkspace/xcuserdata
2+
KeyPopper.xcodeproj/project.xcworkspace/xcuserdata
3+
/KeyPopper Installer/build
4+
KeyPopper.xcodeproj/xcuserdata/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>sh.linus.keypopper.KettleCornSerivce</string>
7+
<key>Program</key>
8+
<string>/Library/PreferencePanes/KeyPopper\ PrefPane.prefPane/Contents/XPCServices/KettleCornService</string>
9+
<key>MachServices</key>
10+
<dict>
11+
<key>sh.linus.keypopper.KettleCornService.mach</key>
12+
<true/>
13+
</dict>
14+
</dict>
15+
</plist>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.automation.apple-events</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// KettleCornService.swift
3+
// KettleCornService
4+
//
5+
// Created by Linus Skucas on 8/3/21.
6+
//
7+
8+
import Foundation
9+
10+
struct SoundState {
11+
private let userDefaults = UserDefaults.init(suiteName: "sh.linus.keypopper")!
12+
13+
var sound: PoppingSounds {
14+
get {
15+
let soundInt = userDefaults.integer(forKey: "sound")
16+
let sound = PoppingSounds(rawValue: soundInt)!
17+
return sound
18+
}
19+
set {
20+
userDefaults.set(newValue.rawValue, forKey: "sound")
21+
}
22+
}
23+
var enabled: Bool {
24+
get {
25+
let enabled = userDefaults.bool(forKey: "enabled")
26+
return enabled
27+
}
28+
set {
29+
userDefaults.set(newValue, forKey: "enabled")
30+
}
31+
}
32+
static var shared: SoundState = SoundState()
33+
}
34+
35+
@objc class KettleCornService: NSObject, KettleCornServiceProtocol {
36+
// func hello(_ text: String, withReply reply: @escaping (String) -> Void) {
37+
// reply("Hello, \(text)!")
38+
// }
39+
40+
var connection: NSXPCConnection!
41+
var service: PoppingServiceProtocol!
42+
43+
override init() {
44+
super.init()
45+
connection = NSXPCConnection(machServiceName: "sh.linus.keypopper.PoppingService.mach")
46+
connection.remoteObjectInterface = NSXPCInterface(with: PoppingServiceProtocol.self)
47+
connection.resume()
48+
49+
service = connection.remoteObjectProxyWithErrorHandler { error in
50+
fatalError("Error: \(error.localizedDescription)")
51+
} as! PoppingServiceProtocol
52+
}
53+
54+
func changeSoundTo(_ soundInt: Int) {
55+
let sound = PoppingSounds(rawValue: soundInt)!
56+
// Store sound
57+
NSLog("Change sound")
58+
SoundState.shared.sound = sound
59+
}
60+
61+
func changeSoundState(shouldPlaySound: Bool) {
62+
NSLog("Change state")
63+
SoundState.shared.enabled = shouldPlaySound
64+
}
65+
66+
func boop() {
67+
guard SoundState.shared.enabled else { return }
68+
69+
switch SoundState.shared.sound {
70+
case .pop:
71+
service.pop()
72+
NSLog("POP")
73+
case .frog:
74+
service.frog()
75+
NSLog("Frog")
76+
case .moo:
77+
service.moo()
78+
NSLog("Moo")
79+
}
80+
}
81+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// KettleCornServiceDelegate.swift
3+
// KettleCornService
4+
//
5+
// Created by Linus Skucas on 8/3/21.
6+
//
7+
8+
import Foundation
9+
10+
class KettleCornServiceDelegate: NSObject, NSXPCListenerDelegate {
11+
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
12+
let exportedObject = KettleCornService()
13+
newConnection.exportedInterface = NSXPCInterface(with: KettleCornServiceProtocol.self)
14+
newConnection.exportedObject = exportedObject
15+
16+
newConnection.resume()
17+
return true
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// KettleCornServiceProtocol.swift
3+
// KettleCornService
4+
//
5+
// Created by Linus Skucas on 8/3/21.
6+
//
7+
8+
import Foundation
9+
10+
@objc(KettleCornServiceProtocol) protocol KettleCornServiceProtocol {
11+
// func hello(_ text: String, withReply reply: @escaping (String) -> Void)
12+
func changeSoundTo(_ soundInt: Int)
13+
func changeSoundState(shouldPlaySound: Bool)
14+
func boop()
15+
}
16+

KettleCornService/main.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// main.swift
3+
// KettleCornService
4+
//
5+
// Created by Linus Skucas on 8/3/21.
6+
//
7+
8+
import Foundation
9+
10+
let delegate = KettleCornServiceDelegate()
11+
let listener = NSXPCListener(machServiceName: "sh.linus.keypopper.KettleCornService.mach")
12+
listener.delegate = delegate
13+
listener.resume()
14+
RunLoop.main.run()

KeyPopper Catcher/AppDelegate.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// AppDelegate.swift
3+
// KeyPopper Catcher
4+
//
5+
// Created by Linus Skucas on 8/13/21.
6+
//
7+
8+
import Cocoa
9+
10+
@main
11+
class AppDelegate: NSObject, NSApplicationDelegate {
12+
13+
// var connection: NSXPCConnection!
14+
// var service: KettleCornServiceProtocol!
15+
16+
func applicationDidFinishLaunching(_ aNotification: Notification) {
17+
// Insert code here to initialize your application
18+
19+
// connection = NSXPCConnection(machServiceName: "sh.linus.keypopper.KettleCornService.mach")
20+
// connection.remoteObjectInterface = NSXPCInterface(with: KettleCornServiceProtocol.self)
21+
// connection.resume()
22+
//
23+
// service = connection.remoteObjectProxyWithErrorHandler { error in
24+
// fatalError("Error: \(error.localizedDescription)")
25+
// } as! KettleCornServiceProtocol
26+
27+
let eventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue)
28+
NSLog("gggp")
29+
func cgEventCallback(proxy: CGEventTapProxy, type: CGEventType, event: CGEvent, refcon: UnsafeMutableRawPointer?) -> Unmanaged<CGEvent>? {
30+
let connection = NSXPCConnection(machServiceName: "sh.linus.keypopper.KettleCornService.mach")
31+
connection.remoteObjectInterface = NSXPCInterface(with: KettleCornServiceProtocol.self)
32+
connection.resume()
33+
34+
let service = connection.remoteObjectProxyWithErrorHandler { error in
35+
fatalError("Error: \(error.localizedDescription)")
36+
} as! KettleCornServiceProtocol
37+
service.boop()
38+
return nil
39+
}
40+
41+
guard let eventTap = CGEvent.tapCreate(tap: .cgAnnotatedSessionEventTap, place: .headInsertEventTap, options: .listenOnly, eventsOfInterest: CGEventMask(eventMask), callback: cgEventCallback, userInfo: nil) else {
42+
DispatchQueue.main.async {
43+
NSLog("faileddddddddd")
44+
}
45+
return
46+
}
47+
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0)
48+
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
49+
CGEvent.tapEnable(tap: eventTap, enable: true)
50+
CFRunLoopRun()
51+
}
52+
53+
func applicationWillTerminate(_ aNotification: Notification) {
54+
// Insert code here to tear down your application
55+
// connection.invalidate()
56+
}
57+
58+
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
59+
return true
60+
}
61+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"scale" : "1x",
6+
"size" : "16x16"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"scale" : "2x",
11+
"size" : "16x16"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"scale" : "1x",
16+
"size" : "32x32"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"scale" : "2x",
21+
"size" : "32x32"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"scale" : "1x",
26+
"size" : "128x128"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"scale" : "2x",
31+
"size" : "128x128"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"scale" : "1x",
36+
"size" : "256x256"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"scale" : "2x",
41+
"size" : "256x256"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"scale" : "1x",
46+
"size" : "512x512"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"scale" : "2x",
51+
"size" : "512x512"
52+
}
53+
],
54+
"info" : {
55+
"author" : "xcode",
56+
"version" : 1
57+
}
58+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

0 commit comments

Comments
 (0)