Skip to content

Commit 6800de7

Browse files
committed
persistence
1 parent 6c6d5ac commit 6800de7

4 files changed

Lines changed: 34 additions & 24 deletions

File tree

src/renderer/components/OutputDiagram/blobs/SourceBlob.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import GenericBlob from "./GenericBlob.vue";
1717
import { MediaSourceType } from "@/logic/MediaSource";
1818
const router = useRouter();
1919
20-
const sourceType = ref(MediaSourceType.Generic);
20+
const sourceType = ref(MediaSourceType.Local);
2121
2222
const updateSourceType = (track: Track) => {
2323
sourceType.value = track.sourceType;

src/renderer/logic/MediaSource/SubsonicMediaSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class SubsonicMediaSource extends MediaSource {
5252

5353
setInterval(() => this.getScanStatus(), 1000);
5454
this.getScanStatus();
55-
this.sync();
55+
// this.sync();
5656
this.fetchFavoriteSongs();
5757
}
5858

src/renderer/logic/queue.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { type Amethyst, amethyst } from "@/amethyst.js";
88
import { fisherYatesShuffle } from "@/logic/math.js";
99
import { Track } from "@/logic/track.js";
1010

11+
import { MediaSourceType } from "./MediaSource/index.js";
12+
1113
const COMPARATORS_BY_METHOD = {
1214
default: () => 0,
1315
trackNumber: (a, b) => {
@@ -44,7 +46,7 @@ const COMPARATORS_BY_METHOD = {
4446
export type PossibleSortingMethods = keyof typeof COMPARATORS_BY_METHOD;
4547

4648
export class Queue {
47-
private savedQueue = useLocalStorage<string[]>("queuev2", []);
49+
private savedQueue = useLocalStorage<{ path: string; type: MediaSourceType }[]>("queuev2", []);
4850
private list: Ref<Map<string, Track>> = ref(new Map());
4951
private lastSearch = "";
5052
private lastSearchList: Track[] = [];
@@ -55,9 +57,19 @@ export class Queue {
5557
public currentSortingDirection: Ref<"ascending" | "descending"> = ref("ascending");
5658

5759
public constructor(private amethyst: Amethyst, paths?: string[]) {
58-
paths
59-
? this.add(paths)
60-
: this.add(this.savedQueue.value);
60+
if (paths) this.add(paths);
61+
else {
62+
// load saved queue from local storage
63+
this.savedQueue.value.forEach((item) => {
64+
const track = new Track(this.amethyst, item.path);
65+
66+
if (item.type == MediaSourceType.Subsonic) {
67+
track.sourceType = MediaSourceType.Subsonic;
68+
}
69+
70+
this.add(track);
71+
});
72+
}
6173
}
6274

6375
public getList() {
@@ -112,7 +124,7 @@ export class Queue {
112124
* Saves the current queue to local storage for persistance
113125
*/
114126
private syncLocalStorage() {
115-
this.savedQueue.value = this.getList().map((t) => t.absolutePath);
127+
this.savedQueue.value = this.getList().map((t) => ({ path: t.absolutePath, type: t.sourceType }));
116128
}
117129

118130
/**

src/renderer/logic/track.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,25 +320,23 @@ export class Track {
320320
if (metadata) {
321321
metadata.common.picture = [];
322322
}
323-
324-
if (force && this.amethyst.getCurrentPlatform() == "desktop") {
325-
window.fs.writeFile(this.getCachePath(true), JSON.stringify({
326-
cover,
327-
metadata,
328-
sourceType: this.sourceType,
329-
coverUrl: this.coverUrl,
330-
title: this.title,
331-
duration: this.duration,
332-
album: this.album,
333-
artists: this.artists,
334-
size: this.size,
335-
bitRate: this.bitRate,
336-
}, null, 2)).catch((error) => {
337-
console.error("Failed to write metadata cache file, did you delete the 'Metadata Cache' folder?", error);
338-
});
339-
}
340323
};
341324

325+
if (force && this.amethyst.getCurrentPlatform() == "desktop") {
326+
window.fs.writeFile(this.getCachePath(true), JSON.stringify({
327+
sourceType: this.sourceType,
328+
coverUrl: this.coverUrl,
329+
title: this.title,
330+
duration: this.duration,
331+
album: this.album,
332+
artists: this.artists,
333+
size: this.size,
334+
bitRate: this.bitRate,
335+
}, null, 2)).catch((error) => {
336+
console.error("Failed to write metadata cache file, did you delete the 'Metadata Cache' folder?", error);
337+
});
338+
}
339+
342340
this.isLoading.value = false;
343341
this.isLoaded.value = true;
344342
};

0 commit comments

Comments
 (0)