From abf4a5763a2faeedeb93d54e66c1f2482295b326 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Wed, 12 Oct 2022 21:02:50 +0600 Subject: [PATCH] fix: cached local track is fetched from network, body is not behind AppBar in desktop --- lib/components/Home/Shell.dart | 1 + lib/components/Library/UserLocalTracks.dart | 2 ++ lib/models/CurrentPlaylist.dart | 15 ++++++++++++--- lib/models/Intents.dart | 12 +++++++++--- lib/provider/Playback.dart | 4 ++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/components/Home/Shell.dart b/lib/components/Home/Shell.dart index 06115aaef..8844b6c66 100644 --- a/lib/components/Home/Shell.dart +++ b/lib/components/Home/Shell.dart @@ -83,6 +83,7 @@ class Shell extends HookConsumerWidget { ), ) : null, + extendBodyBehindAppBar: true, body: Row( children: [ Sidebar( diff --git a/lib/components/Library/UserLocalTracks.dart b/lib/components/Library/UserLocalTracks.dart index 445757436..c36233a30 100644 --- a/lib/components/Library/UserLocalTracks.dart +++ b/lib/components/Library/UserLocalTracks.dart @@ -16,6 +16,7 @@ import 'package:spotube/models/CurrentPlaylist.dart'; import 'package:spotube/models/Logger.dart'; import 'package:spotube/provider/Playback.dart'; import 'package:spotube/provider/UserPreferences.dart'; +import 'package:spotube/utils/platform.dart'; import 'package:spotube/utils/primitive_utils.dart'; import 'package:spotube/utils/type_conversion_utils.dart'; @@ -137,6 +138,7 @@ class UserLocalTracks extends HookConsumerWidget { useAsyncEffect( () async { + if (!kIsMobile) return; if (!await Permission.storage.isGranted && !await Permission.storage.isLimited) { await Permission.storage.request(); diff --git a/lib/models/CurrentPlaylist.dart b/lib/models/CurrentPlaylist.dart index cacb42ff4..045f2e0b7 100644 --- a/lib/models/CurrentPlaylist.dart +++ b/lib/models/CurrentPlaylist.dart @@ -1,4 +1,5 @@ import 'package:spotify/spotify.dart'; +import 'package:spotube/models/SpotubeTrack.dart'; extension AlbumJson on AlbumSimple { Map toJson() { @@ -74,8 +75,13 @@ class CurrentPlaylist { static CurrentPlaylist fromJson(Map map) { return CurrentPlaylist( id: map["id"], - tracks: List.castFrom( - map["tracks"].map((track) => Track.fromJson(track)).toList()), + tracks: List.castFrom(map["tracks"] + .map( + (track) => map["isLocal"] == true + ? SpotubeTrack.fromJson(track) + : Track.fromJson(track), + ) + .toList()), name: map["name"], thumbnail: map["thumbnail"], isLocal: map["isLocal"], @@ -108,7 +114,10 @@ class CurrentPlaylist { return { "id": id, "name": name, - "tracks": tracks.map((track) => track.toJson()).toList(), + "tracks": tracks + .map((track) => + track is SpotubeTrack ? track.toJson() : track.toJson()) + .toList(), "thumbnail": thumbnail, "isLocal": isLocal, }; diff --git a/lib/models/Intents.dart b/lib/models/Intents.dart index 8254a4e46..67e4466e5 100644 --- a/lib/models/Intents.dart +++ b/lib/models/Intents.dart @@ -30,9 +30,15 @@ class PlayPauseAction extends Action { } else if (playback.track != null && playback.currentDuration == Duration.zero && await playback.player.getCurrentPosition() == Duration.zero) { - final track = Track.fromJson(playback.track!.toJson()); - playback.track = null; - await playback.play(track); + if (playback.track!.ytUri.startsWith("http")) { + final track = Track.fromJson(playback.track!.toJson()); + playback.track = null; + await playback.play(track); + } else { + final track = playback.track; + playback.track = null; + await playback.play(track!); + } } else { await playback.togglePlayPause(); } diff --git a/lib/provider/Playback.dart b/lib/provider/Playback.dart index f5429208c..1bb4ce918 100644 --- a/lib/provider/Playback.dart +++ b/lib/provider/Playback.dart @@ -576,8 +576,8 @@ class Playback extends PersistedChangeNotifier { track = SpotubeTrack.fromJson(trackMap); } volume = map["volume"] ?? volume; - } catch (e) { - _logger.e("loadFromLocal", e); + } catch (e, stack) { + _logger.e("loadFromLocal", e, stack); } }