@@ -23,6 +23,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
23
23
24
24
@Default ( . refreshRate) var refreshRate
25
25
@Default ( . buildType) var buildType
26
+ @Default ( . counterType) var counterType
26
27
27
28
@Default ( . githubUsername) var githubUsername
28
29
@FromKeychain ( . githubToken) var githubToken
@@ -84,19 +85,18 @@ extension AppDelegate {
84
85
func refreshMenu( ) {
85
86
NSLog ( " Refreshing menu " )
86
87
self . menu. removeAllItems ( )
87
- self . statusBarItem. button? . title = " "
88
-
88
+
89
89
if ( githubUsername == " " || githubToken == " " ) {
90
90
addMenuFooterItems ( )
91
91
return
92
92
}
93
-
94
-
93
+
94
+
95
95
var assignedPulls : [ Edge ] ? = [ ]
96
96
var createdPulls : [ Edge ] ? = [ ]
97
97
var reviewRequestedPulls : [ Edge ] ? = [ ]
98
-
99
-
98
+
99
+
100
100
let group = DispatchGroup ( )
101
101
102
102
if showAssigned {
@@ -106,63 +106,62 @@ extension AppDelegate {
106
106
group. leave ( )
107
107
}
108
108
}
109
-
109
+
110
110
if showCreated {
111
111
group. enter ( )
112
112
ghClient. getCreatedPulls ( ) { pulls in
113
113
createdPulls? . append ( contentsOf: pulls)
114
114
group. leave ( )
115
115
}
116
116
}
117
-
117
+
118
118
if showRequested {
119
119
group. enter ( )
120
120
ghClient. getReviewRequestedPulls ( ) { pulls in
121
121
reviewRequestedPulls? . append ( contentsOf: pulls)
122
122
group. leave ( )
123
123
}
124
124
}
125
-
125
+
126
126
group. notify ( queue: . main) {
127
127
128
- let isOneSelected = ( self . showAssigned. intValue + self . showCreated. intValue + self . showRequested. intValue) == 1
129
-
130
-
131
128
if let assignedPulls = assignedPulls, let createdPulls = createdPulls, let reviewRequestedPulls = reviewRequestedPulls {
132
-
129
+ self . statusBarItem. button? . title = " "
130
+
133
131
if self . showAssigned && !assignedPulls. isEmpty {
132
+ if self . counterType == . assigned {
133
+ self . statusBarItem. button? . title = String ( assignedPulls. count)
134
+ }
135
+
134
136
self . menu. addItem ( NSMenuItem ( title: " Assigned ( \( assignedPulls. count) ) " , action: nil , keyEquivalent: " " ) )
135
137
for pull in assignedPulls {
136
138
self . menu. addItem ( self . createMenuItem ( pull: pull) )
137
139
}
138
140
self . menu. addItem ( . separator( ) )
139
- if isOneSelected {
140
- self . statusBarItem. button? . title = String ( assignedPulls. count)
141
- }
142
141
}
143
142
144
143
if self . showCreated && !createdPulls. isEmpty {
144
+ if self . counterType == . created {
145
+ self . statusBarItem. button? . title = String ( createdPulls. count)
146
+ }
147
+
145
148
self . menu. addItem ( NSMenuItem ( title: " Created ( \( createdPulls. count) ) " , action: nil , keyEquivalent: " " ) )
146
149
for pull in createdPulls {
147
150
self . menu. addItem ( self . createMenuItem ( pull: pull) )
148
151
}
149
152
self . menu. addItem ( . separator( ) )
150
- if isOneSelected {
151
- self . statusBarItem. button? . title = String ( createdPulls. count)
152
- }
153
-
154
153
}
155
-
154
+
156
155
if self . showRequested && !reviewRequestedPulls. isEmpty {
156
+ if self . counterType == . reviewRequested {
157
+ self . statusBarItem. button? . title = String ( reviewRequestedPulls. count)
158
+ }
159
+
157
160
self . menu. addItem ( NSMenuItem ( title: " Review Requested ( \( reviewRequestedPulls. count) ) " , action: nil , keyEquivalent: " " ) )
158
161
for pull in reviewRequestedPulls {
159
162
self . menu. addItem ( self . createMenuItem ( pull: pull) )
160
163
}
161
164
self . menu. addItem ( . separator( ) )
162
- if isOneSelected {
163
- self . statusBarItem. button? . title = String ( reviewRequestedPulls. count)
164
- }
165
-
166
165
}
167
166
168
167
@@ -312,14 +311,9 @@ extension AppDelegate {
312
311
issueItemTitle. appendIcon ( iconName: " dot-fill " , color: NSColor . gray)
313
312
314
313
}
315
-
316
314
issueItem. submenu? . addItem ( buildItem)
317
315
}
318
-
319
-
320
-
321
316
}
322
-
323
317
}
324
318
325
319
issueItem. attributedTitle = issueItemTitle
@@ -347,7 +341,7 @@ extension AppDelegate {
347
341
preferencesWindow. close ( )
348
342
}
349
343
preferencesWindow = NSWindow (
350
- contentRect: NSRect ( x: 0 , y: 0 , width: 500 , height: 500 ) ,
344
+ contentRect: NSRect ( x: 0 , y: 0 , width: 0 , height: 0 ) ,
351
345
styleMask: [ . closable, . titled] ,
352
346
backing: . buffered,
353
347
defer: false
0 commit comments