Skip to content

Commit 21222b1

Browse files
feat: initialize repository
0 parents  commit 21222b1

File tree

20 files changed

+1027
-0
lines changed

20 files changed

+1027
-0
lines changed

GitHub Notifications.xcodeproj/project.pbxproj

Lines changed: 410 additions & 0 deletions
Large diffs are not rendered by default.

GitHub Notifications.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

GitHub Notifications.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>GitHub Notifications.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
</dict>
14+
</plist>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// AppDelegate.swift
3+
// GitHub Notifications
4+
//
5+
// Created by Yoann Fleury on 25/06/2020.
6+
// Copyright © 2020 Yoann Fleury. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
import Defaults
11+
import SwiftUI
12+
import Foundation
13+
import Preferences
14+
15+
extension Preferences.PaneIdentifier {
16+
static let general = Self("general")
17+
}
18+
19+
@NSApplicationMain
20+
class AppDelegate: NSObject, NSApplicationDelegate {
21+
@IBOutlet weak var menu: NSMenu?
22+
@IBOutlet weak var firstMenuItem: NSMenuItem?
23+
24+
@IBOutlet private var preferencesWindow: NSWindow!
25+
26+
lazy var preferencesWindowController = PreferencesWindowController(
27+
preferencePanes: [
28+
GeneralPreferenceViewController(),
29+
],
30+
style: .segmentedControl
31+
)
32+
33+
34+
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
35+
36+
override func awakeFromNib() {
37+
super.awakeFromNib()
38+
39+
let itemImage = NSImage(named: "StatusItemImage")
40+
itemImage?.isTemplate = true
41+
42+
statusItem.button?.image = itemImage
43+
44+
if let menu = menu {
45+
statusItem.menu = menu
46+
}
47+
48+
firstMenuItem?.action = #selector(openGitHub)
49+
50+
update()
51+
}
52+
53+
func applicationDidFinishLaunching(_ aNotification: Notification) {
54+
Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(AppDelegate.update), userInfo: nil, repeats: true)
55+
}
56+
57+
@IBAction
58+
func preferencesMenuItemActionHandler(_ sender: NSMenuItem) {
59+
preferencesWindowController.show()
60+
}
61+
62+
func applicationWillTerminate(_ aNotification: Notification) {
63+
// Insert code here to tear down your application
64+
}
65+
66+
@objc func openGitHub() {
67+
NSWorkspace.shared.open(NSURL(string: "https://github.com/notifications")! as URL)
68+
}
69+
70+
@objc func update() {
71+
let username = Defaults[.username]
72+
let password = Defaults[.password]
73+
74+
let basicAuth = "\(username):\(password)".data(using: .utf8)
75+
76+
if let base64Encoded = basicAuth?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0)) {
77+
let headers = ["authorization": "Basic \(base64Encoded)"]
78+
79+
let request = NSMutableURLRequest(
80+
url: NSURL(string: "https://api.github.com/notifications")! as URL,
81+
cachePolicy: .reloadIgnoringLocalCacheData,
82+
timeoutInterval: 10.0
83+
)
84+
85+
request.httpMethod = "GET"
86+
request.allHTTPHeaderFields = headers
87+
88+
let session = URLSession.shared
89+
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
90+
if error != nil {
91+
print(error!)
92+
} else {
93+
guard let responseData = data else {
94+
print("Error: did not receive data")
95+
return
96+
}
97+
98+
do {
99+
guard let notifications = try JSONSerialization.jsonObject(with: responseData, options: [])
100+
as? [Any] else {
101+
print("error trying to convert data to JSON 1")
102+
return
103+
}
104+
105+
self.firstMenuItem?.title = "\(notifications.count) notification\(notifications.count > 1 ? "s" : "")"
106+
107+
} catch {
108+
print("error trying to convert data to JSON")
109+
return
110+
}
111+
112+
}
113+
})
114+
115+
dataTask.resume()
116+
}
117+
}
118+
119+
}
120+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"scale" : "1x",
6+
"size" : "16x16"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"scale" : "2x",
11+
"size" : "16x16"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"scale" : "1x",
16+
"size" : "32x32"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"scale" : "2x",
21+
"size" : "32x32"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"scale" : "1x",
26+
"size" : "128x128"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"scale" : "2x",
31+
"size" : "128x128"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"scale" : "1x",
36+
"size" : "256x256"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"scale" : "2x",
41+
"size" : "256x256"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"scale" : "1x",
46+
"size" : "512x512"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"scale" : "2x",
51+
"size" : "512x512"
52+
}
53+
],
54+
"info" : {
55+
"author" : "xcode",
56+
"version" : 1
57+
}
58+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "GitHub-Mark-Light-16px.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "GitHub-Mark-Light-32px.png",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"author" : "xcode",
20+
"version" : 1
21+
}
22+
}
410 Bytes
Loading

0 commit comments

Comments
 (0)