fix(ohos): bind WXApi event handler on registerApp so the first callback after cold start is not lost (#773) - #775
Merged
JarvanMo merged 1 commit intoSep 23, 2026
Conversation
…allback after cold start is not lost The WeChat HarmonyOS SDK (@tencent/wechat_open_sdk 1.0.15) dispatches responses to the handler it got in the most recent handleWant() call, and handleWant() is the only way to give it one. With current WeChat versions the SDK sends requests through openLink and delivers the response from the openLink completion callback via `this.eventHandler?.onResp(...)`, which never goes through onNewWant. fluwx only called handleWant() from onNewWant / attemptToResumeMsgFromWx, so after every cold start the handler was null and the first auth / pay response was dropped silently; later ones worked only because WeChat's return had triggered onNewWant once. - registerApp now binds the plugin as event handler through handleWant() with an empty Want. An empty Want carries no WeChat payload, so nothing is dispatched; the launch Want is still left to attemptToResumeMsgFromWx(), which apps call once their subscribers are ready (binding with the launch Want here would deliver a cold-start message before Dart listens, and again on attemptToResumeMsgFromWx). - registerApp re-binds on repeated calls instead of returning early. - attemptToResumeMsgFromWx now completes its MethodResult; previously `await attemptToResumeMsgFromWx()` never returned on HarmonyOS. Fixes OpenFlutter#773 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F7jis66xcRRD5gTkwH1uLe
Member
|
Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #773.
Problem
On HarmonyOS, the first WeChat auth / pay after every cold start never gets a callback, so callers time out. Retrying in the same process works; killing the process brings it back. Reproduced with fluwx 5.7.7 and present on
main, @tencent/wechat_open_sdk 1.0.15.Root cause
In
@tencent/wechat_open_sdk(WXAPIFactory.js):this.eventHandler?.onResp(resp);eventHandleris assigned only insidehandleWant(want, eventHandler), the only public way to hand the SDK a handler (WXApihas no setter);sendReqgoes throughopenLink, and the response comes back through the openLink completion callback (handleResult→handleWantInternal), not throughonNewWant.fluwx calls
handleWant()only fromonNewWantandattemptToResumeMsgFromWx. After a cold start neither has run, soeventHandlerisnulland the first response is dropped by the?.with no log. WeChat's return also triggersonNewWant, which binds the handler, which is why every later attempt works.Fix
registerAppbinds the plugin as event handler by callinghandleWant()with an emptyWant. It carries no WeChat payload, so nothing is dispatched. The launchWantis deliberately not used here: that would deliver a cold-start message (e.g. launched from a mini program) before the Dart side has subscribed, and then again when the app callsattemptToResumeMsgFromWx().registerAppre-binds on repeated calls instead of returning early, so the handler is always the current plugin instance.attemptToResumeMsgFromWxnow callsresult.success(null). It never completed itsMethodResult, soawait fluwx.attemptToResumeMsgFromWx()hung forever on HarmonyOS, which also rules out the workaround suggested in [ohos] 冷启动后微信登录/支付回调丢失:eventHandler仅在onNewWant中绑定,首次回调被静默吞掉 #773 when awaited.No Dart API changes; Android / iOS untouched.
Testing
On a Huawei MatePad (HarmonyOS NEXT), app built with Flutter 3.27.5-ohos, fluwx 5.7.7 + this exact patch applied to its
ohos/sources (that code is identical onmain), with all app-side workarounds removed:hilogshows the response arriving through the openLink callback, not throughonNewWant, on each cold start:The ArkTS changes also compile with
flutter build hap.🤖 Generated with Claude Code
https://claude.ai/code/session_01F7jis66xcRRD5gTkwH1uLe