Add defaultBrowserID user default and make the appropriate toolbar item use that browser's icon
This commit is contained in:
parent
b8220d3a9c
commit
0c2d057860
|
@ -33,6 +33,7 @@ struct AppDefaults {
|
|||
static let addFolderAccountID = "addFolderAccountID"
|
||||
static let importOPMLAccountID = "importOPMLAccountID"
|
||||
static let exportOPMLAccountID = "exportOPMLAccountID"
|
||||
static let defaultBrowserID = "defaultBrowserID"
|
||||
|
||||
// Hidden prefs
|
||||
static let showDebugMenu = "ShowDebugMenu"
|
||||
|
@ -172,6 +173,15 @@ struct AppDefaults {
|
|||
}
|
||||
}
|
||||
|
||||
static var defaultBrowserID: String? {
|
||||
get {
|
||||
return string(for: Key.defaultBrowserID)
|
||||
}
|
||||
set {
|
||||
setString(for: Key.defaultBrowserID, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static var showTitleOnMainWindow: Bool {
|
||||
return bool(for: Key.showTitleOnMainWindow)
|
||||
}
|
||||
|
|
|
@ -93,6 +93,8 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
DispatchQueue.main.async {
|
||||
self.updateWindowTitle()
|
||||
}
|
||||
|
||||
defaultBrowserDidChange(nil)
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
|
@ -168,6 +170,36 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
|
||||
}
|
||||
|
||||
@objc func defaultBrowserDidChange(_ note: Notification?) {
|
||||
guard let item = self.window?.toolbar?.items.first(where: { $0.action == #selector(openArticleInBrowser(_:)) }) else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let button = item.view as? NSButton else { return }
|
||||
|
||||
var browserName = NSLocalizedString("Browser", comment: "Browser")
|
||||
var icon = NSImage(named: "openInBrowser")!
|
||||
|
||||
var currentBrowser: MacWebBrowser?
|
||||
|
||||
if let browserID = AppDefaults.defaultBrowserID {
|
||||
currentBrowser = MacWebBrowser(bundleIdentifier: browserID)
|
||||
} else {
|
||||
currentBrowser = MacWebBrowser.default
|
||||
}
|
||||
|
||||
if let currentBrowser = currentBrowser {
|
||||
icon = currentBrowser.icon!
|
||||
icon.size = NSSize(width: 16.0, height: 16.0)
|
||||
browserName = currentBrowser.name!
|
||||
}
|
||||
|
||||
button.image = icon
|
||||
|
||||
let format = NSLocalizedString("Open in $@", comment: "Open in Browser toolbar item tooltip format")
|
||||
item.toolTip = String(format: format, browserName)
|
||||
}
|
||||
|
||||
// MARK: - Toolbar
|
||||
|
||||
@objc func makeToolbarValidate() {
|
||||
|
|
Loading…
Reference in New Issue