Skip to content

Commit 7064683

Browse files
author
Alan Westbrook
committed
Double and persistent notifications
* Move the notification cleaning to a check inside the response parse to avoid any race conditions * Remove the extraneous notification of new mail in the state change handler to avoid double notifications * Persist the number of unread mails to avoid double notifications between sessions * enable the address sanitizer, as it seems like the right thing to do. * Update the version to 2.1
1 parent f1f21b8 commit 7064683

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

Orangered-Swift/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>2.0</string>
20+
<string>2.1</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>6</string>
24+
<string>7</string>
2525
<key>LSApplicationCategoryType</key>
2626
<string>public.app-category.utilities</string>
2727
<key>LSMinimumSystemVersion</key>

Orangered-Swift/StatusItemController.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
9696
fileprivate var prefWindowController:NSWindowController?
9797
fileprivate var mailboxItem:NSMenuItem?
9898
fileprivate var loginItem:NSMenuItem?
99-
fileprivate var mailCount = 0
99+
fileprivate var mailCount:Int {
100+
get {
101+
return prefs.mailCount
102+
}
103+
set {
104+
prefs.mailCount = newValue
105+
}
106+
}
100107

101108
override init() {
102109
super.init()
@@ -279,6 +286,10 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
279286
if mailCount > 0 {
280287
notifyMail()
281288
}
289+
else {
290+
// We had mail, and now we don't. Safe to assume it's all been read.
291+
NSUserNotificationCenter.default.removeAllDeliveredNotifications()
292+
}
282293
}
283294
}
284295

@@ -306,10 +317,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
306317
mailboxItem?.isEnabled = true
307318
loginItem?.title = prefs.loggedIn ? kLogoutMenuTitle : kLoginMenuTitle
308319

309-
switch state {
310-
case .orangered, .modmail:
311-
notifyMail()
312-
320+
switch state {
313321
case .disconnected:
314322
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 10, execute: {
315323
self.login()
@@ -319,7 +327,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
319327
mailboxItem?.isEnabled = false
320328

321329

322-
case .mailfree, .update:
330+
case .orangered, .modmail, .mailfree, .update:
323331
break
324332
}
325333
}
@@ -341,6 +349,7 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
341349
mailCount)
342350
}
343351

352+
print("notifying")
344353
NSUserNotificationCenter.default.deliver(note)
345354
}
346355

@@ -349,11 +358,10 @@ class StatusItemController: NSObject, NSUserNotificationCenterDelegate {
349358
NSWorkspace.shared().open(url)
350359
}
351360

361+
// There's no reasonable way to know when reddit has cleared the unread flag, so we just wait a bit and check again.
352362
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + kOpenMailboxRecheckDelay) {
353363
self.checkReddit()
354364
}
355-
356-
NSUserNotificationCenter.default.removeAllDeliveredNotifications()
357365
}
358366

359367
private func logout() {

Orangered-Swift/UserDefaults+Orangered.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Cocoa
1212
private let kUserNameKey = "username"
1313
private let kLoggedInKey = "logged in"
1414
private let kUseAltImagesKey = "use alt images"
15+
private let kMailCountKey = "unread inbox count"
1516
private let kServiceName = "Orangered!"
1617

1718
extension UserDefaults {
@@ -53,6 +54,15 @@ extension UserDefaults {
5354
}
5455
}
5556

57+
var mailCount:Int {
58+
get {
59+
return integer(forKey: kMailCountKey)
60+
}
61+
set {
62+
set(newValue, forKey: kMailCountKey)
63+
}
64+
}
65+
5666
// C APIs are *the worst*
5767
static fileprivate var keychainItem:SecKeychainItem? = nil
5868

Orangered.xcodeproj/xcshareddata/xcschemes/Orangered.xcscheme

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
useCustomWorkingDirectory = "NO"
5050
ignoresPersistentStateOnLaunch = "NO"
5151
debugDocumentVersioning = "YES"
52+
enableAddressSanitizer = "YES"
5253
debugServiceExtension = "internal"
5354
allowLocationSimulation = "YES">
5455
<BuildableProductRunnable
@@ -62,16 +63,6 @@
6263
</BuildableReference>
6364
</BuildableProductRunnable>
6465
<AdditionalOptions>
65-
<AdditionalOption
66-
key = "MallocStackLogging"
67-
value = ""
68-
isEnabled = "YES">
69-
</AdditionalOption>
70-
<AdditionalOption
71-
key = "MallocScribble"
72-
value = ""
73-
isEnabled = "YES">
74-
</AdditionalOption>
7566
</AdditionalOptions>
7667
</LaunchAction>
7768
<ProfileAction

0 commit comments

Comments
 (0)