Skip to content

Commit 6f04dd4

Browse files
fix: multiple icon issue
light theme icon was not visible, and the icon didn't show on first launch without credentials
1 parent f8d240e commit 6f04dd4

19 files changed

+174
-123
lines changed

GitHub Notifications.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
/* Begin PBXBuildFile section */
1010
311107F324AE81A900D7CE07 /* assets in Resources */ = {isa = PBXBuildFile; fileRef = 311107F224AE81A900D7CE07 /* assets */; };
11-
3145EAD524A93D940096F234 /* GitHubService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3145EAD424A93D940096F234 /* GitHubService.swift */; };
1211
3145EAD724A9C3660096F234 /* GeneralPreferenceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3145EAD624A9C3660096F234 /* GeneralPreferenceViewController.swift */; };
1312
3145EADB24AA0E730096F234 /* GeneralPreferenceViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3145EADA24AA0E730096F234 /* GeneralPreferenceViewController.xib */; };
1413
3195609824AB5E060049691C /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = 3195609724AB5E060049691C /* Defaults */; };
1514
3195609A24AB5E9A0049691C /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3195609924AB5E9A0049691C /* Constants.swift */; };
1615
31EA4CC624A509F40044C1FF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31EA4CC524A509F40044C1FF /* AppDelegate.swift */; };
17-
31EA4CC824A509F40044C1FF /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31EA4CC724A509F40044C1FF /* ContentView.swift */; };
1816
31EA4CCA24A509F40044C1FF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 31EA4CC924A509F40044C1FF /* Assets.xcassets */; };
1917
31EA4CCD24A509F40044C1FF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 31EA4CCC24A509F40044C1FF /* Preview Assets.xcassets */; };
2018
31EA4CD024A509F40044C1FF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 31EA4CCE24A509F40044C1FF /* Main.storyboard */; };
@@ -24,13 +22,11 @@
2422
/* Begin PBXFileReference section */
2523
311107F124ADCA1D00D7CE07 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
2624
311107F224AE81A900D7CE07 /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; path = assets; sourceTree = "<group>"; };
27-
3145EAD424A93D940096F234 /* GitHubService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubService.swift; sourceTree = "<group>"; };
2825
3145EAD624A9C3660096F234 /* GeneralPreferenceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPreferenceViewController.swift; sourceTree = "<group>"; };
2926
3145EADA24AA0E730096F234 /* GeneralPreferenceViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GeneralPreferenceViewController.xib; sourceTree = "<group>"; };
3027
3195609924AB5E9A0049691C /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
3128
31EA4CC224A509F40044C1FF /* GitHub Notifications.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GitHub Notifications.app"; sourceTree = BUILT_PRODUCTS_DIR; };
3229
31EA4CC524A509F40044C1FF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
33-
31EA4CC724A509F40044C1FF /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
3430
31EA4CC924A509F40044C1FF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3531
31EA4CCC24A509F40044C1FF /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
3632
31EA4CCF24A509F40044C1FF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -73,13 +69,11 @@
7369
isa = PBXGroup;
7470
children = (
7571
31EA4CC524A509F40044C1FF /* AppDelegate.swift */,
76-
31EA4CC724A509F40044C1FF /* ContentView.swift */,
7772
31EA4CC924A509F40044C1FF /* Assets.xcassets */,
7873
31EA4CCE24A509F40044C1FF /* Main.storyboard */,
7974
31EA4CD124A509F40044C1FF /* Info.plist */,
8075
31EA4CD224A509F40044C1FF /* GitHub_Notifications.entitlements */,
8176
31EA4CCB24A509F40044C1FF /* Preview Content */,
82-
3145EAD424A93D940096F234 /* GitHubService.swift */,
8377
3145EAD624A9C3660096F234 /* GeneralPreferenceViewController.swift */,
8478
3145EADA24AA0E730096F234 /* GeneralPreferenceViewController.xib */,
8579
3195609924AB5E9A0049691C /* Constants.swift */,
@@ -178,8 +172,6 @@
178172
files = (
179173
3195609A24AB5E9A0049691C /* Constants.swift in Sources */,
180174
3145EAD724A9C3660096F234 /* GeneralPreferenceViewController.swift in Sources */,
181-
31EA4CC824A509F40044C1FF /* ContentView.swift in Sources */,
182-
3145EAD524A93D940096F234 /* GitHubService.swift in Sources */,
183175
31EA4CC624A509F40044C1FF /* AppDelegate.swift in Sources */,
184176
);
185177
runOnlyForDeploymentPostprocessing = 0;

