ensureInitialized static method

Future<void> ensureInitialized({
  1. bool? isSimulate,
  2. Size? size,
  3. bool? center,
  4. Size? minimumSize,
  5. Size? maximumSize,
  6. bool? alwaysOnTop,
  7. bool? fullScreen,
  8. Color? backgroundColor,
  9. bool? skipTaskbar,
  10. String? title,
  11. TitleBarStyle? titleBarStyle,
  12. bool? windowButtonVisibility,
  13. bool isShowFrame = kDebugMode,
  14. FutureOr<void> onWindowInit(
    1. WindowManager windowManager
    )?,
})

Implementation

static Future<void> ensureInitialized({
  bool? isSimulate,
  Size? size,
  bool? center,
  Size? minimumSize,
  Size? maximumSize,
  bool? alwaysOnTop,
  bool? fullScreen,
  Color? backgroundColor,
  bool? skipTaskbar,
  String? title,
  TitleBarStyle? titleBarStyle,
  bool? windowButtonVisibility,
  bool isShowFrame = kDebugMode,
  FutureOr<void> Function(WindowManager windowManager)? onWindowInit,
}) async {
  WidgetsFlutterBinding.ensureInitialized();
  if (isSimulate != null) {
    simulate_data.is_simulate = isSimulate;
  }
  bool isSetWindowManager = false;
  bool isSetWindowTransparent = false;
  if (isShowFrame) {
    if (Platform.isAndroid) {
    } else if (Platform.isIOS) {
    } else {
      isSetWindowManager = true;
      isSetWindowTransparent = true;
    }
  } else {
    if (Platform.isAndroid) {
    } else if (Platform.isIOS) {
    } else {
      isSetWindowManager = true;
      isSetWindowTransparent = true;
    }
  }

  if (kIsWeb) {
    isSetWindowManager = false;
    isSetWindowTransparent = false;
  }

  if (isSetWindowTransparent) {
    // await Window.initialize();
    // await Window.setEffect(
    //   effect: WindowEffect.transparent,
    // );
  }

  if (isSetWindowManager) {
    await windowManager.ensureInitialized();

    WindowOptions windowOptions = WindowOptions(
      size: size,
      alwaysOnTop: alwaysOnTop,
      fullScreen: fullScreen,
      center: center,
      backgroundColor: Colors.transparent,
      skipTaskbar: false,
      titleBarStyle: TitleBarStyle.hidden,
      windowButtonVisibility: false,
    );

    await windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.show();
      await windowManager.focus();

      if (onWindowInit != null) {
        await onWindowInit(windowManager);
      }
    });
  }
}