Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Stabilize Android media uploads #29

Merged
merged 9 commits into from
Oct 17, 2024
Merged

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Oct 11, 2024

Description

Relates to wordpress-mobile/WordPress-Android#21223.

Fix various instabilities in Android media uploads. Synchronize Gradle versions
with the WordPress-Android project.

Testing Instructions

See wordpress-mobile/WordPress-Android#21223.

Address errors originating from version conflicts with the
WordPress-Android project.
Address version incompatibility by mirroring the WordPress-Android
project.
It is not possible to use `evaluateJavascript` within the
`shouldInterceptRequest` callback, as it occurs to early. This resulted
in the absence of the `GBKit` global.
Defaulting this value to `false` should suffice.
The weak references resulted in unexpectedly null callback values, which
meant that the media upload callback would occasionally fail.
@dcalhoun dcalhoun added the bug Something isn't working label Oct 11, 2024
It is not possible to use `evaluateJavascript` within the
`shouldInterceptRequest` callback, as it occurs to early. This resulted
in the absence of the `GBKit` global.
private var assetLoader = WebViewAssetLoader.Builder()
.addPathHandler("/assets/", AssetsPathHandler(this.context))
.build()
private var initialTitle: String = ""
private var type: String = ""
private var id: Int? = null
private var themeStyles: Boolean? = null
private var themeStyles: Boolean = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting to false felt simpler than a nullable value.

var filePathCallback: ValueCallback<Array<Uri?>?>? = null
val pickImageRequestCode = 1
private var onFileChooserRequested: WeakReference<((Intent, Int) -> Unit)?>? = null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The weak references seemingly led to unexpectedly discarded event handlers, which led to the "Upload" button sporadically failing to operate. Given we null out these values during view destruction, it feels safe to remove the weak reference.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and good call 👍

Comment on lines -97 to -104
if (!hasSetEditorConfig && withConfig) {
handler.post {
var editorInitialConfig = getEditorConfiguration()
view?.evaluateJavascript(editorInitialConfig, null)

}
hasSetEditorConfig = true
}
Copy link
Member Author

@dcalhoun dcalhoun Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race condition that results in this approach not consistently load the global values before the HTML page loaded.

Unfortunately, Android does not provide a method similar to iOS' addUserScript. So, this "push" approach was replaced with a "pull" approach on Android to ensure the value is available before the first WebView requests are made.

@@ -1,5 +1,5 @@
[versions]
agp = "8.4.2"
agp = "8.5.1"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AGP and Gradle versions were updated to mirror the WordPress-Android project.

@dcalhoun dcalhoun marked this pull request as ready for review October 14, 2024 20:57
@dcalhoun dcalhoun requested a review from nbradbury October 14, 2024 21:15
Mitigate cryptic errors from unexpected editor configuration values.
@nbradbury nbradbury self-assigned this Oct 17, 2024
try {
return JSON.parse(window.editorDelegate.getEditorConfiguration());
} catch (error) {
console.error('Failed parsing GBKit from editorDelegate:', error);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an error occurs here, is there a way to let the user know something went wrong? And does the message sent to console.error get added to the app log? Apologies if those are basic questions, but I have little experience here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. In the event his is triggered—given the fallback value of an empty object—the editor will display normally. However, most actions will undoubtedly fail, creating a confusing experience.

Unfortunately, it is unlikely a user would be recover from an error of this nature themselves, but we could communicate configuration failed and direct them to contact support/community forums. I captured this opportunity in https://github.com/Automattic/dotcom-forge/issues/9453.

Copy link

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a minor comment that isn't an issue, more of an item for my curiosity. Let's :shipit:!

@dcalhoun dcalhoun merged commit a58a46f into trunk Oct 17, 2024
5 checks passed
@dcalhoun dcalhoun deleted the fix/android-media-integration branch October 17, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants