Skip to content

Commit a65b50a

Browse files
author
Alan Westbrook
committed
Clean up and debug
* Remove unnecessary image resources from xcassets * Use the correct alt-image for the item selected icon * Disable the mailbox item when we aren't logged in from the start * Update for latest Xcode 8 beta (beta 2) * Remove a few force unwraps (always makes me happy)
1 parent 62af197 commit a65b50a

File tree

26 files changed

+66
-128
lines changed

26 files changed

+66
-128
lines changed

Orangered-Swift/AppDelegate.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1717
}
1818
}
1919

20-
21-
22-
Binary file not shown.
Binary file not shown.

Orangered-Swift/Assets.xcassets/BlackEnvelope.imageset/Contents.json

Lines changed: 0 additions & 22 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

Orangered-Swift/Assets.xcassets/BlueEnvelope.imageset/Contents.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

Orangered-Swift/Assets.xcassets/GreyEnvelope.imageset/Contents.json

Lines changed: 0 additions & 22 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

Orangered-Swift/Assets.xcassets/OrangeredEnvelope.imageset/Contents.json

Lines changed: 0 additions & 21 deletions
This file was deleted.
Binary file not shown.

Orangered-Swift/Assets.xcassets/active.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "active@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/logged-in-dark.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "logged-in-dark@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/logged-in.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "logged-in@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/message-dark.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "message-dark@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/message.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "message@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/mod-dark.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "mod-dark@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/mod.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "mod@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/modmailgrey.imageset/Contents.json

Lines changed: 0 additions & 21 deletions
This file was deleted.
Binary file not shown.

Orangered-Swift/Assets.xcassets/not-connected-dark.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "not-connected-dark@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/Assets.xcassets/not-connected.imageset/Contents.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"idiom" : "universal",
1010
"filename" : "not-connected@2x.png",
1111
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
1216
}
1317
],
1418
"info" : {

Orangered-Swift/LoginViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class LoginViewController: NSViewController {
5858
setupLabel(label: nameLabel, text: "User Name:")
5959
setupLabel(label: passwordLabel, text: "Password:")
6060

61-
let pref = UserDefaults.standard()
61+
let pref = UserDefaults.standard
6262
nameField.stringValue = pref.username ?? ""
6363
passwordField.stringValue = pref.password ?? ""
6464

6565
loginButton.title = NSLocalizedString("Login", comment: "login button title on the login window")
66-
loginButton.bezelStyle = .roundedBezelStyle
66+
loginButton.bezelStyle = .rounded
6767
loginButton.keyEquivalent = "\r"
6868
loginButton.target = self
6969
loginButton.action = #selector(loginClicked)

Orangered-Swift/PrefViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension NSButton {
5353
self.init(checkboxWithTitle: title, target: target, action: action)
5454
} else {
5555
self.init()
56-
self.setButtonType(.switchButton)
56+
setButtonType(.switch)
5757
self.title = title
5858
self.target = target
5959
self.action = action

Orangered-Swift/StatusItemController.swift

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
4848
]
4949

5050
let index = appearanceName == NSAppearanceNameVibrantDark ? 1 : 0
51-
return NSImage(named: imageMap[self]![index])!
51+
52+
guard let name = imageMap[self]?[index] else {
53+
fatalError("you really messed up this time, missing case: imageMap for \(self), index: \(index)")
54+
}
55+
56+
guard let image = NSImage(named: name) else {
57+
fatalError("fix yo assets, missing image: \(name)")
58+
}
59+
60+
return image
5261
}
5362

5463
func mailboxUrl() -> URL? {
@@ -65,9 +74,9 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
6574
private let statusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength)
6675

6776
private var statusPoller:Timer?
68-
private let prefs = UserDefaults.standard()
77+
private let prefs = UserDefaults.standard
6978
private var statusConnection:URLSession?
70-
private let session = URLSession.shared()
79+
private let session = URLSession.shared
7180
private var loginWindowController:NSWindowController?
7281
private var prefWindowController:NSWindowController?
7382
private var mailboxItem:NSMenuItem?
@@ -82,21 +91,25 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
8291
}
8392

