Skip to content

Commit

Permalink
fix(lyrics): LRCLIB lyrics should be usable without logging in #1803
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Sep 15, 2024
1 parent 57c8f85 commit 1cad097
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 55 deletions.
57 changes: 27 additions & 30 deletions lib/modules/root/bottom_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'package:spotube/extensions/context.dart';
import 'package:spotube/extensions/image.dart';
import 'package:spotube/hooks/utils/use_brightness_value.dart';
import 'package:flutter/material.dart';
import 'package:spotube/provider/authentication/authentication.dart';
import 'package:spotube/provider/audio_player/audio_player.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';

Expand All @@ -30,7 +29,6 @@ class BottomPlayer extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {
final auth = ref.watch(authenticationProvider);
final playlist = ref.watch(audioPlayerProvider);
final layoutMode =
ref.watch(userPreferencesProvider.select((s) => s.layoutMode));
Expand Down Expand Up @@ -89,35 +87,34 @@ class BottomPlayer extends HookConsumerWidget {
children: [
PlayerActions(
extraActions: [
if (auth.asData?.value != null)
IconButton(
tooltip: context.l10n.mini_player,
icon: const Icon(SpotubeIcons.miniPlayer),
onPressed: () async {
if (!kIsDesktop) return;
IconButton(
tooltip: context.l10n.mini_player,
icon: const Icon(SpotubeIcons.miniPlayer),
onPressed: () async {
if (!kIsDesktop) return;

final prevSize = await windowManager.getSize();
await windowManager.setMinimumSize(
const Size(300, 300),
);
await windowManager.setAlwaysOnTop(true);
if (!kIsLinux) {
await windowManager.setHasShadow(false);
}
await windowManager
.setAlignment(Alignment.topRight);
await windowManager.setSize(const Size(400, 500));
await Future.delayed(
const Duration(milliseconds: 100),
() async {
GoRouter.of(context).go(
'/mini-player',
extra: prevSize,
);
},
);
},
),
final prevSize = await windowManager.getSize();
await windowManager.setMinimumSize(
const Size(300, 300),
);
await windowManager.setAlwaysOnTop(true);
if (!kIsLinux) {
await windowManager.setHasShadow(false);
}
await windowManager
.setAlignment(Alignment.topRight);
await windowManager.setSize(const Size(400, 500));
await Future.delayed(
const Duration(milliseconds: 100),
() async {
GoRouter.of(context).go(
'/mini-player',
extra: prevSize,
);
},
);
},
),
],
),
Container(
Expand Down
11 changes: 0 additions & 11 deletions lib/pages/lyrics/lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/fallbacks/anonymous_fallback.dart';
import 'package:spotube/components/titlebar/titlebar.dart';
import 'package:spotube/components/image/universal_image.dart';
import 'package:spotube/components/themed_button_tab_bar.dart';
Expand All @@ -17,7 +16,6 @@ import 'package:spotube/hooks/utils/use_custom_status_bar_color.dart';
import 'package:spotube/hooks/utils/use_palette_color.dart';
import 'package:spotube/pages/lyrics/plain_lyrics.dart';
import 'package:spotube/pages/lyrics/synced_lyrics.dart';
import 'package:spotube/provider/authentication/authentication.dart';
import 'package:spotube/provider/audio_player/audio_player.dart';
import 'package:spotube/utils/platform.dart';
import 'package:spotube/provider/spotify/spotify.dart';
Expand Down Expand Up @@ -82,15 +80,6 @@ class LyricsPage extends HookConsumerWidget {
),
);

final auth = ref.watch(authenticationProvider);

if (auth.asData?.value == null) {
return Scaffold(
appBar: !kIsMacOS && !isModal ? const PageWindowTitleBar() : null,
body: const AnonymousFallback(),
);
}

if (isModal) {
return DefaultTabController(
length: 2,
Expand Down
12 changes: 1 addition & 11 deletions lib/pages/lyrics/mini_lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/modules/player/player_controls.dart';
import 'package:spotube/modules/player/player_queue.dart';
import 'package:spotube/modules/root/sidebar.dart';
import 'package:spotube/components/fallbacks/anonymous_fallback.dart';
import 'package:spotube/components/titlebar/titlebar.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/hooks/utils/use_force_update.dart';
import 'package:spotube/pages/lyrics/plain_lyrics.dart';
import 'package:spotube/pages/lyrics/synced_lyrics.dart';
import 'package:spotube/provider/authentication/authentication.dart';
import 'package:spotube/provider/audio_player/audio_player.dart';
import 'package:spotube/utils/platform.dart';
import 'package:window_manager/window_manager.dart';
Expand Down Expand Up @@ -46,14 +43,7 @@ class MiniLyricsPage extends HookConsumerWidget {
return null;
}, []);

final auth = ref.watch(authenticationProvider);

if (auth.asData?.value == null) {
return const Scaffold(
appBar: PageWindowTitleBar(),
body: AnonymousFallback(),
);
}


return MouseRegion(
onEnter: !hoverMode.value
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/lyrics/synced_lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SyncedLyrics extends HookConsumerWidget {
WidgetsBinding.instance.addPostFrameCallback((_) {
subscription = audioPlayer.positionStream.listen((event) {
try {
if (event > Duration.zero) return;
if (event > Duration.zero || !controller.hasClients) return;
controller.animateTo(
0,
duration: const Duration(milliseconds: 500),
Expand Down
7 changes: 5 additions & 2 deletions lib/provider/spotify/lyrics/synced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier<SubtitleSimple, Track?> {
try {
final database = ref.watch(databaseProvider);
final spotify = ref.watch(spotifyProvider);
final auth = await ref.watch(authenticationProvider.future);

if (track == null) {
throw "No track currently";
Expand All @@ -139,11 +140,13 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier<SubtitleSimple, Track?> {

final token = await spotify.getCredentials();

if (lyrics == null || lyrics.lyrics.isEmpty) {
if ((lyrics == null || lyrics.lyrics.isEmpty) && auth != null) {
lyrics = await getSpotifyLyrics(token.accessToken);
}

if (lyrics.lyrics.isEmpty || lyrics.lyrics.length <= 5) {
if (lyrics == null ||
lyrics.lyrics.isEmpty ||
lyrics.lyrics.length <= 5) {
lyrics = await getLRCLibLyrics();
}

Expand Down
1 change: 1 addition & 0 deletions lib/provider/spotify/spotify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:async';

import 'package:drift/drift.dart';
import 'package:spotube/models/database/database.dart';
import 'package:spotube/provider/authentication/authentication.dart';
import 'package:spotube/provider/database/database.dart';
import 'package:spotube/provider/spotify/utils/json_cast.dart';
import 'package:spotube/services/logger/logger.dart';
Expand Down

0 comments on commit 1cad097

Please sign in to comment.