mirror of
https://github.com/koel/koel
synced 2024-12-20 09:33:23 +00:00
36 lines
684 B
TypeScript
36 lines
684 B
TypeScript
|
import { ref } from 'vue'
|
||
|
import { preferenceStore } from '@/stores'
|
||
|
|
||
|
export class VolumeManager {
|
||
|
private input!: HTMLInputElement
|
||
|
public volume = ref(0)
|
||
|
|
||
|
public init (input: HTMLInputElement) {
|
||
|
this.input = input
|
||
|
this.set(preferenceStore.state.volume)
|
||
|
}
|
||
|
|
||
|
public get () {
|
||
|
return this.volume.value
|
||
|
}
|
||
|
|
||
|
public set (volume: number, persist = true) {
|
||
|
if (persist) {
|
||
|
preferenceStore.state.volume = volume
|
||
|
}
|
||
|
|
||
|
this.volume.value = volume
|
||
|
this.input.value = String(volume)
|
||
|
}
|
||
|
|
||
|
public mute () {
|
||
|
this.set(0, false)
|
||
|
}
|
||
|
|
||
|
public unmute () {
|
||
|
this.set(preferenceStore.state.volume)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const volumeManager = new VolumeManager()
|