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 ----- 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..c3fa0de0cc5a 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,31 @@ 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.") + // 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() { webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: [.new], context: nil) } @@ -123,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() } }