From 348dcee7c88707e9608fc96b37abf3af7f304f28 Mon Sep 17 00:00:00 2001 From: Joshua Tang Date: Sat, 19 Aug 2023 00:56:05 +1000 Subject: [PATCH] refactor: migrate to use `window_manager` for setting window size --- lib/main.dart | 18 ++++++++++++---- linux/flutter/generated_plugin_registrant.cc | 12 +++++++---- linux/flutter/generated_plugins.cmake | 3 ++- macos/Flutter/GeneratedPluginRegistrant.swift | 6 ++++-- macos/Podfile.lock | 16 +++++++++----- pubspec.lock | 21 ++++++++++++------- pubspec.yaml | 6 +----- .../flutter/generated_plugin_registrant.cc | 9 +++++--- windows/flutter/generated_plugins.cmake | 3 ++- 9 files changed, 62 insertions(+), 32 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e9d02b76b..1ab583704 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,7 +10,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:universal_io/io.dart'; -import 'package:window_size/window_size.dart'; +import 'package:window_manager/window_manager.dart'; import 'app.dart'; import 'bloc_observer.dart'; @@ -21,9 +21,19 @@ void main() async { EquatableConfig.stringify = kDebugMode; if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { - setWindowTitle("Appainter"); - setWindowMinSize(const Size(1350, 850)); - setWindowMaxSize(Size.infinite); + await windowManager.ensureInitialized(); + const windowOptions = WindowOptions( + size: Size(1350, 850), + center: true, + backgroundColor: Colors.transparent, + skipTaskbar: false, + titleBarStyle: TitleBarStyle.normal, + ); + windowManager.waitUntilReadyToShow(windowOptions, () async { + await windowManager.maximize(); + await windowManager.show(); + await windowManager.focus(); + }); } if (kDebugMode) { diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 99b7b22b8..76c9a9526 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,18 +6,22 @@ #include "generated_plugin_registrant.h" +#include #include #include -#include +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) screen_retriever_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); + screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); g_autoptr(FlPluginRegistrar) sentry_flutter_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin"); sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar); g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); - g_autoptr(FlPluginRegistrar) window_size_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "WindowSizePlugin"); - window_size_plugin_register_with_registrar(window_size_registrar); + g_autoptr(FlPluginRegistrar) window_manager_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin"); + window_manager_plugin_register_with_registrar(window_manager_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 66db3ec17..7194bb723 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,9 +3,10 @@ # list(APPEND FLUTTER_PLUGIN_LIST + screen_retriever sentry_flutter url_launcher_linux - window_size + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 9ce2c6438..ed0af9cb4 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,10 +10,11 @@ import firebase_auth import firebase_core import package_info_plus import path_provider_foundation +import screen_retriever import sentry_flutter import shared_preferences_foundation import url_launcher_macos -import window_size +import window_manager func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseAnalyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAnalyticsPlugin")) @@ -21,8 +22,9 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) - WindowSizePlugin.register(with: registry.registrar(forPlugin: "WindowSizePlugin")) + WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) } diff --git a/macos/Podfile.lock b/macos/Podfile.lock index ef3dce646..665c10fc0 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -109,6 +109,8 @@ PODS: - Flutter - FlutterMacOS - PromisesObjC (2.3.1) + - screen_retriever (0.0.1): + - FlutterMacOS - Sentry/HybridSDK (8.9.1): - SentryPrivate (= 8.9.1) - sentry_flutter (0.0.1): @@ -121,7 +123,7 @@ PODS: - FlutterMacOS - url_launcher_macos (0.0.1): - FlutterMacOS - - window_size (0.0.2): + - window_manager (0.2.0): - FlutterMacOS DEPENDENCIES: @@ -131,10 +133,11 @@ DEPENDENCIES: - FlutterMacOS (from `Flutter/ephemeral`) - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) + - screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`) - sentry_flutter (from `Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos`) - shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`) - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) - - window_size (from `Flutter/ephemeral/.symlinks/plugins/window_size/macos`) + - window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`) SPEC REPOS: trunk: @@ -166,14 +169,16 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos path_provider_foundation: :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin + screen_retriever: + :path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos sentry_flutter: :path: Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos shared_preferences_foundation: :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin url_launcher_macos: :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos - window_size: - :path: Flutter/ephemeral/.symlinks/plugins/window_size/macos + window_manager: + :path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos SPEC CHECKSUMS: Firebase: 07150e75d142fb9399f6777fa56a187b17f833a0 @@ -194,12 +199,13 @@ SPEC CHECKSUMS: package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4 + screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38 Sentry: e3203780941722a1fcfee99e351de14244c7f806 sentry_flutter: 8f0ffd53088e6a4d50c095852c5cad9e4405025c SentryPrivate: 5e3683390f66611fc7c6215e27645873adb55d13 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95 - window_size: 339dafa0b27a95a62a843042038fa6c3c48de195 + window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8 PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7 diff --git a/pubspec.lock b/pubspec.lock index 7f6349438..c84b998f5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -963,6 +963,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.1.1" + screen_retriever: + dependency: transitive + description: + name: screen_retriever + sha256: "4931f226ca158123ccd765325e9fbf360bfed0af9b460a10f960f9bb13d58323" + url: "https://pub.dev" + source: hosted + version: "0.1.6" sentry: dependency: transitive description: @@ -1360,15 +1368,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.0.6" - window_size: + window_manager: dependency: "direct main" description: - path: "plugins/window_size" - ref: "89c350f787e1d7bff12b3517e5671146211ee70e" - resolved-ref: "89c350f787e1d7bff12b3517e5671146211ee70e" - url: "https://github.com/google/flutter-desktop-embedding.git" - source: git - version: "0.1.0" + name: window_manager + sha256: "9eef00e393e7f9308309ce9a8b2398c9ee3ca78b50c96e8b4f9873945693ac88" + url: "https://pub.dev" + source: hosted + version: "0.3.5" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0c89ba0a8..5585f5458 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,11 +44,7 @@ dependencies: universal_html: 2.2.3 universal_io: 2.2.2 url_launcher: 6.1.12 - window_size: - git: - url: https://github.com/google/flutter-desktop-embedding.git - path: plugins/window_size - ref: 89c350f787e1d7bff12b3517e5671146211ee70e + window_manager: ^0.3.5 dependency_overrides: intl: ^0.18.0 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 45c573d03..9a168b9e3 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,17 +7,20 @@ #include "generated_plugin_registrant.h" #include +#include #include #include -#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { FirebaseCorePluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("FirebaseCorePluginCApi")); + ScreenRetrieverPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); SentryFlutterPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("SentryFlutterPlugin")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); - WindowSizePluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("WindowSizePlugin")); + WindowManagerPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("WindowManagerPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 5377e1702..cffb7bb26 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,9 +4,10 @@ list(APPEND FLUTTER_PLUGIN_LIST firebase_core + screen_retriever sentry_flutter url_launcher_windows - window_size + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST