0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2025-01-03 11:20:07 -05:00

Improve quality

This commit is contained in:
dragongoose 2023-08-18 13:12:06 -04:00
parent 93ca3a612a
commit fc498f078d
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5
3 changed files with 40 additions and 24 deletions

View file

@ -4,6 +4,7 @@ import videojs from 'video.js'
import 'videojs-contrib-quality-levels' import 'videojs-contrib-quality-levels'
import type { QualityLevelList, QualityLevel } from 'videojs-contrib-quality-levels' import type { QualityLevelList, QualityLevel } from 'videojs-contrib-quality-levels'
import i18n from '@/i18n' import i18n from '@/i18n'
import { getSetting } from '@/mixins'
const getQualityFromSettings = (qualityLevels) => { const getQualityFromSettings = (qualityLevels) => {
const settings = localStorage.getItem("settings") const settings = localStorage.getItem("settings")
@ -52,7 +53,7 @@ export const createQualitySelector = (player: any) => {
} }
// set quality on startup // set quality on startup
const startingQuality = getQualityFromSettings() const startingQuality = getSetting("defaultQuality")
const id = formatedQualities.find((i) => i.name === startingQuality)?.id const id = formatedQualities.find((i) => i.name === startingQuality)?.id
setQuality(id) setQuality(id)

View file

@ -41,13 +41,43 @@ export async function getEndpoint(endpoint: string) {
return data return data
} }
export function chatVisible() { export function getDefaultSettings() {
const storage = localStorage.getItem('settings') return {
if (!storage) return true "audioOnly": {
const parsed = JSON.parse(storage) "name": "Audio Only",
"selected": false,
"type": "checkbox"
},
"defaultQuality": {
"name": "Default Quality",
"options": ["160p", "360p", "480p", "720p", "1080p"],
"selected": "480p",
"type": "option"
},
"chatVisible": {
"name": "Hide Chat",
"selected": false,
"type": "checkbox"
},
}
}
export function getSetting(key: string): boolean | string {
const storage = localStorage.getItem('settings')
let parsed
if (!storage) {
parsed = getDefaultSettings()
} else {
parsed = JSON.parse(storage)
}
return parsed[key].selected
}
export function chatVisible() {
const p = getSetting("chatVisible")
// Flip becuase on the setting page it's // Flip becuase on the setting page it's
// displayed as "Hide Chat", but the value // displayed as "Hide Chat", but the value
// is chatVisible // is chatVisible
return !parsed.chatVisible.selected return !p
} }

View file

@ -1,28 +1,13 @@
<script lang="ts"> <script lang="ts">
import { getDefaultSettings } from '@/mixins'
export default { export default {
setup() { setup() {
let settings let settings
let storedSettings = localStorage.getItem("settings") let storedSettings = localStorage.getItem("settings")
if (storedSettings === null) { if (storedSettings === null) {
settings = { settings = getDefaultSettings()
"audioOnly": {
"name": "Audio Only",
"selected": false,
"type": "checkbox"
},
"defaultQuality": {
"name": "Default Quality",
"options": ["160p", "360p", "480p", "720p", "1080p"],
"selected": "480p",
"type": "option"
},
"chatVisible": {
"name": "Hide Chat",
"selected": false,
"type": "checkbox"
},
}
} else { } else {
settings = JSON.parse(storedSettings) settings = JSON.parse(storedSettings)
} }