Skip to content

Commit

Permalink
fix: cached local track is fetched from network, body is not behind A…
Browse files Browse the repository at this point in the history
…ppBar in desktop
  • Loading branch information
KRTirtho committed Oct 12, 2022
1 parent 8a72f62 commit abf4a57
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/components/Home/Shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Shell extends HookConsumerWidget {
),
)
: null,
extendBodyBehindAppBar: true,
body: Row(
children: [
Sidebar(
Expand Down
2 changes: 2 additions & 0 deletions lib/components/Library/UserLocalTracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
Expand Down
15 changes: 12 additions & 3 deletions lib/models/CurrentPlaylist.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:spotify/spotify.dart';
import 'package:spotube/models/SpotubeTrack.dart';

extension AlbumJson on AlbumSimple {
Map<String, dynamic> toJson() {
Expand Down Expand Up @@ -74,8 +75,13 @@ class CurrentPlaylist {
static CurrentPlaylist fromJson(Map<String, dynamic> map) {
return CurrentPlaylist(
id: map["id"],
tracks: List.castFrom<dynamic, Track>(
map["tracks"].map((track) => Track.fromJson(track)).toList()),
tracks: List.castFrom<dynamic, Track>(map["tracks"]
.map(
(track) => map["isLocal"] == true
? SpotubeTrack.fromJson(track)
: Track.fromJson(track),
)
.toList()),
name: map["name"],
thumbnail: map["thumbnail"],
isLocal: map["isLocal"],
Expand Down Expand Up @@ -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,
};
Expand Down
12 changes: 9 additions & 3 deletions lib/models/Intents.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ class PlayPauseAction extends Action<PlayPauseIntent> {
} 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();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/provider/Playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit abf4a57

Please sign in to comment.