Skip to content

Commit

Permalink
fix: mini player not working in release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Apr 15, 2023
1 parent 6259014 commit 28ff321
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
16 changes: 7 additions & 9 deletions lib/collections/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 20 additions & 2 deletions lib/components/root/bottom_player.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -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');
},
);
},
),
],
Expand Down
17 changes: 11 additions & 6 deletions lib/pages/lyrics/mini_lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ class MiniLyricsPage extends HookConsumerWidget {
final theme = Theme.of(context);
final update = useForceUpdate();
final prevSize = useRef<Size?>(null);
final wasMaximized = useRef<bool>(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;
}, []);
Expand Down Expand Up @@ -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');
}
}
},
),
Expand Down

0 comments on commit 28ff321

Please sign in to comment.