Make a Browser struct with two static methods to replace two top-level functions.

This commit is contained in:
Brent Simmons 2017-10-05 18:12:58 -07:00
parent 77b01eb72c
commit 4d77dbfd36
5 changed files with 22 additions and 21 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}
}

View File

@ -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)

View File

@ -86,7 +86,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
@IBAction func openArticleInBrowser(_ sender: AnyObject?) {
if let link = currentLink {
openInBrowser(link)
Browser.open(link)
}
}

View File

@ -133,7 +133,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
@objc func openArticleInBrowser(_ sender: AnyObject) {
if let link = oneSelectedArticle?.preferredLink {
openInBrowser(link)
Browser.open(link)
}
}