Shows Twitter deprecation alert on macOS

This commit is contained in:
Stuart Breckenridge committed 2023-02-05 09:40:41 +08:00
1 parent 6c1e1ea1c6
commit da91548875
2 files changed
+53

No files matched your search

+11
View File
@@ -42,6 +42,7 @@ final class AppDefaults {
static let exportOPMLAccountID = "exportOPMLAccountID"
static let defaultBrowserID = "defaultBrowserID"
static let currentThemeName = "currentThemeName"
static let twitterDeprecationAlertShown = "twitterDeprecationAlertShown"
// Hidden prefs
static let showDebugMenu = "ShowDebugMenu"
@@ -308,6 +309,16 @@ final class AppDefaults {
UserDefaults.standard.set(newValue.rawValue, forKey: Key.refreshInterval)
}
}
var twitterDeprecationAlertShown: Bool {
get {
return AppDefaults.bool(for: Key.twitterDeprecationAlertShown)
}
set {
AppDefaults.setBool(for: Key.twitterDeprecationAlertShown, newValue)
}
}
func registerDefaults() {
#if DEBUG
+42
View File
@@ -132,6 +132,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(didWakeNotification(_:)), name: NSWorkspace.didWakeNotification, object: nil)
appDelegate = self
presentTwitterDeprecationAlertIfRequired()
}
// MARK: - API
@@ -952,6 +954,46 @@ internal extension AppDelegate {
}
}
private func presentTwitterDeprecationAlertIfRequired() {
if AppDefaults.shared.twitterDeprecationAlertShown { return }
let expiryDate = Date(timeIntervalSince1970: 1691539200).timeIntervalSince1970 // August 9th 2023, 00:00 UTC
let currentDate = Date().timeIntervalSince1970
if currentDate > expiryDate {
return // If after August 9th, don't show
}
var twitterIsActive: Bool = false
AccountManager.shared.accounts.forEach({ account in
account.flattenedWebFeeds().forEach({ webfeed in
guard let components = URLComponents(string: webfeed.url),
let host = components.host else {
return
}
if host == "twitter.com" {
twitterIsActive = true
return
}
})
})
if twitterIsActive {
showTwitterDeprecationAlert()
}
AppDefaults.shared.twitterDeprecationAlertShown = true
}
private func showTwitterDeprecationAlert() {
DispatchQueue.main.async {
let alert = NSAlert()
alert.alertStyle = .warning
alert.messageText = NSLocalizedString("Twitter Integration Removed", comment: "Twitter Integration Removed")
alert.informativeText = NSLocalizedString("On February 1, 2023, Twitter announced the end of free access to the Twitter API, effective February 9.\n\nSince Twitter does not provide RSS feeds, we’ve had to use the Twitter API. Without free access to that API, we can’t read feeds from Twitter.\n\nWe’ve left your Twitter 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. 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()
}
}
@objc func openThemesFolder(_ sender: Any) {
if themeImportPath == nil {
let url = URL(fileURLWithPath: ArticleThemesManager.shared.folderPath)