From 28ff3216efee81184798eedfbb10ba66395bbf36 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 15 Apr 2023 13:54:11 +0600 Subject: [PATCH] fix: mini player not working in release mode --- lib/collections/routes.dart | 16 +++++++--------- lib/components/root/bottom_player.dart | 22 ++++++++++++++++++++-- lib/pages/lyrics/mini_lyrics.dart | 17 +++++++++++------ 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/lib/collections/routes.dart b/lib/collections/routes.dart index 5db3617b3..ff2700446 100644 --- a/lib/collections/routes.dart +++ b/lib/collections/routes.dart @@ -51,15 +51,6 @@ final router = GoRouter( name: "Lyrics", pageBuilder: (context, state) => const SpotubePage(child: LyricsPage()), - routes: [ - GoRoute( - path: "mini", - parentNavigatorKey: rootNavigatorKey, - pageBuilder: (context, state) => const SpotubePage( - child: MiniLyricsPage(), - ), - ), - ], ), GoRoute( path: "/settings", @@ -106,6 +97,13 @@ final router = GoRouter( ), ], ), + GoRoute( + path: "/mini-player", + parentNavigatorKey: rootNavigatorKey, + pageBuilder: (context, state) => const SpotubePage( + child: MiniLyricsPage(), + ), + ), GoRoute( path: "/login", parentNavigatorKey: rootNavigatorKey, diff --git a/lib/components/root/bottom_player.dart b/lib/components/root/bottom_player.dart index 37e89a2bf..efec40542 100644 --- a/lib/components/root/bottom_player.dart +++ b/lib/components/root/bottom_player.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:flutter/gestures.dart'; +import 'package:flutter_desktop_tools/flutter_desktop_tools.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; @@ -17,6 +18,7 @@ import 'package:spotube/models/logger.dart'; import 'package:flutter/material.dart'; import 'package:spotube/provider/playlist_queue_provider.dart'; import 'package:spotube/provider/user_preferences_provider.dart'; +import 'package:spotube/utils/platform.dart'; import 'package:spotube/utils/type_conversion_utils.dart'; class BottomPlayer extends HookConsumerWidget { @@ -130,8 +132,24 @@ class BottomPlayer extends HookConsumerWidget { IconButton( tooltip: 'Mini Player', icon: const Icon(SpotubeIcons.miniPlayer), - onPressed: () { - GoRouter.of(context).push('/lyrics/mini'); + onPressed: () async { + await DesktopTools.window.setMinimumSize( + const Size(300, 300), + ); + await DesktopTools.window.setAlwaysOnTop(true); + if (!kIsLinux) { + await DesktopTools.window.setHasShadow(false); + } + await DesktopTools.window + .setAlignment(Alignment.topRight); + await DesktopTools.window + .setSize(const Size(400, 500)); + await Future.delayed( + const Duration(milliseconds: 100), + () async { + GoRouter.of(context).go('/mini-player'); + }, + ); }, ), ], diff --git a/lib/pages/lyrics/mini_lyrics.dart b/lib/pages/lyrics/mini_lyrics.dart index 127f7fb45..77c16a3f8 100644 --- a/lib/pages/lyrics/mini_lyrics.dart +++ b/lib/pages/lyrics/mini_lyrics.dart @@ -25,16 +25,14 @@ class MiniLyricsPage extends HookConsumerWidget { final theme = Theme.of(context); final update = useForceUpdate(); final prevSize = useRef(null); + final wasMaximized = useRef(false); final playlistQueue = ref.watch(PlaylistQueueNotifier.provider); useEffect(() { WidgetsBinding.instance.addPostFrameCallback((_) async { prevSize.value = await DesktopTools.window.getSize(); - await DesktopTools.window.setMinimumSize(const Size(300, 300)); - await DesktopTools.window.setAlwaysOnTop(true); - if (!kIsLinux) await DesktopTools.window.setHasShadow(false); - await DesktopTools.window.setSize(const Size(400, 500)); + wasMaximized.value = await DesktopTools.window.isMaximized(); }); return null; }, []); @@ -106,13 +104,20 @@ class MiniLyricsPage extends HookConsumerWidget { await DesktopTools.window .setMinimumSize(const Size(300, 700)); await DesktopTools.window.setAlwaysOnTop(false); - await DesktopTools.window.setSize(prevSize.value!); + if (wasMaximized.value) { + await DesktopTools.window.maximize(); + } else { + await DesktopTools.window.setSize(prevSize.value!); + } await DesktopTools.window.setAlignment(Alignment.center); if (!kIsLinux) { await DesktopTools.window.setHasShadow(true); } + await Future.delayed(const Duration(milliseconds: 200)); } finally { - if (context.mounted) GoRouter.of(context).go('/'); + if (context.mounted) { + GoRouter.of(context).go('/lyrics'); + } } }, ),