Skip to content

Commit 4d2cb56

Browse files
authored
Add a debug menu to launch the in-app web browser (#25043)
1 parent 338a68c commit 4d2cb56

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

WordPress/Classes/ViewRelated/Me/App Settings/DebugMenuViewController.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import TipKit
88

99
struct DebugMenuView: View {
1010
@StateObject private var viewModel = DebugMenuViewModel()
11+
@State private var isShowingWebViewURLDialog = false
12+
@State private var webViewURL = ""
1113

1214
fileprivate var navigation: NavigationContext
1315

@@ -16,13 +18,26 @@ struct DebugMenuView: View {
1618
Section { main }
1719
Section(Strings.sectionSettings) { settings }
1820
Section(Strings.sectionTipKit) { tipKit }
21+
Section(Strings.sectionWebView) { webView }
1922
Section(Strings.sectionLogging) { logging }
2023
}
2124
.toolbar {
2225
ToolbarItem(placement: .principal) {
2326
(Text(Image(systemName: "bolt.fill")).foregroundColor(.yellow) + Text(" " + Strings.title)).font(.headline)
2427
}
2528
}
29+
.alert(Strings.webViewDialogTitle, isPresented: $isShowingWebViewURLDialog) {
30+
TextField("https://example.com", text: $webViewURL)
31+
.keyboardType(.URL)
32+
.textContentType(.URL)
33+
.textInputAutocapitalization(.never)
34+
.autocorrectionDisabled()
35+
Button(SharedStrings.Button.cancel, role: .cancel) {
36+
}
37+
Button(SharedStrings.Button.view) {
38+
presentAuthenticatedWebView()
39+
}
40+
}
2641
}
2742

2843
@ViewBuilder private var main: some View {
@@ -68,6 +83,13 @@ struct DebugMenuView: View {
6883
}
6984
}
7085

86+
@ViewBuilder private var webView: some View {
87+
Button(Strings.webViewRow) {
88+
webViewURL = Blog.lastUsed(in: ContextManager.shared.mainContext)?.url ?? ""
89+
isShowingWebViewURLDialog = true
90+
}
91+
}
92+
7193
@ViewBuilder private var logging: some View {
7294
Button(Strings.sendLogMessage) {
7395
WordPressAppDelegate.crashLogging?.logMessage("Debug Log Message \(UUID().uuidString)")
@@ -95,6 +117,25 @@ struct DebugMenuView: View {
95117
Toggle(Strings.alwaysSendLogs, isOn: $viewModel.isForcedCrashLoggingEnabled)
96118
}
97119

120+
private func presentAuthenticatedWebView() {
121+
guard let url = URL(string: webViewURL) else {
122+
preconditionFailure("Invalid URL")
123+
return
124+
}
125+
126+
guard let currentBlog = Blog.lastUsed(in: ContextManager.shared.mainContext) else {
127+
preconditionFailure("Can't get current blog")
128+
return
129+
}
130+
131+
let webViewController = WebViewControllerFactory.controller(
132+
url: url,
133+
blog: currentBlog,
134+
source: "debug_menu"
135+
)
136+
navigation.push(webViewController)
137+
}
138+
98139
private var readerSettings: some View {
99140
let viewController = SettingsTextViewController(text: ReaderCSS().customAddress, placeholder: Strings.readerURLPlaceholder, hint: Strings.readerURLHint)
100141
viewController.title = Strings.readerCssTitle
@@ -201,6 +242,7 @@ private enum Strings {
201242
static let sectionSettings = NSLocalizedString("debugMenu.section.settings", value: "Settings", comment: "Debug Menu section title")
202243
static let sectionLogging = NSLocalizedString("debugMenu.section.logging", value: "Logging", comment: "Debug Menu section title")
203244
static let sectionTipKit = NSLocalizedString("debugMenu.section.tipKit", value: "TipKit", comment: "Debug Menu section title")
245+
static let sectionWebView = NSLocalizedString("debugMenu.section.webView", value: "Web View", comment: "Debug Menu section title")
204246
static let sandboxStoreCookieSecretRow = NSLocalizedString("Sandbox Store", comment: "Title of a row displayed on the debug screen used to configure the sandbox store use in the App.")
205247
static let sendTestCrash = NSLocalizedString("Send Test Crash", comment: "Title of a row displayed on the debug screen used to crash the app and send a crash report to the crash logging provider to ensure everything is working correctly")
206248
static let sendLogMessage = NSLocalizedString("Send Log Message", comment: "Title of a row displayed on the debug screen used to send a pretend error message to the crash logging provider to ensure everything is working correctly")
@@ -214,6 +256,8 @@ private enum Strings {
214256
static let featureFlags = NSLocalizedString("debugMenu.featureFlags", value: "Feature Flags", comment: "Feature flags menu item")
215257
static let weeklyRoundup = NSLocalizedString("debugMenu.weeklyRoundup", value: "Weekly Roundup", comment: "Weekly Roundup debug menu item")
216258
static let booleanUserDefaults = NSLocalizedString("debugMenu.booleanUserDefaults", value: "Boolean User Defaults", comment: "Boolean User Defaults debug menu item")
259+
static let webViewRow = NSLocalizedString("debugMenu.webView.row", value: "Browse as loggedin account", comment: "Debug menu item to present an authenticated web view for the currently displayed site")
260+
static let webViewDialogTitle = NSLocalizedString("debugMenu.webView.dialogTitle", value: "Enter URL", comment: "Title for web view URL input dialog")
217261

218262
static let showAllTips = NSLocalizedString("debugMenu.showAllTips", value: "Show All Tips", comment: "Debug Menu action for TipKit")
219263
static let hideAllTips = NSLocalizedString("debugMenu.hideAllTips", value: "Hide All Tips", comment: "Debug Menu action for TipKit")

0 commit comments

Comments
 (0)