From 4a0bbeacc2740b5b59c2eda04428189ee02fb7b6 Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Thu, 19 Sep 2019 10:38:17 -0500 Subject: [PATCH] Disable Web Inspector for App Store builds - Hide the "Enable Web Inspector" menu item. - #if-out notifications/defaults/etc. - Make toggleWebInspectorEnabled(_) a no-op. --- Mac/AppDefaults.swift | 36 ++++++++++--------- Mac/AppDelegate.swift | 24 ++++++++----- Mac/Base.lproj/Main.storyboard | 3 +- .../Detail/DetailWebViewController.swift | 30 +++++++++------- Shared/AppNotifications.swift | 5 ++- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index 175d75dc8..9df0e52c2 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -37,8 +37,10 @@ struct AppDefaults { static let showTitleOnMainWindow = "KafasisTitleMode" static let hideDockUnreadCount = "JustinMillerHideDockUnreadCount" - static let webInspectorEnabled = "WebInspectorEnabled" - static let webInspectorStartsAttached = "__WebInspectorPageGroupLevel1__.WebKit2InspectorStartsAttached" + #if !MAC_APP_STORE + static let webInspectorEnabled = "WebInspectorEnabled" + static let webInspectorStartsAttached = "__WebInspectorPageGroupLevel1__.WebKit2InspectorStartsAttached" + #endif } private static let smallestFontSizeRawValue = FontSize.small.rawValue @@ -141,23 +143,25 @@ struct AppDefaults { return bool(for: Key.hideDockUnreadCount) } - static var webInspectorEnabled: Bool { - get { - return bool(for: Key.webInspectorEnabled) + #if !MAC_APP_STORE + static var webInspectorEnabled: Bool { + get { + return bool(for: Key.webInspectorEnabled) + } + set { + setBool(for: Key.webInspectorEnabled, newValue) + } } - set { - setBool(for: Key.webInspectorEnabled, newValue) - } - } - static var webInspectorStartsAttached: Bool { - get { - return bool(for: Key.webInspectorStartsAttached) + static var webInspectorStartsAttached: Bool { + get { + return bool(for: Key.webInspectorStartsAttached) + } + set { + setBool(for: Key.webInspectorStartsAttached, newValue) + } } - set { - setBool(for: Key.webInspectorStartsAttached, newValue) - } - } + #endif static var timelineSortDirection: ComparisonResult { get { diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index dd0276976..fcde2aaad 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -42,7 +42,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, @IBOutlet var sortByOldestArticleOnTopMenuItem: NSMenuItem! @IBOutlet var sortByNewestArticleOnTopMenuItem: NSMenuItem! @IBOutlet var checkForUpdatesMenuItem: NSMenuItem! - + @IBOutlet var enableWebInspectorMenuItem: NSMenuItem! + var unreadCount = 0 { didSet { if unreadCount != oldValue { @@ -116,6 +117,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, #if MAC_APP_STORE checkForUpdatesMenuItem.isHidden = true + enableWebInspectorMenuItem.isHidden = true #endif appName = (Bundle.main.infoDictionary!["CFBundleExecutable"]! as! String) @@ -309,9 +311,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, if item.action == #selector(showAddFeedWindow(_:)) || item.action == #selector(showAddFolderWindow(_:)) { return !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty } + #if MAC_APP_STORE if item.action == #selector(toggleWebInspectorEnabled(_:)) { (item as! NSMenuItem).state = AppDefaults.webInspectorEnabled ? .on : .off } + #endif return true } @@ -530,15 +534,17 @@ extension AppDelegate { } @IBAction func toggleWebInspectorEnabled(_ sender: Any?) { - let newValue = !AppDefaults.webInspectorEnabled - AppDefaults.webInspectorEnabled = newValue + #if MAC_APP_STORE + 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 the default to a separate window when the preference is toggled off and on again in case the inspector is - // accidentally reattached. - - AppDefaults.webInspectorStartsAttached = false - NotificationCenter.default.post(name: .WebInspectorEnabledDidChange, object: newValue) + // An attached inspector can display incorrectly on certain setups (like mine); default to displaying in a separate window, + // and reset the default to a separate window when the preference is toggled off and on again in case the inspector is + // accidentally reattached. + + AppDefaults.webInspectorStartsAttached = false + NotificationCenter.default.post(name: .WebInspectorEnabledDidChange, object: newValue) + #endif } } diff --git a/Mac/Base.lproj/Main.storyboard b/Mac/Base.lproj/Main.storyboard index e12b64504..05b2dee53 100644 --- a/Mac/Base.lproj/Main.storyboard +++ b/Mac/Base.lproj/Main.storyboard @@ -473,7 +473,7 @@ - + @@ -588,6 +588,7 @@ + diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index 9e889db4b..4320bfa99 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -28,14 +28,16 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { } } - private var webInspectorEnabled: Bool { - get { - return webView.configuration.preferences._developerExtrasEnabled + #if !MAC_APP_STORE + private var webInspectorEnabled: Bool { + get { + return webView.configuration.preferences._developerExtrasEnabled + } + set { + webView.configuration.preferences._developerExtrasEnabled = newValue + } } - set { - webView.configuration.preferences._developerExtrasEnabled = newValue - } - } + #endif private var waitingForFirstReload = false private let keyboardDelegate = DetailKeyboardDelegate() @@ -96,9 +98,11 @@ final class DetailWebViewController: NSViewController, WKUIDelegate { webView.isHidden = true waitingForFirstReload = true - webInspectorEnabled = AppDefaults.webInspectorEnabled + #if !MAC_APP_STORE + webInspectorEnabled = AppDefaults.webInspectorEnabled - NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil) + #endif reloadHTML() } @@ -199,9 +203,11 @@ private extension DetailWebViewController { } } - @objc func webInspectorEnabledDidChange(_ notification: Notification) { - self.webInspectorEnabled = notification.object! as! Bool - } + #if !MAC_APP_STORE + @objc func webInspectorEnabledDidChange(_ notification: Notification) { + self.webInspectorEnabled = notification.object! as! Bool + } + #endif } // MARK: - ScrollInfo diff --git a/Shared/AppNotifications.swift b/Shared/AppNotifications.swift index 3fd03355a..6f2e8e4bb 100644 --- a/Shared/AppNotifications.swift +++ b/Shared/AppNotifications.swift @@ -13,7 +13,10 @@ 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") + + #if !MAC_APP_STORE + static let WebInspectorEnabledDidChange = Notification.Name("WebInspectorEnabledDidChange") + #endif } typealias UserInfoDictionary = [AnyHashable: Any]