mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-23 16:20:53 +01:00
Add a menu item to the Debug menu to enable the Web Inspector
Just enables the "Inspect Element" item in a WKWebView's contextual menu at the moment.
This commit is contained in:
parent
66d9333999
commit
e39fa31bf7
@ -36,6 +36,8 @@ struct AppDefaults {
|
||||
static let timelineShowsSeparators = "CorreiaSeparators"
|
||||
static let showTitleOnMainWindow = "KafasisTitleMode"
|
||||
static let hideDockUnreadCount = "JustinMillerHideDockUnreadCount"
|
||||
|
||||
static let webInspectorEnabled = "WebInspectorEnabled"
|
||||
}
|
||||
|
||||
private static let smallestFontSizeRawValue = FontSize.small.rawValue
|
||||
@ -138,6 +140,15 @@ struct AppDefaults {
|
||||
return bool(for: Key.hideDockUnreadCount)
|
||||
}
|
||||
|
||||
static var webInspectorEnabled: Bool {
|
||||
get {
|
||||
return bool(for: Key.webInspectorEnabled)
|
||||
}
|
||||
set {
|
||||
setBool(for: Key.webInspectorEnabled, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static var timelineSortDirection: ComparisonResult {
|
||||
get {
|
||||
return sortDirection(for: Key.timelineSortDirection)
|
||||
|
@ -309,6 +309,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
if item.action == #selector(showAddFeedWindow(_:)) || item.action == #selector(showAddFolderWindow(_:)) {
|
||||
return !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty
|
||||
}
|
||||
if item.action == #selector(toggleWebInspectorEnabled(_:)) {
|
||||
(item as! NSMenuItem).state = AppDefaults.webInspectorEnabled ? .on : .off
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -525,6 +528,15 @@ extension AppDelegate {
|
||||
@IBAction func debugSearch(_ sender: Any?) {
|
||||
AccountManager.shared.defaultAccount.debugRunSearch()
|
||||
}
|
||||
|
||||
@IBAction func toggleWebInspectorEnabled(_ sender: Any?) {
|
||||
let newValue = !AppDefaults.webInspectorEnabled
|
||||
AppDefaults.webInspectorEnabled = newValue
|
||||
// An attached inspector can display incorrectly on certain setups (like mine); default to displaying in a separate window,
|
||||
// And reset to a separate window when the preference is toggled off and on again in case the inspector is accidentally reattached.
|
||||
UserDefaults.standard.set(false, forKey: "__WebInspectorPageGroupLevel1__.WebKit2InspectorStartsAttached")
|
||||
NotificationCenter.default.post(name: .WebInspectorEnabledDidChange, object: newValue)
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppDelegate {
|
||||
|
@ -469,6 +469,13 @@
|
||||
<action selector="debugSearch:" target="Ady-hI-5gd" id="HvM-F7-u7s"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="OOI-Hk-eqi"/>
|
||||
<menuItem title="Enable Web Inspector" id="EwI-z4-ZA3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleWebInspectorEnabled:" target="Voe-Tx-rLC" id="nsd-PV-Tz2"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
|
@ -27,6 +27,22 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var webInspectorEnabled: Bool {
|
||||
get {
|
||||
if let webView = webView {
|
||||
let val: NSNumber? = webView.configuration.preferences.value(forKey: "developerExtrasEnabled") as? NSNumber
|
||||
return val != nil ? val!.boolValue : false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
set {
|
||||
if let webView = webView {
|
||||
webView.configuration.preferences.setValue(newValue, forKey: "developerExtrasEnabled")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var waitingForFirstReload = false
|
||||
private let keyboardDelegate = DetailKeyboardDelegate()
|
||||
@ -87,6 +103,12 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
|
||||
webView.isHidden = true
|
||||
waitingForFirstReload = true
|
||||
|
||||
webInspectorEnabled = AppDefaults.webInspectorEnabled
|
||||
|
||||
NotificationCenter.default.addObserver(forName: .WebInspectorEnabledDidChange, object: nil, queue: OperationQueue.main) { (notification) in
|
||||
self.webInspectorEnabled = notification.object! as! Bool
|
||||
}
|
||||
|
||||
reloadHTML()
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ extension Notification.Name {
|
||||
static let InspectableObjectsDidChange = Notification.Name("TimelineSelectionDidChangeNotification")
|
||||
static let UserDidAddFeed = Notification.Name("UserDidAddFeedNotification")
|
||||
static let UserDidRequestSidebarSelection = Notification.Name("UserDidRequestSidebarSelectionNotification")
|
||||
static let WebInspectorEnabledDidChange = Notification.Name("WebInspectorEnabledDidChange")
|
||||
}
|
||||
|
||||
typealias UserInfoDictionary = [AnyHashable: Any]
|
||||
|
Loading…
Reference in New Issue
Block a user