From e6a25f374a2dc64997234248343621d1ad3de909 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 18 Jun 2023 15:53:37 -0700 Subject: [PATCH] Show Reddit deprecation alert if needed. --- Mac/AppDefaults.swift | 9 +++++++ Mac/AppDelegate.swift | 56 +++++++++++++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index c169c76a9..7c910ca42 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -43,6 +43,7 @@ final class AppDefaults { static let defaultBrowserID = "defaultBrowserID" static let currentThemeName = "currentThemeName" static let twitterDeprecationAlertShown = "twitterDeprecationAlertShown" + static let redditDeprecationAlertShown = "redditDeprecationAlertShown" // Hidden prefs static let showDebugMenu = "ShowDebugMenu" @@ -319,6 +320,14 @@ final class AppDefaults { } } + var redditDeprecationAlertShown: Bool { + get { + return AppDefaults.bool(for: Key.redditDeprecationAlertShown) + } + set { + AppDefaults.setBool(for: Key.redditDeprecationAlertShown, newValue) + } + } func registerDefaults() { #if DEBUG diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index d94bb544b..6d9451e1f 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -133,7 +133,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, appDelegate = self - presentTwitterDeprecationAlertIfRequired() + if shouldShowTwitterDeprecationAlert() { + showTwitterDeprecationAlert() + } + else if shouldShowRedditDeprecationAlert() { + showRedditDeprecationAlert() + } } // MARK: - API @@ -953,23 +958,23 @@ internal extension AppDelegate { alert.runModal() } } - - 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 @@ -980,7 +985,34 @@ internal extension AppDelegate { 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 ExtensionPointManager.shared.isRedditEnabled + } + + 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 announced the end of free access to their API, effective July 1.\n\nThough Reddit does provide RSS feeds, we use the Reddit API to get more and better data. But, without free access to that API, we will stop using it on June 30, 2023.\n\nWe’ve left your Reddit feeds intact. If you have any starred items from those feeds, they will remain as long as you don’t delete those feeds.\n\nYou can still read whatever you have already downloaded.\n\nAlso, importantly — after you remove Reddit from your extensions in NetNewsWire, you can add Reddit RSS feeds and those feeds will continue to update.", comment: "Reddit deprecation message") + alert.addButton(withTitle: NSLocalizedString("OK", comment: "OK")) + alert.buttons[0].keyEquivalent = "\r" + alert.runModal() + } + } + @objc func openThemesFolder(_ sender: Any) { if themeImportPath == nil { let url = URL(fileURLWithPath: ArticleThemesManager.shared.folderPath)