diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index 4dbb0eafc..f6cd38a7d 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -32,7 +32,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { var unreadCount = 0 { didSet { - dockBadge.update() + if unreadCount != oldValue { + dockBadge.update() + } } } @@ -103,10 +105,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { func unreadCountDidChange(_ note: Notification) { - let updatedUnreadCount = AccountManager.shared.unreadCount - if updatedUnreadCount != unreadCount { - unreadCount = updatedUnreadCount - } + unreadCount = AccountManager.shared.unreadCount } // MARK: Main Window @@ -256,22 +255,22 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { @IBAction func openWebsite(_ sender: AnyObject) { - openInBrowser("https://ranchero.com/evergreen/", inBackground: false) + Browser.open("//ranchero.com/evergreen/", inBackground: false) } @IBAction func openRepository(_ sender: AnyObject) { - openInBrowser("https://github.com/brentsimmons/Evergreen", inBackground: false) + Browser.open("https://github.com/brentsimmons/Evergreen", inBackground: false) } @IBAction func openBugTracker(_ sender: AnyObject) { - openInBrowser("https://github.com/brentsimmons/Evergreen/issues", inBackground: false) + Browser.open("https://github.com/brentsimmons/Evergreen/issues", inBackground: false) } @IBAction func showHelp(_ sender: AnyObject) { - openInBrowser("https://ranchero.com/evergreen/help/1.0/", inBackground: false) + Browser.open("https://ranchero.com/evergreen/help/1.0/", inBackground: false) } } diff --git a/Evergreen/Browser.swift b/Evergreen/Browser.swift index 7f53aef80..81e21cb93 100644 --- a/Evergreen/Browser.swift +++ b/Evergreen/Browser.swift @@ -10,17 +10,19 @@ import Foundation import CoreServices import RSWeb +struct Browser { -func openInBrowser(_ urlString: String) { - - // Opens according to prefs. - openInBrowser(urlString, inBackground: AppDefaults.shared.openInBrowserInBackground) -} + static func open(_ urlString: String) { -func openInBrowser(_ urlString: String, inBackground: Bool) { - - if let url = URL(string: urlString) { - MacWebBrowser.openURL(url, inBackground: inBackground) + // Opens according to prefs. + open(urlString, inBackground: AppDefaults.shared.openInBrowserInBackground) + } + + static func open(_ urlString: String, inBackground: Bool) { + + if let url = URL(string: urlString) { + MacWebBrowser.openURL(url, inBackground: inBackground) + } } } diff --git a/Evergreen/MainWindow/Detail/DetailViewController.swift b/Evergreen/MainWindow/Detail/DetailViewController.swift index 281d72028..e69bad5dd 100644 --- a/Evergreen/MainWindow/Detail/DetailViewController.swift +++ b/Evergreen/MainWindow/Detail/DetailViewController.swift @@ -86,7 +86,7 @@ class DetailViewController: NSViewController, WKNavigationDelegate, WKUIDelegate if navigationAction.navigationType == .linkActivated { if let url = navigationAction.request.url { - openInBrowser(url.absoluteString) + Browser.open(url.absoluteString) } decisionHandler(.cancel) diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index 37aeeb449..479261ead 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -86,7 +86,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { @IBAction func openArticleInBrowser(_ sender: AnyObject?) { if let link = currentLink { - openInBrowser(link) + Browser.open(link) } } diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 0940527ee..39e892fc3 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -133,7 +133,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView @objc func openArticleInBrowser(_ sender: AnyObject) { if let link = oneSelectedArticle?.preferredLink { - openInBrowser(link) + Browser.open(link) } }