From fc498f078dc1f2ac976486ab64228688f18d1d1a Mon Sep 17 00:00:00 2001 From: dragongoose Date: Fri, 18 Aug 2023 13:12:06 -0400 Subject: [PATCH] Improve quality --- src/assets/qualitySelector.ts | 3 ++- src/mixins.ts | 40 ++++++++++++++++++++++++++++++----- src/views/SettingsView.vue | 21 +++--------------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/assets/qualitySelector.ts b/src/assets/qualitySelector.ts index 984e3b6..e35e871 100644 --- a/src/assets/qualitySelector.ts +++ b/src/assets/qualitySelector.ts @@ -4,6 +4,7 @@ import videojs from 'video.js' import 'videojs-contrib-quality-levels' import type { QualityLevelList, QualityLevel } from 'videojs-contrib-quality-levels' import i18n from '@/i18n' +import { getSetting } from '@/mixins' const getQualityFromSettings = (qualityLevels) => { const settings = localStorage.getItem("settings") @@ -52,7 +53,7 @@ export const createQualitySelector = (player: any) => { } // set quality on startup - const startingQuality = getQualityFromSettings() + const startingQuality = getSetting("defaultQuality") const id = formatedQualities.find((i) => i.name === startingQuality)?.id setQuality(id) diff --git a/src/mixins.ts b/src/mixins.ts index acd90df..36596be 100644 --- a/src/mixins.ts +++ b/src/mixins.ts @@ -41,13 +41,43 @@ export async function getEndpoint(endpoint: string) { return data } -export function chatVisible() { - const storage = localStorage.getItem('settings') - if (!storage) return true - const parsed = JSON.parse(storage) +export function getDefaultSettings() { + return { + "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" + }, + } +} +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 // displayed as "Hide Chat", but the value // is chatVisible - return !parsed.chatVisible.selected + return !p } diff --git a/src/views/SettingsView.vue b/src/views/SettingsView.vue index 9f3df88..64d6eb2 100644 --- a/src/views/SettingsView.vue +++ b/src/views/SettingsView.vue @@ -1,28 +1,13 @@