ensureWindow method

Future<Window?> ensureWindow()

ensure window make sure the window object sync from android call this as soon at posible when engine start you should only call this in the window engine if only main as entry point, it's ok to call this and return nothing

Implementation

// only window engine call this
// make sure window engine return only one window from every where
Future<Window?> ensureWindow() async {
  // window object don't have sync method, we must do at here
  // assert if you are in main engine should call this
  var map = await Window.sync();
  log("[window] sync window object from android: $map");
  if (map == null) return null;
  // store current window if needed
  // use the static window first
  // so sync will return only one instance of window
  // improve this logic
  // means first time call sync, just create a new window
  if (_window == null) _window = Window();
  _window!.applyMap(map);
  _isWindow = true;
  return _window;
}