From 8a6ba3b35f0b6b42cf60920e945ac2065c886ecb Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Thu, 5 Jan 2023 23:09:46 +0600 Subject: [PATCH] fix: titlebar maximize+restore button not working and less responsive title bar buttons --- .../shared/page_window_title_bar.dart | 37 +++++++++++-------- lib/main.dart | 10 ++--- pubspec.lock | 4 +- pubspec.yaml | 2 +- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/components/shared/page_window_title_bar.dart b/lib/components/shared/page_window_title_bar.dart index b7fdac9bf..434d99271 100644 --- a/lib/components/shared/page_window_title_bar.dart +++ b/lib/components/shared/page_window_title_bar.dart @@ -54,6 +54,8 @@ class PageWindowTitleBar extends StatefulHookWidget with PreferredSizeWidget { class _PageWindowTitleBarState extends State { @override Widget build(BuildContext context) { + final isMaximized = useState(appWindow.isMaximized); + useEffect(() { if (platform == TargetPlatform.windows && widget.hideWhenWindows && @@ -77,17 +79,30 @@ class _PageWindowTitleBarState extends State { return null; }, [platform, widget.hideWhenWindows]); - final appBar = PlatformAppBar( + if (platform == TargetPlatform.windows && widget.hideWhenWindows) { + return const SizedBox.shrink(); + } + + return PlatformAppBar( actions: [ ...?widget.actions, if (!kIsMacOS && !kIsMobile) - platform == TargetPlatform.linux - ? MoveWindow(child: const PlatformWindowButtons()) - : const PlatformWindowButtons(), + PlatformWindowButtons( + isMaximized: () => isMaximized.value, + onMaximize: () { + appWindow.maximize(); + isMaximized.value = true; + }, + onRestore: () { + appWindow.restore(); + isMaximized.value = false; + }, + ), ], - title: platform == TargetPlatform.linux - ? MoveWindow(child: Center(child: widget.center)) - : widget.center, + onDrag: () { + appWindow.startDragging(); + }, + title: widget.center, toolbarOpacity: widget.toolbarOpacity, backgroundColor: widget.backgroundColor, actionsIconTheme: widget.actionsIconTheme, @@ -101,13 +116,5 @@ class _PageWindowTitleBarState extends State { titleWidth: widget.titleWidth, toolbarTextStyle: widget.toolbarTextStyle, ); - - if (platform == TargetPlatform.windows && widget.hideWhenWindows) { - return const SizedBox.shrink(); - } - - return MoveWindow( - child: appBar, - ); } } diff --git a/lib/main.dart b/lib/main.dart index 5710c55f2..5760cc780 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -238,11 +238,11 @@ class SpotubeState extends ConsumerState with WidgetsBindingObserver { themeMode: themeMode, windowButtonConfig: kIsDesktop ? PlatformWindowButtonConfig( - isMaximized: () => appWindow.isMaximized, - onClose: appWindow.close, - onRestore: appWindow.restore, - onMaximize: appWindow.maximize, - onMinimize: appWindow.minimize, + isMaximized: () async => Future.value(appWindow.isMaximized), + onClose: () async => appWindow.close(), + onRestore: () async => appWindow.restore(), + onMaximize: () async => appWindow.maximize(), + onMinimize: () async => appWindow.minimize(), ) : null, shortcuts: PlatformProperty.all({ diff --git a/pubspec.lock b/pubspec.lock index bd28171a3..64f1f9305 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1070,8 +1070,8 @@ packages: dependency: "direct main" description: path: "." - ref: "7a4cda31e434de7cbee92ac7f418903641a2f023" - resolved-ref: "7a4cda31e434de7cbee92ac7f418903641a2f023" + ref: "073cefb9c419fcb01cbdfd6ca2f9714eec23c83b" + resolved-ref: "073cefb9c419fcb01cbdfd6ca2f9714eec23c83b" url: "https://github.com/KRTirtho/platform_ui.git" source: git version: "0.1.0" diff --git a/pubspec.yaml b/pubspec.yaml index b252f0cf7..93c898b89 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,7 +62,7 @@ dependencies: platform_ui: git: url: https://github.com/KRTirtho/platform_ui.git - ref: 7a4cda31e434de7cbee92ac7f418903641a2f023 + ref: 073cefb9c419fcb01cbdfd6ca2f9714eec23c83b fluent_ui: ^4.0.3 macos_ui: ^1.7.5 libadwaita: ^1.2.5