GitHub Notifications/AppDelegate.swift

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import Cocoa
1010
import Defaults
1111
import SwiftUI
12-
import Foundation
1312
import Preferences
1413

1514
extension Preferences.PaneIdentifier {
@@ -41,22 +40,26 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4140
}
4241

4342
firstMenuItem?.action = #selector(openGitHub)
43+
setStatusItemImage()
4444

4545
update()
4646
}
4747

4848
func applicationDidFinishLaunching(_ aNotification: Notification) {
49-
Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(AppDelegate.update), userInfo: nil, repeats: true)
49+
Timer.scheduledTimer(
50+
timeInterval: 60,
51+
target: self,
52+
selector:
53+
#selector(AppDelegate.update),
54+
userInfo: nil,
55+
repeats: true
56+
)
5057
}
5158

5259
@IBAction
5360
func preferencesMenuItemActionHandler(_ sender: NSMenuItem) {
5461
preferencesWindowController.show()
5562
}
56-
57-
func applicationWillTerminate(_ aNotification: Notification) {
58-
// Insert code here to tear down your application
59-
}
6063

6164
@objc func openGitHub() {
6265
NSWorkspace.shared.open(NSURL(string: "https://github.com/notifications")! as URL)
@@ -71,54 +74,58 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7174
if let base64Encoded = basicAuth?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0)) {
7275
let headers = ["authorization": "Basic \(base64Encoded)"]
7376

74-
let request = NSMutableURLRequest(
75-
url: NSURL(string: "https://api.github.com/notifications")! as URL,
76-
cachePolicy: .reloadIgnoringLocalCacheData,
77-
timeoutInterval: 10.0
78-
)
77+
let request = NSMutableURLRequest(
78+
url: NSURL(string: "https://api.github.com/notifications")! as URL,
79+
cachePolicy: .reloadIgnoringLocalCacheData,
80+
timeoutInterval: 10.0
81+
)
7982

80-
request.httpMethod = "GET"
81-
request.allHTTPHeaderFields = headers
83+
request.httpMethod = "GET"
84+
request.allHTTPHeaderFields = headers
8285

83-
let session = URLSession.shared
84-
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
85-
if error != nil {
86-
print(error!)
87-
} else {
88-
guard let responseData = data else {
89-
print("Error: did not receive data")
90-
return
91-
}
92-
93-
do {
94-
guard let notifications = try JSONSerialization.jsonObject(with: responseData, options: [])
95-
as? [Any] else {
96-
print("error trying to convert data to JSON 1")
97-
return
86+
let session = URLSession.shared
87+
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
88+
if error != nil {
89+
print(error!)
90+
} else {
91+
guard let responseData = data else {
92+
print("Error: did not receive data")
93+
return
94+
}
95+
96+
do {
97+
guard let notifications = try JSONSerialization.jsonObject(with: responseData, options: [])
98+
as? [Any] else {
99+
print("error trying to convert data to JSON 1")
100+
return
98101
}
99102

100103
self.firstMenuItem?.title = "\(notifications.count) notification\(notifications.count > 1 ? "s" : "")"
101104

102105
let doesNotificationExist = notifications.count >= 1
103106

104-
let itemImage = NSImage(named: doesNotificationExist ? "StatusItemImageNotification" : "StatusItemImage")
105-
itemImage?.isTemplate = false
106-
107107
DispatchQueue.main.async {
108-
self.statusItem.button?.image = itemImage
108+
self.setStatusItemImage(
109+
named: doesNotificationExist
110+
? "StatusItemImageNotification"
111+
: "StatusItemImage"
112+
)
109113
}
110-
111114
} catch {
112115
print("error trying to convert data to JSON")
113116
return
114117
}
115-
116118
}
117119
})
118120

119121
dataTask.resume()
120122
}
121123
}
122124

125+
func setStatusItemImage(named: String = "StatusItemImage") {
126+
let itemImage = NSImage(named: named)
127+
itemImage?.isTemplate = false
128+
statusItem.button?.image = itemImage
129+
}
123130
}
124131

