Add Reddit deprecation alert code for Mac.

This commit is contained in:
Brent Simmons
2023-07-02 15:19:08 -07:00
parent d4092b21fd
commit e2d88bbd33
2 changed files with 55 additions and 13 deletions

View File

@@ -43,6 +43,7 @@ final class AppDefaults {
static let currentThemeName = "currentThemeName"
static let hasSeenNotAllArticlesHaveURLsAlert = "hasSeenNotAllArticlesHaveURLsAlert"
static let twitterDeprecationAlertShown = "twitterDeprecationAlertShown"
static let redditDeprecationAlertShown = "redditDeprecationAlertShown"
static let markArticlesAsReadOnScroll = "markArticlesAsReadOnScroll"
// Hidden prefs
@@ -320,6 +321,15 @@ final class AppDefaults {
}
}
var redditDeprecationAlertShown: Bool {
get {
return AppDefaults.bool(for: Key.redditDeprecationAlertShown)
}
set {
AppDefaults.setBool(for: Key.redditDeprecationAlertShown, newValue)
}
}
var markArticlesAsReadOnScroll: Bool {
get {
return AppDefaults.bool(for: Key.markArticlesAsReadOnScroll)

View File

@@ -131,7 +131,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
appDelegate = self
presentTwitterDeprecationAlertIfRequired()
if shouldShowTwitterDeprecationAlert() {
showTwitterDeprecationAlert()
}
else if shouldShowRedditDeprecationAlert() {
showRedditDeprecationAlert()
}
}
// MARK: - API
@@ -941,28 +946,55 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
alert.beginSheetModal(for: window)
}
private func presentTwitterDeprecationAlertIfRequired() {
if AppDefaults.shared.twitterDeprecationAlertShown { return }
private func shouldShowTwitterDeprecationAlert() -> Bool {
if AppDefaults.shared.twitterDeprecationAlertShown { return false }
let expiryDate = Date(timeIntervalSince1970: 1691539200) // August 9th 2023, 00:00 UTC
let currentDate = Date()
if currentDate > expiryDate {
return // If after August 9th, don't show
return false // If after August 9th, don't show
}
if AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneTwitterFeed() {
showTwitterDeprecationAlert()
}
AppDefaults.shared.twitterDeprecationAlertShown = true
return AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneTwitterFeed()
}
private func showTwitterDeprecationAlert() {
assert(shouldShowTwitterDeprecationAlert())
AppDefaults.shared.twitterDeprecationAlertShown = true
DispatchQueue.main.async {
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("alert.title.twitter-integration-removed", comment: "Twitter Integration Removed")
alert.informativeText = NSLocalizedString("alert.message.twitter-integration-removed", comment: "Twitter deprecation informative text.")
alert.addButton(withTitle: NSLocalizedString("button.title.ok", comment: "OK"))
alert.messageText = NSLocalizedString("Twitter Integration Removed", comment: "Twitter Integration Removed")
alert.informativeText = NSLocalizedString("Twitter has ended free access to the parts of the Twitter API that we need.\n\nSince Twitter does not provide RSS feeds, weve had to use the Twitter API. Without free access to that API, we cant read feeds from Twitter.\n\nWeve left your Twitter feeds intact. If you have any starred items from those feeds, they will remain as long as you dont delete those feeds.\n\nYou can still read whatever you have already downloaded. However, those feeds will no longer update.", comment: "Twitter deprecation informative text.")
alert.addButton(withTitle: NSLocalizedString("OK", comment: "OK"))
alert.buttons[0].keyEquivalent = "\r"
alert.runModal()
}
}
private func shouldShowRedditDeprecationAlert() -> Bool {
if AppDefaults.shared.redditDeprecationAlertShown { return false }
let expiryDate = Date(timeIntervalSince1970: 1701331200) // Thu Nov 30 2023 00:00:00 GMT-0800 (Pacific Standard Time)
let currentDate = Date()
if currentDate > expiryDate {
return false
}
return AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneRedditAPIFeed()
}
private func showRedditDeprecationAlert() {
assert(shouldShowRedditDeprecationAlert())
AppDefaults.shared.redditDeprecationAlertShown = true
DispatchQueue.main.async {
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("Reddit API Integration Removed", comment: "Reddit API Integration Removed")
alert.informativeText = NSLocalizedString("Reddit has ended free access to their API.\n\nThough Reddit does provide RSS feeds, we used the Reddit API to get more and better data. But, without free access to that API, we have had to stop using it.\n\nWeve left your Reddit feeds intact. If you have any starred items from those feeds, they will remain as long as you dont delete those feeds.\n\nYou can still read whatever you have already downloaded.\n\nAlso, importantly — Reddit still provides RSS feeds, and you can follow Reddit activity through RSS.", comment: "Reddit deprecation message")
alert.addButton(withTitle: NSLocalizedString("OK", comment: "OK"))
alert.buttons[0].keyEquivalent = "\r"
alert.runModal()
}