Skip to content

Commit b04bfb3

Browse files
committed
Added example for class method
1 parent b29b46f commit b04bfb3

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

Example/InterposeKitExample/Sources/AppDelegate.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
9999
return "## \(title) ##"
100100
}
101101
}
102-
case .NSColor_controlAccentColor:
103-
fatalError("Not implemented")
102+
case .NSColor_labelColor:
103+
return try Interpose.prepareHook(
104+
on: NSColor.self,
105+
for: #selector(getter: NSColor.labelColor),
106+
methodKind: .class,
107+
methodSignature: (@convention(c) (NSColor.Type, Selector) -> NSColor).self,
108+
hookSignature: (@convention(block) (NSColor.Type) -> NSColor).self
109+
) { hook in
110+
return { `self` in
111+
return self.systemPink
112+
}
113+
}
104114
}
105115
} catch {
106116
fatalError("\(error)")

Example/InterposeKitExample/Sources/ContentView.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,13 @@ struct ContentView: View {
4444
.labelsHidden()
4545
.padding(.leading, 20)
4646
} label: {
47-
Group {
48-
Text(example.selector)
49-
.monospaced()
50-
51-
Text(example.description)
52-
.font(.subheadline)
53-
}
54-
.opacity(example == .NSColor_controlAccentColor ? 0.5 : 1)
47+
Text(example.selector)
48+
.monospaced()
49+
.foregroundStyle(Color(NSColor.labelColor))
50+
51+
Text(example.description)
52+
.font(.subheadline)
5553
}
56-
.disabled(example == .NSColor_controlAccentColor)
5754
}
5855
}
5956
}

Example/InterposeKitExample/Sources/HookExample.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ enum HookExample: CaseIterable {
22
case NSApplication_sendEvent
33
case NSWindow_setTitle
44
case NSMenuItem_title
5-
case NSColor_controlAccentColor
5+
case NSColor_labelColor
66
}
77

88
extension HookExample {
@@ -14,8 +14,8 @@ extension HookExample {
1414
return "-[NSWindow setTitle:]"
1515
case .NSMenuItem_title:
1616
return "-[NSMenuItem title]"
17-
case .NSColor_controlAccentColor:
18-
return "+[NSColor controlAccentColor]"
17+
case .NSColor_labelColor:
18+
return "+[NSColor labelColor]"
1919
}
2020
}
2121

@@ -36,10 +36,10 @@ extension HookExample {
3636
A class hook on NSMenuItem that wraps all menu item titles with decorative markers, \
3737
visible in the main menu and the text field’s context menu.
3838
"""
39-
case .NSColor_controlAccentColor:
39+
case .NSColor_labelColor:
4040
return """
41-
A class hook that overrides the system accent color by hooking the corresponding \
42-
class method on NSColor. (Not implemented.)
41+
A class hook that overrides the standard label color by hooking the corresponding \
42+
class method on NSColor. Affects text in this window and menus.
4343
"""
4444
}
4545
}

0 commit comments

Comments
 (0)