Skip to content
This repository was archived by the owner on Jun 19, 2020. It is now read-only.

Commit 9abdb31

Browse files
committed
Using a less suspicious way to customize window buttons suggested by @jnadeau
1 parent f4d96c4 commit 9abdb31

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

EventsUI/EventsUI/EVTWindow.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ open class EVTWindow: NSWindow {
3636
return NSAppearance(named: NSAppearanceNameVibrantDark)!
3737
}
3838

39-
fileprivate var titlebarWidgets: [NSButton]? {
40-
return titlebarView?.subviews.flatMap { subview in
41-
guard subview.isKind(of: NSClassFromString("_NSThemeWidget")!) else { return nil }
42-
return subview as? NSButton
43-
}
44-
}
39+
fileprivate var titlebarWidgets = Set<NSButton>()
4540

4641
fileprivate func appearanceForWidgets() -> NSAppearance? {
4742
if allowsPiPMode {
@@ -53,7 +48,7 @@ open class EVTWindow: NSWindow {
5348

5449
fileprivate func applyAppearanceToWidgets() {
5550
let appearance = appearanceForWidgets()
56-
titlebarWidgets?.forEach { $0.appearance = appearance }
51+
titlebarWidgets.forEach { $0.appearance = appearance }
5752
}
5853

5954
fileprivate var _storedTitlebarView: NSVisualEffectView?
@@ -192,6 +187,14 @@ open class EVTWindow: NSWindow {
192187
}, completionHandler: nil)
193188
}
194189

190+
open override func standardWindowButton(_ b: NSWindowButton) -> NSButton? {
191+
guard let button = super.standardWindowButton(b) else { return nil }
192+
193+
titlebarWidgets.insert(button)
194+
195+
return button
196+
}
197+
195198
// MARK: - Content management
196199

197200
open override var title: String {

0 commit comments

Comments
 (0)