From be89df884ddddadf5cada0ccaf2c0fb4bd74a2b9 Mon Sep 17 00:00:00 2001 From: Jim Correia Date: Sun, 6 Oct 2019 17:56:53 -0700 Subject: [PATCH] The Debug menu can now be enabled in release builds. `defaults write com.ranchero.NetNewsWire-Evergreen ShowDebugMenu -bool YES` Toggling the Web Inspector uses SPI, so it's always excluded from the Debug menu when building for the Mac App Store. --- Mac/AppDefaults.swift | 22 +++++++++++++++++++++- Mac/AppDelegate.swift | 23 ++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index 9df0e52c2..2eaade629 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -33,6 +33,7 @@ struct AppDefaults { static let exportOPMLAccountID = "exportOPMLAccountID" // Hidden prefs + static let showDebugMenu = "ShowDebugMenu" static let timelineShowsSeparators = "CorreiaSeparators" static let showTitleOnMainWindow = "KafasisTitleMode" static let hideDockUnreadCount = "JustinMillerHideDockUnreadCount" @@ -142,6 +143,10 @@ struct AppDefaults { static var hideDockUnreadCount: Bool { return bool(for: Key.hideDockUnreadCount) } + + static var showDebugMenu: Bool { + return bool(for: Key.showDebugMenu) + } #if !MAC_APP_STORE static var webInspectorEnabled: Bool { @@ -196,7 +201,22 @@ struct AppDefaults { } static func registerDefaults() { - let defaults: [String : Any] = [Key.lastImageCacheFlushDate: Date(), Key.sidebarFontSize: FontSize.medium.rawValue, Key.timelineFontSize: FontSize.medium.rawValue, Key.detailFontSize: FontSize.medium.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, "NSScrollViewShouldScrollUnderTitlebar": false, Key.refreshInterval: RefreshInterval.everyHour.rawValue] + #if DEBUG + let showDebugMenu = true + #else + let showDebugMenu = false + #endif + + let defaults: [String : Any] = [ + Key.lastImageCacheFlushDate: Date(), + Key.sidebarFontSize: FontSize.medium.rawValue, + Key.timelineFontSize: FontSize.medium.rawValue, + Key.detailFontSize: FontSize.medium.rawValue, + Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, + "NSScrollViewShouldScrollUnderTitlebar": false, + Key.refreshInterval: RefreshInterval.everyHour.rawValue, + Key.showDebugMenu: showDebugMenu, + ] UserDefaults.standard.register(defaults: defaults) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 581126f56..81fbddd7d 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -175,18 +175,25 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, refreshTimer = AccountRefreshTimer() syncTimer = ArticleStatusSyncTimer() - #if RELEASE + if AppDefaults.showDebugMenu { + refreshTimer!.update() + syncTimer!.update() + + // The Web Inspector uses SPI and can never appear in a MAC_APP_STORE build. + #if MAC_APP_STORE + let debugMenu = debugMenuItem.submenu! + let toggleWebInspectorItemIndex = debugMenu.indexOfItem(withTarget: self, andAction: #selector(toggleWebInspectorEnabled(_:))) + if toggleWebInspectorItemIndex != -1 { + debugMenu.removeItem(at: toggleWebInspectorItemIndex) + } + #endif + } else { debugMenuItem.menu?.removeItem(debugMenuItem) DispatchQueue.main.async { self.refreshTimer!.timedRefresh(nil) self.syncTimer!.timedRefresh(nil) } - #endif - - #if DEBUG - refreshTimer!.update() - syncTimer!.update() - #endif + } #if !MAC_APP_STORE DispatchQueue.main.async { @@ -309,11 +316,13 @@ 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 }