GitHub Notifications/Assets.xcassets/StatusItemImage.imageset/Contents.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,81 @@
55
"idiom" : "universal",
66
"scale" : "1x"
77
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "light"
13+
}
14+
],
15+
"filename" : "LightStatusItemImage_1.png",
16+
"idiom" : "universal",
17+
"scale" : "1x"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "dark"
24+
}
25+
],
26+
"filename" : "StatusItemImage_1-1.png",
27+
"idiom" : "universal",
28+
"scale" : "1x"
29+
},
830
{
931
"filename" : "StatusItemImage_2.png",
1032
"idiom" : "universal",
1133
"scale" : "2x"
1234
},
35+
{
36+
"appearances" : [
37+
{
38+
"appearance" : "luminosity",
39+
"value" : "light"
40+
}
41+
],
42+
"filename" : "LightStatusItemImage_2.png",
43+
"idiom" : "universal",
44+
"scale" : "2x"
45+
},
46+
{
47+
"appearances" : [
48+
{
49+
"appearance" : "luminosity",
50+
"value" : "dark"
51+
}
52+
],
53+
"filename" : "StatusItemImage_2-1.png",
54+
"idiom" : "universal",
55+
"scale" : "2x"
56+
},
1357
{
1458
"filename" : "StatusItemImage_3.png",
1559
"idiom" : "universal",
1660
"scale" : "3x"
61+
},
62+
{
63+
"appearances" : [
64+
{
65+
"appearance" : "luminosity",
66+
"value" : "light"
67+
}
68+
],
69+
"filename" : "LightStatusItemImage_3.png",
70+
"idiom" : "universal",
71+
"scale" : "3x"
72+
},
73+
{
74+
"appearances" : [
75+
{
76+
"appearance" : "luminosity",
77+
"value" : "dark"
78+
}
79+
],
80+
"filename" : "StatusItemImage_3-1.png",
81+
"idiom" : "universal",
82+
"scale" : "3x"
1783
}
1884
],
1985
"info" : {
337 Bytes
Loading
582 Bytes
Loading
1.03 KB
Loading
293 Bytes
Loading
423 Bytes
Loading
748 Bytes
Loading

GitHub Notifications/Assets.xcassets/StatusItemImageNotification.imageset/Contents.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,81 @@
55
"idiom" : "universal",
66
"scale" : "1x"
77
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "light"
13+
}
14+
],
15+
"filename" : "LightStatusItemImageNotification_1.png",
16+
"idiom" : "universal",
17+
"scale" : "1x"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "dark"
24+
}
25+
],
26+
"filename" : "StatusItemImageNotification_1-1.png",
27+
"idiom" : "universal",
28+
"scale" : "1x"
29+
},
830
{
931
"filename" : "StatusItemImageNotification_2.png",
1032
"idiom" : "universal",
1133
"scale" : "2x"
1234
},
35+
{
36+
"appearances" : [
37+
{
38+
"appearance" : "luminosity",
39+
"value" : "light"
40+
}
41+
],
42+
"filename" : "LightStatusItemImageNotification_2.png",
43+
"idiom" : "universal",
44+
"scale" : "2x"
45+
},
46+
{
47+
"appearances" : [
48+
{
49+
"appearance" : "luminosity",
50+
"value" : "dark"
51+
}
52+
],
53+
"filename" : "StatusItemImageNotification_2-1.png",
54+
"idiom" : "universal",
55+
"scale" : "2x"
56+
},
1357
{
1458
"filename" : "StatusItemImageNotification_3.png",
1559
"idiom" : "universal",
1660
"scale" : "3x"
61+
},
62+
{
63+
"appearances" : [
64+
{
65+
"appearance" : "luminosity",
66+
"value" : "light"
67+
}
68+
],
69+
"filename" : "LightStatusItemImageNotification_3.png",
70+
"idiom" : "universal",
71+
"scale" : "3x"
72+
},
73+
{
74+
"appearances" : [
75+
{
76+
"appearance" : "luminosity",
77+
"value" : "dark"
78+
}
79+
],
80+
"filename" : "StatusItemImageNotification_3-1.png",
81+
"idiom" : "universal",
82+
"scale" : "3x"
1783
}
1884
],
1985
"info" : {

0 commit comments

Comments
 (0)