NetNewsWire/Mac/Browser.swift

38 lines
1.0 KiB
Swift
Raw Normal View History

2017-05-26 22:22:31 +02:00
//
// Browser.swift
// Evergren
//
// Created by Brent Simmons on 2/23/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import AppKit
2017-05-26 22:22:31 +02:00
import RSWeb
struct Browser {
2017-05-26 22:22:31 +02:00
static func open(_ urlString: String) {
let shouldInvertPreference = NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false
// Opens according to prefs.
open(urlString, inBackground: shouldInvertPreference ? !AppDefaults.openInBrowserInBackground : AppDefaults.openInBrowserInBackground)
}
static func open(_ urlString: String, inBackground: Bool) {
if let url = URL(string: urlString) {
MacWebBrowser.openURL(url, inBackground: inBackground)
}
2017-05-26 22:22:31 +02:00
}
}
extension Browser {
static var titleForOpenInBrowserInverted: String {
let openInBackgroundPref = AppDefaults.openInBrowserInBackground
return openInBackgroundPref ?
NSLocalizedString("Open in Browser in Foreground", comment: "Open in Browser in Foreground menu item title") :
NSLocalizedString("Open in Browser in Background", comment: "Open in Browser in Background menu item title")
}
}