Skip to content

Commit

Permalink
Show Reddit deprecation alert if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentsimmons committed Jun 18, 2023
1 parent 21ee966 commit e6a25f3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Mac/AppDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
56 changes: 44 additions & 12 deletions Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,

appDelegate = self

presentTwitterDeprecationAlertIfRequired()
if shouldShowTwitterDeprecationAlert() {
showTwitterDeprecationAlert()
}
else if shouldShowRedditDeprecationAlert() {
showRedditDeprecationAlert()
}
}

// MARK: - API
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e6a25f3

Please sign in to comment.