Skip to content

Commit e296bf7

Browse files
committed
Changed hook for NSApplication.sendEvent(_:) from object to class
This caused issues with KVO when attempting to revert the hook
1 parent e45a2d1 commit e296bf7

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

Example/InterposeKitExample/Sources/AppDelegate.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6464
) -> Hook {
6565
do {
6666
switch example {
67+
case .NSWindow_setTitle:
68+
return try Interpose.prepareHook(
69+
on: self.window,
70+
for: #selector(setter: NSWindow.title),
71+
methodSignature: (@convention(c) (NSWindow, Selector, String) -> Void).self,
72+
hookSignature: (@convention(block) (NSWindow, String) -> Void).self
73+
) { hook in
74+
return { `self`, title in
75+
hook.original(self, hook.selector, "## \(title.uppercased()) ##")
76+
}
77+
}
6778
case .NSApplication_sendEvent:
6879
return try Interpose.prepareHook(
6980
on: NSApplication.shared,
@@ -76,17 +87,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7687
hook.original(self, hook.selector, event)
7788
}
7889
}
79-
case .NSWindow_setTitle:
80-
return try Interpose.prepareHook(
81-
on: self.window,
82-
for: #selector(setter: NSWindow.title),
83-
methodSignature: (@convention(c) (NSWindow, Selector, String) -> Void).self,
84-
hookSignature: (@convention(block) (NSWindow, String) -> Void).self
85-
) { hook in
86-
return { `self`, title in
87-
hook.original(self, hook.selector, "## \(title.uppercased()) ##")
88-
}
89-
}
9090
case .NSMenuItem_title:
9191
return try Interpose.prepareHook(
9292
on: NSMenuItem.self,

Example/InterposeKitExample/Sources/HookExample.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
enum HookExample: CaseIterable {
2-
case NSApplication_sendEvent
32
case NSWindow_setTitle
3+
case NSApplication_sendEvent
44
case NSMenuItem_title
55
case NSColor_labelColor
66
}
77

88
extension HookExample {
99
var selector: String {
1010
switch self {
11-
case .NSApplication_sendEvent:
12-
return "-[NSApplication sendEvent:]"
1311
case .NSWindow_setTitle:
1412
return "-[NSWindow setTitle:]"
13+
case .NSApplication_sendEvent:
14+
return "-[NSApplication sendEvent:]"
1515
case .NSMenuItem_title:
1616
return "-[NSMenuItem title]"
1717
case .NSColor_labelColor:
@@ -21,16 +21,15 @@ extension HookExample {
2121

2222
var description: String {
2323
switch self {
24-
case .NSApplication_sendEvent:
25-
return """
26-
An object hook on the shared NSApplication instance that logs all events passed \
27-
through sendEvent(_:).
28-
"""
2924
case .NSWindow_setTitle:
3025
return """
3126
An object hook on the main NSWindow that uppercases the title and wraps it with \
3227
decorative markers whenever it’s set. This can be tested using the text field below.
3328
"""
29+
case .NSApplication_sendEvent:
30+
return """
31+
A class hook on NSApplication that logs all events passed through sendEvent(_:).
32+
"""
3433
case .NSMenuItem_title:
3534
return """
3635
A class hook on NSMenuItem that wraps all menu item titles with decorative markers, \

0 commit comments

Comments
 (0)