diff --git a/{{cookiecutter.out_dir}}/lib/main.dart b/{{cookiecutter.out_dir}}/lib/main.dart index a364ed8..ffe2145 100644 --- a/{{cookiecutter.out_dir}}/lib/main.dart +++ b/{{cookiecutter.out_dir}}/lib/main.dart @@ -10,6 +10,7 @@ import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart' as path_provider; import 'package:serious_python/serious_python.dart'; import 'package:url_strategy/url_strategy.dart'; +import 'package:window_manager/window_manager.dart'; {% for dep in cookiecutter.flutter.dependencies %} import 'package:{{ dep }}/{{ dep }}.dart' as {{ dep }}; @@ -345,4 +346,29 @@ Future getUnusedPort() { socket.close(); return port; }); -} \ No newline at end of file +} + +bool isDesktop() { + return !kIsWeb && + (defaultTargetPlatform == TargetPlatform.windows || + defaultTargetPlatform == TargetPlatform.macOS || + defaultTargetPlatform == TargetPlatform.linux); +} + +Future setupDesktop() async { + if (isDesktop()) { + WidgetsFlutterBinding.ensureInitialized(); + await windowManager.ensureInitialized(); + + Map env = Platform.environment; + var hideWindowOnStart = env["FLET_HIDE_WINDOW_ON_START"]; + debugPrint("hideWindowOnStart: $hideWindowOnStart"); + + await windowManager.waitUntilReadyToShow(null, () async { + if (hideWindowOnStart == null) { + await windowManager.show(); + await windowManager.focus(); + } + }); + } +} diff --git a/{{cookiecutter.out_dir}}/pubspec.yaml b/{{cookiecutter.out_dir}}/pubspec.yaml index 570ae27..6a2d493 100644 --- a/{{cookiecutter.out_dir}}/pubspec.yaml +++ b/{{cookiecutter.out_dir}}/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: dependency_overrides: wakelock_plus: ^1.2.5 web: ^1.0.0 + window_manager: ^0.4.3 # {% if 'flet_audio_recorder' in cookiecutter.flutter.dependencies %} record: ^5.1.1