Remove async in theme toggles load

This commit is contained in:
Cohee
2024-09-04 22:15:29 +03:00
parent 7e5417c072
commit 0b89c8aee9
2 changed files with 42 additions and 41 deletions

View File

@ -6480,6 +6480,7 @@ export async function getSettings() {
// Load power user settings // Load power user settings
await loadPowerUserSettings(settings, data); await loadPowerUserSettings(settings, data);
// Apply theme toggles from power user settings
applyPowerUserSettings(); applyPowerUserSettings();
// Load character tags // Load character tags

View File

@ -1027,7 +1027,7 @@ function applyChatWidth(type) {
$('#chat_width_slider_counter').val(power_user.chat_width); $('#chat_width_slider_counter').val(power_user.chat_width);
} }
async function applyThemeColor(type) { function applyThemeColor(type) {
if (type === 'main') { if (type === 'main') {
document.documentElement.style.setProperty('--SmartThemeBodyColor', power_user.main_text_color); document.documentElement.style.setProperty('--SmartThemeBodyColor', power_user.main_text_color);
const color = power_user.main_text_color.split('(')[1].split(')')[0].split(','); const color = power_user.main_text_color.split('(')[1].split(')')[0].split(',');
@ -1068,7 +1068,7 @@ async function applyThemeColor(type) {
} }
} }
async function applyCustomCSS() { function applyCustomCSS() {
$('#customCSS').val(power_user.custom_css); $('#customCSS').val(power_user.custom_css);
var styleId = 'custom-style'; var styleId = 'custom-style';
var style = document.getElementById(styleId); var style = document.getElementById(styleId);
@ -1081,20 +1081,20 @@ async function applyCustomCSS() {
style.innerHTML = power_user.custom_css; style.innerHTML = power_user.custom_css;
} }
async function applyBlurStrength() { function applyBlurStrength() {
document.documentElement.style.setProperty('--blurStrength', String(power_user.blur_strength)); document.documentElement.style.setProperty('--blurStrength', String(power_user.blur_strength));
$('#blur_strength_counter').val(power_user.blur_strength); $('#blur_strength_counter').val(power_user.blur_strength);
$('#blur_strength').val(power_user.blur_strength); $('#blur_strength').val(power_user.blur_strength);
} }
async function applyShadowWidth() { function applyShadowWidth() {
document.documentElement.style.setProperty('--shadowWidth', String(power_user.shadow_width)); document.documentElement.style.setProperty('--shadowWidth', String(power_user.shadow_width));
$('#shadow_width_counter').val(power_user.shadow_width); $('#shadow_width_counter').val(power_user.shadow_width);
$('#shadow_width').val(power_user.shadow_width); $('#shadow_width').val(power_user.shadow_width);
} }
async function applyFontScale(type) { function applyFontScale(type) {
//this is to allow forced setting on page load, theme swap, etc //this is to allow forced setting on page load, theme swap, etc
if (type === 'forced') { if (type === 'forced') {
document.documentElement.style.setProperty('--fontScale', String(power_user.font_scale)); document.documentElement.style.setProperty('--fontScale', String(power_user.font_scale));
@ -1109,7 +1109,7 @@ async function applyFontScale(type) {
$('#font_scale').val(power_user.font_scale); $('#font_scale').val(power_user.font_scale);
} }
async function applyTheme(name) { function applyTheme(name) {
const theme = themes.find(x => x.name == name); const theme = themes.find(x => x.name == name);
if (!theme) { if (!theme) {
@ -1129,61 +1129,61 @@ async function applyTheme(name) {
{ key: 'border_color', selector: '#border-color-picker', type: 'border' }, { key: 'border_color', selector: '#border-color-picker', type: 'border' },
{ {
key: 'blur_strength', key: 'blur_strength',
action: async () => { action: () => {
await applyBlurStrength(); applyBlurStrength();
}, },
}, },
{ {
key: 'custom_css', key: 'custom_css',
action: async () => { action: () => {
await applyCustomCSS(); applyCustomCSS();
}, },
}, },
{ {
key: 'shadow_width', key: 'shadow_width',
action: async () => { action: () => {
await applyShadowWidth(); applyShadowWidth();
}, },
}, },
{ {
key: 'font_scale', key: 'font_scale',
action: async () => { action: () => {
await applyFontScale('forced'); applyFontScale('forced');
}, },
}, },
{ {
key: 'fast_ui_mode', key: 'fast_ui_mode',
action: async () => { action: () => {
switchUiMode(); switchUiMode();
}, },
}, },
{ {
key: 'waifuMode', key: 'waifuMode',
action: async () => { action: () => {
switchWaifuMode(); switchWaifuMode();
}, },
}, },
{ {
key: 'chat_display', key: 'chat_display',
action: async () => { action: () => {
applyChatDisplay(); applyChatDisplay();
}, },
}, },
{ {
key: 'avatar_style', key: 'avatar_style',
action: async () => { action: () => {
applyAvatarStyle(); applyAvatarStyle();
}, },
}, },
{ {
key: 'noShadows', key: 'noShadows',
action: async () => { action: () => {
applyNoShadows(); applyNoShadows();
}, },
}, },
{ {
key: 'chat_width', key: 'chat_width',
action: async () => { action: () => {
// If chat width is not set, set it to 50 // If chat width is not set, set it to 50
if (!power_user.chat_width) { if (!power_user.chat_width) {
power_user.chat_width = 50; power_user.chat_width = 50;
@ -1193,88 +1193,88 @@ async function applyTheme(name) {
}, },
{ {
key: 'timer_enabled', key: 'timer_enabled',
action: async () => { action: () => {
switchTimer(); switchTimer();
}, },
}, },
{ {
key: 'timestamps_enabled', key: 'timestamps_enabled',
action: async () => { action: () => {
switchTimestamps(); switchTimestamps();
}, },
}, },
{ {
key: 'timestamp_model_icon', key: 'timestamp_model_icon',
action: async () => { action: () => {
switchIcons(); switchIcons();
}, },
}, },
{ {
key: 'message_token_count_enabled', key: 'message_token_count_enabled',
action: async () => { action: () => {
switchTokenCount(); switchTokenCount();
}, },
}, },
{ {
key: 'mesIDDisplay_enabled', key: 'mesIDDisplay_enabled',
action: async () => { action: () => {
switchMesIDDisplay(); switchMesIDDisplay();
}, },
}, },
{ {
key: 'hideChatAvatars_enabled', key: 'hideChatAvatars_enabled',
action: async () => { action: () => {
switchHideChatAvatars(); switchHideChatAvatars();
}, },
}, },
{ {
key: 'expand_message_actions', key: 'expand_message_actions',
action: async () => { action: () => {
switchMessageActions(); switchMessageActions();
}, },
}, },
{ {
key: 'enableZenSliders', key: 'enableZenSliders',
action: async () => { action: () => {
switchMessageActions(); switchMessageActions();
}, },
}, },
{ {
key: 'enableLabMode', key: 'enableLabMode',
action: async () => { action: () => {
switchMessageActions(); switchMessageActions();
}, },
}, },
{ {
key: 'hotswap_enabled', key: 'hotswap_enabled',
action: async () => { action: () => {
switchHotswap(); switchHotswap();
}, },
}, },
{ {
key: 'bogus_folders', key: 'bogus_folders',
action: async () => { action: () => {
$('#bogus_folders').prop('checked', power_user.bogus_folders); $('#bogus_folders').prop('checked', power_user.bogus_folders);
printCharactersDebounced(); printCharactersDebounced();
}, },
}, },
{ {
key: 'zoomed_avatar_magnification', key: 'zoomed_avatar_magnification',
action: async () => { action: () => {
$('#zoomed_avatar_magnification').prop('checked', power_user.zoomed_avatar_magnification); $('#zoomed_avatar_magnification').prop('checked', power_user.zoomed_avatar_magnification);
printCharactersDebounced(); printCharactersDebounced();
}, },
}, },
{ {
key: 'reduced_motion', key: 'reduced_motion',
action: async () => { action: () => {
$('#reduced_motion').prop('checked', power_user.reduced_motion); $('#reduced_motion').prop('checked', power_user.reduced_motion);
switchReducedMotion(); switchReducedMotion();
}, },
}, },
{ {
key: 'compact_input_area', key: 'compact_input_area',
action: async () => { action: () => {
$('#compact_input_area').prop('checked', power_user.compact_input_area); $('#compact_input_area').prop('checked', power_user.compact_input_area);
switchCompactInputArea(); switchCompactInputArea();
}, },
@ -1285,8 +1285,8 @@ async function applyTheme(name) {
if (theme[key] !== undefined) { if (theme[key] !== undefined) {
power_user[key] = theme[key]; power_user[key] = theme[key];
if (selector) $(selector).attr('color', power_user[key]); if (selector) $(selector).attr('color', power_user[key]);
if (type) await applyThemeColor(type); if (type) applyThemeColor(type);
if (action) await action(); if (action) action();
} else { } else {
if (selector) { $(selector).attr('color', 'rgba(0,0,0,0)'); } if (selector) { $(selector).attr('color', 'rgba(0,0,0,0)'); }
console.debug(`Empty theme key: ${key}`); console.debug(`Empty theme key: ${key}`);
@ -1793,7 +1793,7 @@ async function loadContextSettings() {
.prop('checked', control.isGlobalSetting ? power_user[control.property] : power_user.context[control.property]) .prop('checked', control.isGlobalSetting ? power_user[control.property] : power_user.context[control.property])
.trigger('input'); .trigger('input');
} else { } else {
$element[0].innerText = (control.isGlobalSetting ? power_user[control.property] : power_user.context[control.property]) $element[0].innerText = (control.isGlobalSetting ? power_user[control.property] : power_user.context[control.property]);
$element.trigger('input'); $element.trigger('input');
} }
} }
@ -2156,7 +2156,7 @@ async function deleteTheme() {
power_user.theme = themes[0]?.name; power_user.theme = themes[0]?.name;
saveSettingsDebounced(); saveSettingsDebounced();
if (power_user.theme) { if (power_user.theme) {
await applyTheme(power_user.theme); applyTheme(power_user.theme);
} }
toastr.success('Theme deleted.'); toastr.success('Theme deleted.');
} }
@ -3226,21 +3226,21 @@ $(document).ready(() => {
const applyMode = data?.forced ? 'forced' : 'normal'; const applyMode = data?.forced ? 'forced' : 'normal';
power_user.font_scale = Number(e.target.value); power_user.font_scale = Number(e.target.value);
$('#font_scale_counter').val(power_user.font_scale); $('#font_scale_counter').val(power_user.font_scale);
await applyFontScale(applyMode); applyFontScale(applyMode);
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$('input[name="blur_strength"]').on('input', async function (e) { $('input[name="blur_strength"]').on('input', async function (e) {
power_user.blur_strength = Number(e.target.value); power_user.blur_strength = Number(e.target.value);
$('#blur_strength_counter').val(power_user.blur_strength); $('#blur_strength_counter').val(power_user.blur_strength);
await applyBlurStrength(); applyBlurStrength();
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$('input[name="shadow_width"]').on('input', async function (e) { $('input[name="shadow_width"]').on('input', async function (e) {
power_user.shadow_width = Number(e.target.value); power_user.shadow_width = Number(e.target.value);
$('#shadow_width_counter').val(power_user.shadow_width); $('#shadow_width_counter').val(power_user.shadow_width);
await applyShadowWidth(); applyShadowWidth();
saveSettingsDebounced(); saveSettingsDebounced();
}); });