Make a Browser struct with two static methods to replace two top-level functions.
This commit is contained in:
parent
77b01eb72c
commit
4d77dbfd36
|
@ -32,7 +32,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
|
|
||||||
var unreadCount = 0 {
|
var unreadCount = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
dockBadge.update()
|
if unreadCount != oldValue {
|
||||||
|
dockBadge.update()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +105,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
|
|
||||||
func unreadCountDidChange(_ note: Notification) {
|
func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
let updatedUnreadCount = AccountManager.shared.unreadCount
|
unreadCount = AccountManager.shared.unreadCount
|
||||||
if updatedUnreadCount != unreadCount {
|
|
||||||
unreadCount = updatedUnreadCount
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Main Window
|
// MARK: Main Window
|
||||||
|
@ -256,22 +255,22 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
||||||
|
|
||||||
@IBAction func openWebsite(_ sender: AnyObject) {
|
@IBAction func openWebsite(_ sender: AnyObject) {
|
||||||
|
|
||||||
openInBrowser("https://ranchero.com/evergreen/", inBackground: false)
|
Browser.open("//ranchero.com/evergreen/", inBackground: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func openRepository(_ sender: AnyObject) {
|
@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) {
|
@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) {
|
@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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,19 @@ import Foundation
|
||||||
import CoreServices
|
import CoreServices
|
||||||
import RSWeb
|
import RSWeb
|
||||||
|
|
||||||
|
struct Browser {
|
||||||
|
|
||||||
func openInBrowser(_ urlString: String) {
|
static func open(_ urlString: String) {
|
||||||
|
|
||||||
// Opens according to prefs.
|
|
||||||
openInBrowser(urlString, inBackground: AppDefaults.shared.openInBrowserInBackground)
|
|
||||||
}
|
|
||||||
|
|
||||||
func openInBrowser(_ urlString: String, inBackground: Bool) {
|
// Opens according to prefs.
|
||||||
|
open(urlString, inBackground: AppDefaults.shared.openInBrowserInBackground)
|
||||||
if let url = URL(string: urlString) {
|
}
|
||||||
MacWebBrowser.openURL(url, inBackground: inBackground)
|
|
||||||
|
static func open(_ urlString: String, inBackground: Bool) {
|
||||||
|
|
||||||
|
if let url = URL(string: urlString) {
|
||||||
|
MacWebBrowser.openURL(url, inBackground: inBackground)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ class DetailViewController: NSViewController, WKNavigationDelegate, WKUIDelegate
|
||||||
if navigationAction.navigationType == .linkActivated {
|
if navigationAction.navigationType == .linkActivated {
|
||||||
|
|
||||||
if let url = navigationAction.request.url {
|
if let url = navigationAction.request.url {
|
||||||
openInBrowser(url.absoluteString)
|
Browser.open(url.absoluteString)
|
||||||
}
|
}
|
||||||
|
|
||||||
decisionHandler(.cancel)
|
decisionHandler(.cancel)
|
||||||
|
|
|
@ -86,7 +86,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||||
@IBAction func openArticleInBrowser(_ sender: AnyObject?) {
|
@IBAction func openArticleInBrowser(_ sender: AnyObject?) {
|
||||||
|
|
||||||
if let link = currentLink {
|
if let link = currentLink {
|
||||||
openInBrowser(link)
|
Browser.open(link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
|
||||||
@objc func openArticleInBrowser(_ sender: AnyObject) {
|
@objc func openArticleInBrowser(_ sender: AnyObject) {
|
||||||
|
|
||||||
if let link = oneSelectedArticle?.preferredLink {
|
if let link = oneSelectedArticle?.preferredLink {
|
||||||
openInBrowser(link)
|
Browser.open(link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue