From 12d6bd2c383b449278f9f0e25e218a76fd0cdbf3 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Fri, 18 Aug 2023 14:23:59 -0400 Subject: [PATCH] Move settings related functions --- src/mixins.ts | 44 +------------------------------------- src/settingsManager.ts | 42 ++++++++++++++++++++++++++++++++++++ src/views/SettingsView.vue | 2 +- src/views/UserView.vue | 3 ++- src/views/VodView.vue | 3 ++- 5 files changed, 48 insertions(+), 46 deletions(-) create mode 100644 src/settingsManager.ts diff --git a/src/mixins.ts b/src/mixins.ts index d2a73a1..7d43667 100644 --- a/src/mixins.ts +++ b/src/mixins.ts @@ -39,46 +39,4 @@ export async function getEndpoint(endpoint: string) { const data = rawData.data return data -} - -export function getDefaultSettings() { - return { - version: import.meta.env.SAFETWITCH_TAG, - 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 !p -} +} \ No newline at end of file diff --git a/src/settingsManager.ts b/src/settingsManager.ts new file mode 100644 index 0000000..6d6276d --- /dev/null +++ b/src/settingsManager.ts @@ -0,0 +1,42 @@ +export function getDefaultSettings() { + return { + version: import.meta.env.SAFETWITCH_TAG, + 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 !p + } + \ No newline at end of file diff --git a/src/views/SettingsView.vue b/src/views/SettingsView.vue index 8639f79..e718934 100644 --- a/src/views/SettingsView.vue +++ b/src/views/SettingsView.vue @@ -1,5 +1,5 @@