8493
private func setup() {
85-
NSUserNotificationCenter.default().delegate = self
94+
NSUserNotificationCenter.default.delegate = self
8695
setupMenu()
8796
}
8897

8998
private func setupMenu() {
9099
let menu = Menu()
91100

92-
mailboxItem = NSMenuItem(title: NSLocalizedString("Mailbox…", comment:"Menu item for opening the reddit mailbox"),
101+
let mailbox = NSMenuItem(title: NSLocalizedString("Mailbox…", comment:"Menu item for opening the reddit mailbox"),
93102
action: #selector(handleMailboxItemSelected), keyEquivalent: "")
94-
menu.addItem(mailboxItem!)
103+
mailbox.isEnabled = false
104+
menu.addItem(mailbox)
95105
menu.addItem(NSMenuItem.separator())
96106

97-
loginItem = NSMenuItem(title: kLoginMenuTitle,
107+
mailboxItem = mailbox
108+
109+
let login = NSMenuItem(title: kLoginMenuTitle,
98110
action: #selector(handleLoginItemSelected), keyEquivalent: "")
99-
menu.addItem(loginItem!)
111+
menu.addItem(login)
112+
loginItem = login
100113

101114
#if PrefsDone
102115
let prefsItem = NSMenuItem(title: NSLocalizedString("Preferences…", comment:"Menu item title for opening the preferences window"),
@@ -113,7 +126,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
113126
}
114127

115128
statusItem.menu = menu
116-
statusItem.alternateImage = NSImage(named: "logged-in-dark")
129+
statusItem.alternateImage = NSImage(named: "active")
117130
updateIcon()
118131
}
119132

@@ -168,7 +181,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
168181
state = .disconnected
169182
}
170183
else {
171-
HTTPCookieStorage.shared().setCookies(cookies, for: kRedditCookieURL, mainDocumentURL: nil)
184+
HTTPCookieStorage.shared.setCookies(cookies, for: kRedditCookieURL, mainDocumentURL: nil)
172185

173186
prefs.loggedIn = true
174187
state = .mailfree
@@ -180,7 +193,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
180193
statusPoller?.invalidate()
181194
let interval:TimeInterval = 60
182195
statusPoller = Timer(timeInterval: interval, target: self, selector: #selector(checkReddit), userInfo: nil, repeats: true)
183-
RunLoop.main().add(statusPoller!, forMode: RunLoopMode.defaultRunLoopMode)
196+
RunLoop.main.add(statusPoller!, forMode: RunLoopMode.defaultRunLoopMode)
184197
statusPoller?.fire()
185198
}
186199

@@ -261,7 +274,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
261274
note.informativeText = NSLocalizedString("You have a new message on reddit!", comment: "new message notification text")
262275
note.actionButtonTitle = NSLocalizedString("Read", comment: "notification call to action button")
263276

264-
NSUserNotificationCenter.default().deliver(note)
277+
NSUserNotificationCenter.default.deliver(note)
265278
}
266279

267280
private func openMailbox() {
@@ -273,13 +286,13 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
273286
self.checkReddit()
274287
}
275288

276-
NSUserNotificationCenter.default().removeAllDeliveredNotifications()
289+
NSUserNotificationCenter.default.removeAllDeliveredNotifications()
277290
}
278291

279292
private func logout() {
280293
prefs.loggedIn = false
281294
statusPoller?.invalidate()
282-
let storage = HTTPCookieStorage.shared()
295+
let storage = HTTPCookieStorage.shared
283296
storage.cookies(for: kRedditCookieURL!)?.forEach { storage.deleteCookie($0) }
284297
state = .loggedout
285298
}

0 commit comments

Comments
 (0)