Skip to content

Commit

Permalink
fix: titlebar maximize+restore button not working and less responsive…
Browse files Browse the repository at this point in the history
… title bar buttons
  • Loading branch information
KRTirtho committed Jan 5, 2023
1 parent 0b58155 commit 8a6ba3b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
37 changes: 22 additions & 15 deletions lib/components/shared/page_window_title_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class PageWindowTitleBar extends StatefulHookWidget with PreferredSizeWidget {
class _PageWindowTitleBarState extends State<PageWindowTitleBar> {
@override
Widget build(BuildContext context) {
final isMaximized = useState(appWindow.isMaximized);

useEffect(() {
if (platform == TargetPlatform.windows &&
widget.hideWhenWindows &&
Expand All @@ -77,17 +79,30 @@ class _PageWindowTitleBarState extends State<PageWindowTitleBar> {
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,
Expand All @@ -101,13 +116,5 @@ class _PageWindowTitleBarState extends State<PageWindowTitleBar> {
titleWidth: widget.titleWidth,
toolbarTextStyle: widget.toolbarTextStyle,
);

if (platform == TargetPlatform.windows && widget.hideWhenWindows) {
return const SizedBox.shrink();
}

return MoveWindow(
child: appBar,
);
}
}
10 changes: 5 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ class SpotubeState extends ConsumerState<Spotube> 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({
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a6ba3b

Please sign in to comment.