Skip to content

Commit

Permalink
fix: fix kraken.methodChannel.setMethodCallHandler did't get called b…
Browse files Browse the repository at this point in the history
…efore kraken.invokeMethod called.
  • Loading branch information
andycall committed May 7, 2021
1 parent 6fc38ec commit 8724284
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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) {
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

0 comments on commit 8724284

Please sign in to comment.