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: fix kraken.methodChannel.setMethodCallHandler did't get called before kraken.invokeMethod called. #289

Merged
merged 3 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions kraken/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ class KrakenController {
}

_methodChannel = methodChannel;
setJSMethodCallCallback(this);

_view = KrakenViewController(viewportWidth, viewportHeight,
background: background,
showPerformanceOverlay: showPerformanceOverlay,
Expand Down
19 changes: 12 additions & 7 deletions kraken/lib/src/module/method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ Future<dynamic> _invokeMethodFromJavaScript(KrakenController controller, String
return controller.methodChannel._invokeMethodFromJavaScript(method, args);
}

const METHOD_CHANNEL_NAME = 'MethodChannel';

class MethodChannelModule extends BaseModule {
@override
String get name => 'MethodChannel';
MethodChannelModule(ModuleManager moduleManager) : super(moduleManager) {
if (moduleManager == null) return;
moduleManager.controller.methodChannel._onJSMethodCall = (String method, dynamic arguments) async {
moduleManager.emitModuleEvent(name, data: [method, arguments]);
};
}
String get name => METHOD_CHANNEL_NAME;
MethodChannelModule(ModuleManager moduleManager) : super(moduleManager);

@override
void dispose() {}
Expand All @@ -41,6 +38,14 @@ class MethodChannelModule extends BaseModule {
}
}

void setJSMethodCallCallback(KrakenController controller) {
andycall marked this conversation as resolved.
Show resolved Hide resolved
if (controller.methodChannel == null) return;

controller.methodChannel._onJSMethodCall = (String method, dynamic arguments) async {
controller.module.moduleManager.emitModuleEvent(METHOD_CHANNEL_NAME, data: [method, arguments]);
};
}

class KrakenMethodChannel {
MethodCallCallback _onJSMethodCallCallback;

Expand Down