From 6e5fc656a35b0559f47660cc7eeaed5a8644fee7 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 27 May 2021 10:16:48 -0400 Subject: [PATCH 1/3] Remove editor check from UBE Fixes https://github.com/wordpress-mobile/gutenberg-mobile/issues/3425 The `/sites/{site_id}/gutenberg` endpoint is unreliable (see https://github.com/wordpress-mobile/gutenberg-mobile/issues/3425#issuecomment-840223555) but was being used to disable the UBE on sites where gutenberg was unavailable. Since most users will have gutenberg enabled in this scenario, it makes sense to remove usage of this API endpoint and just show a failure state if gutenberg is unavailable. The failure state will show information on how to fix the error (i.e. enable gutenberg on the site). --- .../Gutenberg/GutenbergViewController.swift | 2 +- .../GutenbergWebViewController.swift | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift index 21d39d9264b3..522201dd15c8 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift @@ -1063,7 +1063,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource { let blog = post.blog let isJetpackSSOEnabled = (blog.jetpack?.isConnected ?? false) && (blog.settings?.jetpackSSOEnabled ?? false) - return blog.isHostedAtWPcom || (isJetpackSSOEnabled && blog.webEditor == .gutenberg) + return blog.isHostedAtWPcom || isJetpackSSOEnabled } } diff --git a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift index 4745e35ad97a..7f768abc4cdc 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift @@ -2,7 +2,7 @@ import UIKit import WebKit import Gutenberg -class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitAuthenticatable { +class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitAuthenticatable, NoResultsViewHost { enum GutenbergWebError: Error { case wrongEditorUrl(String?) } @@ -11,6 +11,7 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA private let url: URL private let progressView = WebProgressView() private let userId: String + let gutenbergReadySemaphore = DispatchSemaphore(value: 0) init(with post: AbstractPost, block: Block) throws { authenticator = GutenbergRequestAuthenticator(blog: post.blog) @@ -35,8 +36,10 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA override func viewDidLoad() { super.viewDidLoad() addNavigationBarElements() + showLoadingMessage() addProgressView() startObservingWebView() + waitForGutenbergToLoad(fallback: showTroubleshootingInstructions) } deinit { @@ -82,6 +85,10 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA override func onGutenbergReady() { super.onGutenbergReady() navigationItem.rightBarButtonItem?.isEnabled = true + DispatchQueue.main.async { [weak self] in + self?.hideNoResults() + self?.gutenbergReadySemaphore.signal() + } } private func loadCustomScript(named name: String, with argument: String? = nil) -> WKUserScript? { @@ -104,6 +111,30 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA navigationItem.rightBarButtonItem?.isEnabled = false } + private func showLoadingMessage() { + let title = NSLocalizedString("Loading the block editor.", comment: "Loading message shown while the Unsupported Block Editor is loading.") + let subtitle = NSLocalizedString("Please ensure the block editor is enabled on your site. If it is not enabled, it will not load.", comment: "Message asking users to make sure that the block editor is enabled on their site in order for the Unsupported Block Editor to load properly.") + configureAndDisplayNoResults(on: view, title: title, subtitle: subtitle, accessoryView: NoResultsViewController.loadingAccessoryView()) + } + + private func waitForGutenbergToLoad(fallback: @escaping () -> Void) { + DispatchQueue.global(qos: .background).async { [weak self] in + let timeout: TimeInterval = 15 + // blocking call + if self?.gutenbergReadySemaphore.wait(timeout: .now() + timeout) == .timedOut { + DispatchQueue.main.async { + fallback() + } + } + } + } + + private func showTroubleshootingInstructions() { + let title = NSLocalizedString("Unable to load the block editor right now.", comment: "Title message shown when the Unsupported Block Editor fails to load.") + let subtitle = NSLocalizedString("Please ensure the block editor is enabled on your site and try again.", comment: "Subtitle message shown when the Unsupported Block Editor fails to load. It asks users to verify that the block editor is enabled on their site before trying again.") + self.updateNoResults(title: title, subtitle: subtitle, image: "cloud") + } + private func startObservingWebView() { webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: [.new], context: nil) } From 82baaafa21bec3d74495367da3baa3425d2d6bb7 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 27 May 2021 10:47:31 -0400 Subject: [PATCH 2/3] Add release note --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 8a6c3071d896..e73017b2589c 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -6,6 +6,7 @@ * [*] Improved large text support in the blog details header in My Sites. [#16521] * [***] Block Editor: New Block: Reusable block. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/3490] * [***] Block Editor: Add reusable blocks to the block inserter menu. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/3054] +* [*] Fixed a bug where the web version of the editor did not load when using an account created before December 2018. [#16586] 17.4 ----- From 8b98659cb70aa350af236179b7fe0afe9800d3a2 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 27 May 2021 17:54:50 -0400 Subject: [PATCH 3/3] Dismiss UBE loading screen on login prompt This fixes a bug I caught when testing where the loading screen would be shown above the UBE's content when it asks you to log in via WP.com. --- .../Gutenberg/GutenbergWeb/GutenbergWebViewController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift index 7f768abc4cdc..c3fa0de0cc5a 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergWeb/GutenbergWebViewController.swift @@ -132,7 +132,8 @@ class GutenbergWebViewController: GutenbergWebSingleBlockViewController, WebKitA private func showTroubleshootingInstructions() { let title = NSLocalizedString("Unable to load the block editor right now.", comment: "Title message shown when the Unsupported Block Editor fails to load.") let subtitle = NSLocalizedString("Please ensure the block editor is enabled on your site and try again.", comment: "Subtitle message shown when the Unsupported Block Editor fails to load. It asks users to verify that the block editor is enabled on their site before trying again.") - self.updateNoResults(title: title, subtitle: subtitle, image: "cloud") + // This does nothing if the "no results" screen is not currently displayed, which is the intended behavior + updateNoResults(title: title, subtitle: subtitle, image: "cloud") } private func startObservingWebView() { @@ -154,6 +155,7 @@ extension GutenbergWebViewController { override func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { super.webView(webView, didCommit: navigation) if webView.url?.absoluteString.contains("reauth=1") ?? false { + hideNoResults() removeCoverViewAnimated() } }