@@ -127,9 +127,7 @@ class Maccy: NSObject {
127
127
self . menu. popUp ( positioning: nil , at: NSPoint ( x: topLeftX, y: topLeftY) , in: nil )
128
128
}
129
129
case " statusItem " :
130
- if let button = self . statusItem. button, let window = button. window {
131
- self . menu. popUp ( positioning: nil , at: window. frame. origin, in: nil )
132
- }
130
+ self . simulateStatusItemClick ( )
133
131
default :
134
132
self . menu. popUp ( positioning: nil , at: NSEvent . mouseLocation, in: nil )
135
133
}
@@ -146,13 +144,7 @@ class Maccy: NSObject {
146
144
}
147
145
148
146
withFocus {
149
- if let buttonCell = self . statusItem. button? . cell as? NSButtonCell {
150
- buttonCell. highlightsBy = [ . changeBackgroundCellMask, . changeGrayCellMask, . contentsCellMask, . pushInCellMask]
151
- self . statusItem. menu = self . menu
152
- self . statusItem. button? . performClick ( self )
153
- self . statusItem. menu = nil
154
- buttonCell. highlightsBy = [ ]
155
- }
147
+ self . simulateStatusItemClick ( )
156
148
}
157
149
}
158
150
@@ -272,6 +264,16 @@ class Maccy: NSObject {
272
264
statusItem. button? . title = String ( title. prefix ( statusItemTitleMaxLength) )
273
265
}
274
266
267
+ private func simulateStatusItemClick( ) {
268
+ if let buttonCell = statusItem. button? . cell as? NSButtonCell {
269
+ buttonCell. highlightsBy = [ . changeBackgroundCellMask, . changeGrayCellMask, . contentsCellMask, . pushInCellMask]
270
+ statusItem. menu = menu
271
+ statusItem. button? . performClick ( self )
272
+ statusItem. menu = nil
273
+ buttonCell. highlightsBy = [ ]
274
+ }
275
+ }
276
+
275
277
// Executes closure with application focus (pun intended).
276
278
//
277
279
// Beware of hacks. This code is so fragile that you should
0 commit comments