Skip to content

Commit

Permalink
refactor: migrate to use window_manager for setting window size
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshuaro committed Aug 18, 2023
1 parent 479816d commit 348dcee
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 32 deletions.
18 changes: 14 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_size/window_size_plugin.h>
#include <window_manager/window_manager_plugin.h>

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);
}
3 changes: 2 additions & 1 deletion linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ 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"))
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
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"))
}
16 changes: 11 additions & 5 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 14 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
#include "generated_plugin_registrant.h"

#include <firebase_core/firebase_core_plugin_c_api.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_size/window_size_plugin.h>
#include <window_manager/window_manager_plugin.h>

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"));
}
3 changes: 2 additions & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 348dcee

Please sign in to comment.