2023-10-04 17:44:14 -04:00
|
|
|
const locales = ['en-US', 'es-ES', 'nl-NL', 'pt-PT', 'fa-IR', 'he-IL', 'ru-RU', 'ko-KR', 'cs-CZ', 'pl-PL', 'it-IT', 'fr-FR', 'uk-UA', 'de-DE']
|
|
|
|
const languages = ['English', 'Español', 'Nederlands', 'Português', 'فارسی', 'עִבְרִית', 'Русский', '한국어', 'Česky', 'Polski', 'Italia', 'Français', 'Українська', 'Deutsch']
|
|
|
|
|
2023-08-19 20:37:11 -04:00
|
|
|
export const setLanguage = (selectedLanguage: string, i18n: any) => {
|
|
|
|
// Locales and languages in arrays to match them
|
|
|
|
const locale = locales[languages.indexOf(selectedLanguage)]
|
|
|
|
localStorage.setItem("language", locale)
|
|
|
|
i18n.locale = locale
|
|
|
|
}
|
|
|
|
|
2023-11-04 19:34:22 -04:00
|
|
|
export interface SettingsCheckbox {
|
|
|
|
name: string
|
|
|
|
selected: boolean,
|
|
|
|
type: 'checkbox'
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface SettingsOptions {
|
|
|
|
name: string
|
|
|
|
options: string[]
|
|
|
|
selected: string
|
|
|
|
type: 'option'
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Settings {
|
|
|
|
version: string
|
|
|
|
settings: {
|
|
|
|
audioOnly: SettingsCheckbox
|
|
|
|
defaultQuality: SettingsOptions
|
|
|
|
language: SettingsOptions
|
|
|
|
chatVisible: SettingsCheckbox
|
|
|
|
streamTagsVisible: SettingsCheckbox
|
|
|
|
streamerAboutSectionVisible: SettingsCheckbox
|
|
|
|
autoplay: SettingsCheckbox
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getDefaultSettings(): Settings {
|
2023-08-18 14:23:59 -04:00
|
|
|
return {
|
2023-08-18 14:40:25 -04:00
|
|
|
version: import.meta.env.SAFETWITCH_TAG,
|
2023-11-04 19:34:22 -04:00
|
|
|
settings: {
|
|
|
|
audioOnly: {
|
|
|
|
name: 'audioOnly',
|
|
|
|
selected: false,
|
|
|
|
type: 'checkbox'
|
|
|
|
},
|
|
|
|
defaultQuality: {
|
|
|
|
name: 'defaultQuality',
|
|
|
|
options: ['160p', '360p', '480p', '720p', '1080p'],
|
|
|
|
selected: '480p',
|
|
|
|
type: 'option'
|
|
|
|
},
|
|
|
|
language: {
|
|
|
|
name: 'language',
|
|
|
|
options: languages,
|
|
|
|
selected: 'English',
|
|
|
|
type: 'option'
|
|
|
|
},
|
|
|
|
chatVisible: {
|
|
|
|
name: 'chatVisible',
|
|
|
|
selected: false,
|
|
|
|
type: 'checkbox'
|
|
|
|
},
|
|
|
|
streamTagsVisible: {
|
|
|
|
name: 'streamTagsVisible',
|
|
|
|
selected: true,
|
|
|
|
type: 'checkbox'
|
|
|
|
},
|
|
|
|
streamerAboutSectionVisible: {
|
|
|
|
name: 'streamerAboutSectionVisible',
|
|
|
|
selected: true,
|
|
|
|
type: 'checkbox'
|
|
|
|
},
|
|
|
|
autoplay: {
|
|
|
|
name: 'autoplay',
|
|
|
|
selected: false,
|
|
|
|
type: 'checkbox'
|
|
|
|
}
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
2023-08-18 14:23:59 -04:00
|
|
|
}
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
|
|
|
|
2023-11-04 19:34:22 -04:00
|
|
|
/**
|
|
|
|
* Syncs older user setting to the latest version
|
|
|
|
* @param settings Settings of the Settings type
|
|
|
|
* @returns The synced settings and a boolean stating if the settings were modified
|
|
|
|
*/
|
|
|
|
export function syncUserSettings(settings: Settings): {settings: Settings, changed: boolean}{
|
2023-08-18 14:40:25 -04:00
|
|
|
const defaultSettings = getDefaultSettings()
|
2023-11-04 19:34:22 -04:00
|
|
|
let userSettings = settings
|
|
|
|
|
|
|
|
// converting settings storage from versions older
|
|
|
|
// than 2.4.1
|
|
|
|
let oldMigration = false
|
2023-08-18 14:40:25 -04:00
|
|
|
|
2023-11-04 19:34:22 -04:00
|
|
|
|
|
|
|
if (userSettings.version === import.meta.env.SAFETWITCH_TAG) {
|
2023-08-18 14:40:25 -04:00
|
|
|
console.log('Settings up to date!')
|
2023-11-04 19:34:22 -04:00
|
|
|
return { settings: userSettings, changed: false }
|
2023-08-18 14:40:25 -04:00
|
|
|
} else {
|
|
|
|
console.log('Settings outdated... Migrating')
|
2023-11-04 19:34:22 -04:00
|
|
|
// converts v2.4.1 to 241
|
|
|
|
let settingsVersion = Number(userSettings.version.slice(1, defaultSettings.version.length).split(".").join(""))
|
|
|
|
|
|
|
|
if (settingsVersion < 241) {
|
|
|
|
oldMigration = true
|
|
|
|
}
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
|
|
|
|
2023-11-04 19:34:22 -04:00
|
|
|
if (oldMigration) {
|
|
|
|
let oldSettings: any = userSettings
|
|
|
|
delete oldSettings.version
|
|
|
|
let migrated: Settings = {
|
|
|
|
version: defaultSettings.version,
|
|
|
|
settings: {
|
|
|
|
...oldSettings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
userSettings = migrated
|
|
|
|
}
|
|
|
|
console.log(userSettings)
|
2023-08-18 14:40:25 -04:00
|
|
|
|
2023-11-04 19:34:22 -04:00
|
|
|
const synced = { ...defaultSettings, ...userSettings }
|
2023-11-04 16:53:25 -04:00
|
|
|
|
|
|
|
// update avaliable languages
|
2023-11-04 19:34:22 -04:00
|
|
|
synced.settings.language.options = defaultSettings.settings.language.options
|
2023-08-18 15:04:58 -04:00
|
|
|
synced.version = import.meta.env.SAFETWITCH_TAG
|
2023-08-18 14:40:25 -04:00
|
|
|
localStorage.setItem('settings', JSON.stringify(synced))
|
|
|
|
console.log('Migrated!')
|
2023-11-04 19:34:22 -04:00
|
|
|
return { settings: synced, changed: true }
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getSetting(key: string): boolean | string {
|
2023-08-18 14:23:59 -04:00
|
|
|
const storage = localStorage.getItem('settings')
|
|
|
|
let parsed
|
|
|
|
if (!storage) {
|
2023-08-18 14:40:25 -04:00
|
|
|
parsed = getDefaultSettings()
|
2023-08-18 14:23:59 -04:00
|
|
|
} else {
|
2023-08-18 14:40:25 -04:00
|
|
|
parsed = JSON.parse(storage)
|
2023-08-18 14:23:59 -04:00
|
|
|
}
|
2023-08-18 14:40:25 -04:00
|
|
|
|
2023-08-18 14:23:59 -04:00
|
|
|
return parsed[key].selected
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
|
|
|
|
2023-09-27 16:43:55 -04:00
|
|
|
export function getTheme() {
|
|
|
|
return localStorage.getItem('theme') || "light"
|
|
|
|
}
|
|
|
|
|
2023-08-18 14:40:25 -04:00
|
|
|
export function chatVisible() {
|
2023-08-18 14:23:59 -04:00
|
|
|
const p = getSetting('chatVisible')
|
|
|
|
// Flip becuase on the setting page it's
|
|
|
|
// displayed as "Hide Chat", but the value
|
|
|
|
// is chatVisible
|
|
|
|
return !p
|
2023-08-18 14:40:25 -04:00
|
|
|
}
|
2023-09-25 17:25:42 -04:00
|
|
|
|
|
|
|
export const themeList = [
|
|
|
|
{
|
|
|
|
// name your theme anything that could be a valid css class name
|
|
|
|
// remember what you named your theme because you will use it as a class to enable the theme
|
|
|
|
name: 'dark',
|
|
|
|
// put any overrides your theme has here
|
|
|
|
// just as if you were to extend tailwind's theme like normal https://tailwindcss.com/docs/theme#extending-the-default-theme
|
|
|
|
extend: {
|
|
|
|
colors: {
|
|
|
|
"primary": '#141515',
|
|
|
|
"secondary": '#1e1f1f',
|
|
|
|
"overlay0": '#282a2a',
|
|
|
|
"overlay1": '#323434',
|
|
|
|
"surface0": '#393B3B',
|
|
|
|
"surface1": '#3F4242',
|
|
|
|
"crust": '#0C0C0C',
|
|
|
|
"purple": '#D946EF',
|
|
|
|
"red": "#980C0C",
|
|
|
|
"neutral": "#bdbdbd",
|
|
|
|
"contrast": "white",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// name your theme anything that could be a valid css class name
|
|
|
|
// remember what you named your theme because you will use it as a class to enable the theme
|
|
|
|
name: 'light',
|
|
|
|
// put any overrides your theme has here
|
|
|
|
// just as if you were to extend tailwind's theme like normal https://tailwindcss.com/docs/theme#extending-the-default-theme
|
|
|
|
extend: {
|
|
|
|
colors: {
|
|
|
|
"primary": '#ebeaea',
|
|
|
|
"secondary": '#e1e0e0',
|
|
|
|
"overlay0": '#d7d5d5',
|
|
|
|
"overlay1": '#cdcbcb',
|
|
|
|
"surface0": '#c6c4c4',
|
|
|
|
"surface1": '#c0bdbd',
|
|
|
|
"crust": '#fafafa',
|
|
|
|
"purple": '#D946EF',
|
|
|
|
"red": "#e81304",
|
|
|
|
"neutral": "gray",
|
|
|
|
"contrast": "black",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|