@@ -13,19 +13,7 @@ import KeychainAccess
13
13
14
14
@main
15
15
class AppDelegate : NSObject , NSApplicationDelegate {
16
-
17
- @Default ( . showAssigned) var showAssigned
18
- @Default ( . showCreated) var showCreated
19
- @Default ( . showRequested) var showRequested
20
-
21
- @Default ( . showAvatar) var showAvatar
22
- @Default ( . showLabels) var showLabels
23
-
24
- @Default ( . refreshRate) var refreshRate
25
- @Default ( . buildType) var buildType
26
- @Default ( . counterType) var counterType
27
-
28
- @Default ( . githubUsername) var githubUsername
16
+
29
17
@FromKeychain ( . githubToken) var githubToken
30
18
31
19
let ghClient = GitHubClient ( )
@@ -51,7 +39,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
51
39
statusBarItem. menu = menu
52
40
53
41
timer = Timer . scheduledTimer (
54
- timeInterval: Double ( refreshRate * 60 ) ,
42
+ timeInterval: Double ( Defaults [ . refreshRate] * 60 ) ,
55
43
target: self ,
56
44
selector: #selector( refreshMenu) ,
57
45
userInfo: nil ,
@@ -86,7 +74,7 @@ extension AppDelegate {
86
74
NSLog ( " Refreshing menu " )
87
75
self . menu. removeAllItems ( )
88
76
89
- if ( githubUsername == " " || githubToken == " " ) {
77
+ if ( Defaults [ . githubUsername] == " " || githubToken == " " ) {
90
78
addMenuFooterItems ( )
91
79
return
92
80
}
@@ -99,23 +87,23 @@ extension AppDelegate {
99
87
100
88
let group = DispatchGroup ( )
101
89
102
- if showAssigned {
90
+ if Defaults [ . showAssigned] {
103
91
group. enter ( )
104
92
ghClient. getAssignedPulls ( ) { pulls in
105
93
assignedPulls? . append ( contentsOf: pulls)
106
94
group. leave ( )
107
95
}
108
96
}
109
97
110
- if showCreated {
98
+ if Defaults [ . showCreated] {
111
99
group. enter ( )
112
100
ghClient. getCreatedPulls ( ) { pulls in
113
101
createdPulls? . append ( contentsOf: pulls)
114
102
group. leave ( )
115
103
}
116
104
}
117
105
118
- if showRequested {
106
+ if Defaults [ . showRequested] {
119
107
group. enter ( )
120
108
ghClient. getReviewRequestedPulls ( ) { pulls in
121
109
reviewRequestedPulls? . append ( contentsOf: pulls)
@@ -128,8 +116,8 @@ extension AppDelegate {
128
116
if let assignedPulls = assignedPulls, let createdPulls = createdPulls, let reviewRequestedPulls = reviewRequestedPulls {
129
117
self . statusBarItem. button? . title = " "
130
118
131
- if self . showAssigned && !assignedPulls. isEmpty {
132
- if self . counterType == . assigned {
119
+ if Defaults [ . showAssigned] && !assignedPulls. isEmpty {
120
+ if Defaults [ . counterType] == . assigned {
133
121
self . statusBarItem. button? . title = String ( assignedPulls. count)
134
122
}
135
123
@@ -140,8 +128,8 @@ extension AppDelegate {
140
128
self . menu. addItem ( . separator( ) )
141
129
}
142
130
143
- if self . showCreated && !createdPulls. isEmpty {
144
- if self . counterType == . created {
131
+ if Defaults [ . showCreated] && !createdPulls. isEmpty {
132
+ if Defaults [ . counterType] == . created {
145
133
self . statusBarItem. button? . title = String ( createdPulls. count)
146
134
}
147
135
@@ -152,8 +140,8 @@ extension AppDelegate {
152
140
self . menu. addItem ( . separator( ) )
153
141
}
154
142
155
- if self . showRequested && !reviewRequestedPulls. isEmpty {
156
- if self . counterType == . reviewRequested {
143
+ if Defaults [ . showRequested] && !reviewRequestedPulls. isEmpty {
144
+ if Defaults [ . counterType] == . reviewRequested {
157
145
self . statusBarItem. button? . title = String ( reviewRequestedPulls. count)
158
146
}
159
147
@@ -195,7 +183,7 @@ extension AppDelegate {
195
183
. appendIcon ( iconName: " person " )
196
184
. appendString ( string: pull. node. author. login)
197
185
198
- if !pull. node. labels. nodes. isEmpty && self . showLabels {
186
+ if !pull. node. labels. nodes. isEmpty && Defaults [ . showLabels] {
199
187
issueItemTitle
200
188
. appendNewLine ( )
201
189
. appendIcon ( iconName: " tag " , color: NSColor ( . secondary) )
@@ -208,7 +196,7 @@ extension AppDelegate {
208
196
209
197
issueItemTitle. appendNewLine ( )
210
198
211
- let approvedByMe = pull. node. reviews. edges. contains { $0. node. author. login == githubUsername }
199
+ let approvedByMe = pull. node. reviews. edges. contains { $0. node. author. login == Defaults [ . githubUsername] }
212
200
issueItemTitle
213
201
. appendIcon ( iconName: " check-circle " , color: approvedByMe ? NSColor ( named: " green " ) ! : NSColor . secondaryLabelColor)
214
202
. appendString ( string: " " + String( pull. node. reviews. totalCount) )
@@ -219,7 +207,7 @@ extension AppDelegate {
219
207
. appendIcon ( iconName: " calendar " )
220
208
. appendString ( string: pull. node. createdAt. getElapsedInterval ( ) )
221
209
222
- if showAvatar {
210
+ if Defaults [ . showAvatar] {
223
211
var image = NSImage ( )
224
212
if let imageURL = pull. node. author. avatarUrl {
225
213
image = NSImage . imageFromUrl ( fromURL: imageURL) ?? NSImage ( named: " person " ) !
@@ -400,7 +388,7 @@ extension AppDelegate {
400
388
if ( windowTitle == " Preferences " ) {
401
389
timer? . invalidate ( )
402
390
timer = Timer . scheduledTimer (
403
- timeInterval: Double ( refreshRate * 60 ) ,
391
+ timeInterval: Double ( Defaults [ . refreshRate] * 60 ) ,
404
392
target: self ,
405
393
selector: #selector( refreshMenu) ,
406
394
userInfo: nil ,
0 commit comments