koel/resources/assets/js/services/volumeManager.ts

36 lines
666 B
TypeScript
Raw Normal View History

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
2022-11-02 14:06:53 +00:00
this.set(preferenceStore.volume)
}
public get () {
return this.volume.value
}
public set (volume: number, persist = true) {
if (persist) {
2022-11-02 14:06:53 +00:00
preferenceStore.volume = volume
}
this.volume.value = volume
this.input.value = String(volume)
}
public mute () {
this.set(0, false)
}
public unmute () {
2022-11-02 14:06:53 +00:00
this.set(preferenceStore.volume)
}
}
export const volumeManager = new VolumeManager()