Added fullscreen mode to miniplayer

This commit is contained in:
Eclypsed
2024-04-22 14:18:42 -04:00
parent 2ee60ef302
commit 28e4569507
9 changed files with 391 additions and 166 deletions

View File

@@ -9,44 +9,66 @@ const youtubeMusicBackground: string = 'https://www.gstatic.com/youtube/media/yt
export const backgroundImage: Writable<string> = writable(youtubeMusicBackground)
class Queue {
private currentPos: number | null
private currentPosition: number // -1 means there is no current position
private songs: Song[]
constructor() {
this.currentPos = null
this.currentPosition = -1
this.songs = []
}
public enqueue = (...songs: Song[]) => {
this.songs.push(...songs)
writeableQueue.set(this)
}
public next = () => {
if (this.songs.length === 0) return
if (!this.currentPos) {
this.currentPos = 0
} else {
if (!(this.songs.length > this.currentPos + 1)) return
this.currentPos += 1
}
writeableQueue.set(this)
}
public current = () => {
get current() {
if (this.songs.length > 0) {
if (!this.currentPos) this.currentPos = 0
return this.songs[this.currentPos]
if (this.currentPosition === -1) this.currentPosition = 0
return this.songs[this.currentPosition]
}
return null
}
public getSongs = () => {
set current(newSong: Song | null) {
if (newSong === null) {
this.currentPosition = -1
} else {
const queuePosition = this.songs.findIndex((song) => song === newSong)
if (queuePosition < 0) {
this.songs = [newSong]
this.currentPosition = 0
} else {
this.currentPosition = queuePosition
}
}
writableQueue.set(this)
}
get list() {
return this.songs
}
public next() {
if (this.songs.length === 0 || !(this.songs.length > this.currentPosition + 1)) return
this.currentPosition += 1
writableQueue.set(this)
}
public previous() {
if (this.songs.length === 0 || this.currentPosition <= 0) return
this.currentPosition -= 1
writableQueue.set(this)
}
public enqueue(...songs: Song[]) {
this.songs.push(...songs)
writableQueue.set(this)
}
public clear() {
this.currentPosition = -1
this.songs = []
writableQueue.set(this)
}
}
const writeableQueue: Writable<Queue> = writable(new Queue())
export const queue: Readable<Queue> = readonly(writeableQueue)
const writableQueue: Writable<Queue> = writable(new Queue())
export const queue: Readable<Queue> = readonly(writableQueue)