chore: refactor vue components

This commit is contained in:
2026-09-02 15:21:43 +02:00
parent 8a3dd7a583
commit b903eb416f
30 changed files with 209 additions and 52 deletions
+7
View File
@@ -4,6 +4,7 @@ import {
queue,
queueIdx,
rawQueue,
repeat,
shuffle,
sources
} from '../state';
@@ -27,6 +28,12 @@ export const clearQueue = () => {
duration.value = -1;
playbackPercentage.value = 1;
isPlaying.value = false;
repeat.value = 'off';
shuffle.value = false;
for ( const song of queue.value ) {
sources[ song.source ]?.songUnload( song );
}
};
/**
+2 -2
View File
@@ -7,13 +7,13 @@ import type {
AssociationResult
} from '../plugins/interface';
import type {
Playlist
PlaylistSongs
} from '@/ts/dtype/playlist';
import {
openAssociationManager
} from '@/composables/associationManager';
export const load = ( playlist: Playlist ) => {
export const load = ( playlist: PlaylistSongs ) => {
queue.value = playlist;
rawQueue.value = playlist;
+5
View File
@@ -118,4 +118,9 @@ export interface PlayerSourcePlugin {
* You may use the provided interface elements (search bar and popups) to e.g. ask if user wants to use a playlist, album, etc
*/
'addSongsFromThisSource': ( cb: ( songs: Song[] ) => void ) => void;
/**
* Fully unload a song. This is called on clear of a playlist
*/
'songUnload': ( song: Song ) => Promise<void>;
}
+4 -2
View File
@@ -7,7 +7,8 @@ import {
updateIdentifiers
} from './association';
import {
load
load,
unload
} from './loader';
import {
ref
@@ -38,6 +39,7 @@ export const useLocalPlayer: PlayerSourcePluginInitializer = async (): Promise<P
'association': associate,
'updateIdentifiers': updateIdentifiers,
'mime': 'audio/aac,audio/mpeg,audio/wav,audio/mp4,audio/ogg'
}
},
'songUnload': unload
};
};
@@ -75,3 +75,7 @@ export const load = ( cb: ( songs: Song[] ) => void ) => {
}
};
};
export const unload = async ( song: Song ) => {
URL.revokeObjectURL( song.identifier );
};
+2 -4
View File
@@ -2,9 +2,6 @@ import type {
PlayerSourcePlugin,
PlayerSourcePluginInitializer
} from '../interface';
import type {
Song
} from '@/ts/dtype/playlist';
import {
addFromAppleMusic
} from './search';
@@ -57,7 +54,8 @@ export const useMusicKit: PlayerSourcePluginInitializer = ( storefront: string =
'addSongsFromThisSource': addFromAppleMusic,
'loading': {
'requiresLocalFiles': false
}
},
'songUnload': async () => {}
};
} else {
throw new Error( 'ERR_AUTH' );
+3 -3
View File
@@ -6,7 +6,7 @@ import type {
PlayerSourcePlugin
} from './plugins/interface';
import type {
Playlist
PlaylistSongs
} from '../dtype/playlist';
import type {
RepeatMode
@@ -24,11 +24,11 @@ export const sources: {
export const currentSource = ref( '' );
export const rawQueue: Ref<Playlist> = ref( [] );
export const rawQueue: Ref<PlaylistSongs> = ref( [] );
export const queueIdx = ref( 0 );
export const queue: Ref<Playlist> = ref( [] );
export const queue: Ref<PlaylistSongs> = ref( [] );
export const isPlaying = ref( false );