Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class OverlayService extends Service implements View.OnTouchListener {
public static boolean isRunning = false;
private WindowManager windowManager = null;
private FlutterView flutterView;
private MethodChannel flutterChannel = new MethodChannel(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG).getDartExecutor(), OverlayConstants.OVERLAY_TAG);
private BasicMessageChannel<Object> overlayMessageChannel = new BasicMessageChannel(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG).getDartExecutor(), OverlayConstants.MESSENGER_TAG, JSONMessageCodec.INSTANCE);
private MethodChannel flutterChannel;
private BasicMessageChannel<Object> overlayMessageChannel;
private int clickableFlag = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

Expand Down Expand Up @@ -117,6 +117,15 @@ public int onStartCommand(Intent intent, int flags, int startId) {
isRunning = true;
Log.d("onStartCommand", "Service started");
FlutterEngine engine = FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG);

if(engine == null){
return START_STICKY;
}

if(flutterChannel == null){
flutterChannel = new MethodChannel(engine.getDartExecutor(), OverlayConstants.OVERLAY_TAG);
}

engine.getLifecycleChannel().appIsResumed();
flutterView = new FlutterView(getApplicationContext(), new FlutterTextureView(getApplicationContext()));
flutterView.attachToFlutterEngine(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG));
Expand All @@ -139,6 +148,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
resizeOverlay(width, height, enableDrag, result);
}
});

if(overlayMessageChannel == null) {
overlayMessageChannel = new BasicMessageChannel(engine.getDartExecutor(), OverlayConstants.MESSENGER_TAG, JSONMessageCodec.INSTANCE);
}

overlayMessageChannel.setMessageHandler((message, reply) -> {
WindowSetup.messenger.send(message);
});
Expand Down