Use saved settings instead of local storage noShadows, fast_ui_mode, avatar_style and hotswap_enabled are now using settings json instead of local storage.

d153991a11c42b976a13e13b06f1b7d2280bea7a

d-ber <davide.bertalero@studenti.unimi.it>

2 files changed, +12 -33Showing whitespace changes
public/script.js+3 -0
@@ -84,6 +84,7 @@ import {
8484 context_presets,
8585 resetMovableStyles,
8686 forceCharacterEditorTokenize,
87+ applyPowerUserSettings,
8788} from './scripts/power-user.js';
8889
8990import {
@@ -6450,6 +6451,8 @@ export async function getSettings() {
64506451 // Load power user settings
64516452 await loadPowerUserSettings(settings, data);
64526453
6454+ applyPowerUserSettings();
6455+
64536456 // Load character tags
64546457 loadTagsSettings(settings);
64556458
public/scripts/power-user.js+9 -33
@@ -60,6 +60,7 @@ export {
6060 power_user,
6161 send_on_enter_options,
6262 getContextSettings,
63+ applyPowerUserSettings,
6364};
6465
6566export const MAX_CONTEXT_DEFAULT = 8192;
@@ -300,8 +301,6 @@ let movingUIPresets = [];
300301export let context_presets = [];
301302
302303const storage_keys = {
303- fast_ui_mode: 'TavernAI_fast_ui_mode',
304- avatar_style: 'TavernAI_avatar_style',
305304 chat_display: 'TavernAI_chat_display',
306305 chat_width: 'chat_width',
307306 font_scale: 'TavernAI_font_scale',
@@ -323,9 +322,7 @@ const storage_keys = {
323322
324323 waifuMode: 'TavernAI_waifuMode',
325324 movingUI: 'TavernAI_movingUI',
326- noShadows: 'TavernAI_noShadows',
327325
328- hotswap_enabled: 'HotswapEnabled',
329326 timer_enabled: 'TimerEnabled',
330327 timestamps_enabled: 'TimestampsEnabled',
331328 timestamp_model_icon: 'TimestampModelIcon',
@@ -458,8 +455,6 @@ function fixMarkdown(text, forDisplay) {
458455}
459456
460457function switchHotswap() {
461- const value = localStorage.getItem(storage_keys.hotswap_enabled);
462- power_user.hotswap_enabled = value === null ? true : value == 'true';
463458 $('body').toggleClass('no-hotswap', !power_user.hotswap_enabled);
464459 $('#hotswapEnabled').prop('checked', power_user.hotswap_enabled);
465460}
@@ -971,8 +966,6 @@ async function CreateZenSliders(elmnt) {
971966 }
972967}
973968function switchUiMode() {
974- const fastUi = localStorage.getItem(storage_keys.fast_ui_mode);
975- power_user.fast_ui_mode = fastUi === null ? true : fastUi == 'true';
976969 $('body').toggleClass('no-blur', power_user.fast_ui_mode);
977970 $('#fast_ui_mode').prop('checked', power_user.fast_ui_mode);
978971 if (power_user.fast_ui_mode) {
@@ -1039,9 +1032,7 @@ function switchMovingUI() {
10391032 }
10401033}
10411034
10421035function noShadowsapplyNoShadows() {
1043- const noShadows = localStorage.getItem(storage_keys.noShadows);
1044- power_user.noShadows = noShadows === null ? false : noShadows == 'true';
10451036 $('body').toggleClass('noShadows', power_user.noShadows);
10461037 $('#noShadowsmode').prop('checked', power_user.noShadows);
10471038 if (power_user.noShadows) {
@@ -1055,12 +1046,9 @@ function noShadows() {
10551046}
10561047
10571048function applyAvatarStyle() {
1058- power_user.avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? avatar_styles.ROUND);
10591049 $('body').toggleClass('big-avatars', power_user.avatar_style === avatar_styles.RECTANGULAR);
10601050 $('body').toggleClass('square-avatars', power_user.avatar_style === avatar_styles.SQUARE);
10611051 $('#avatar_style').val(power_user.avatar_style).prop('selected', true);
1062- //$(`input[name="avatar_style"][value="${power_user.avatar_style}"]`).prop("checked", true);
1063-
10641052}
10651053
10661054function applyChatDisplay() {
@@ -1255,7 +1243,6 @@ async function applyTheme(name) {
12551243 {
12561244 key: 'fast_ui_mode',
12571245 action: async () => {
1258- localStorage.setItem(storage_keys.fast_ui_mode, power_user.fast_ui_mode);
12591246 switchUiMode();
12601247 },
12611248 },
@@ -1276,15 +1263,13 @@ async function applyTheme(name) {
12761263 {
12771264 key: 'avatar_style',
12781265 action: async () => {
1279- localStorage.setItem(storage_keys.avatar_style, power_user.avatar_style);
12801266 applyAvatarStyle();
12811267 },
12821268 },
12831269 {
12841270 key: 'noShadows',
12851271 action: async () => {
1286- localStorage.setItem(storage_keys.noShadows, power_user.noShadows);
1272+ applyNoShadows();
1287- noShadows();
12881273 },
12891274 },
12901275 {
@@ -1365,7 +1350,6 @@ async function applyTheme(name) {
13651350 {
13661351 key: 'hotswap_enabled',
13671352 action: async () => {
1368- localStorage.setItem(storage_keys.hotswap_enabled, Boolean(power_user.hotswap_enabled));
13691353 switchHotswap();
13701354 },
13711355 },
@@ -1449,6 +1433,7 @@ async function showDebugMenu() {
14491433 callGenericPopup(template, POPUP_TYPE.TEXT, '', { wide: true, large: true, allowVerticalScrolling: true });
14501434}
14511435
1436+function applyPowerUserSettings() {
14521437 switchUiMode();
14531438 applyFontScale('forced');
14541439 applyThemeColor();
@@ -1458,7 +1443,7 @@ applyBlurStrength();
14581443 applyShadowWidth();
14591444 applyCustomCSS();
14601445 switchMovingUI();
14611446noShadows applyNoShadows();
14621447 switchHotswap();
14631448 switchTimer();
14641449 switchTimestamps();
@@ -1467,6 +1452,8 @@ switchMesIDDisplay();
14671452 switchHideChatAvatars();
14681453 switchTokenCount();
14691454 switchMessageActions();
1455+}
1456+
14701457
14711458function getExampleMessagesBehavior() {
14721459 if (power_user.strip_examples) {
@@ -1530,10 +1517,7 @@ async function loadPowerUserSettings(settings, data) {
15301517 }
15311518
15321519 // These are still local storage
1533- const fastUi = localStorage.getItem(storage_keys.fast_ui_mode);
15341520 const movingUI = localStorage.getItem(storage_keys.movingUI);
1535- const noShadows = localStorage.getItem(storage_keys.noShadows);
1536- const hotswap = localStorage.getItem(storage_keys.hotswap_enabled);
15371521 const timer = localStorage.getItem(storage_keys.timer_enabled);
15381522 const timestamps = localStorage.getItem(storage_keys.timestamps_enabled);
15391523 const mesIDDisplay = localStorage.getItem(storage_keys.mesIDDisplay_enabled);
@@ -1554,10 +1538,7 @@ async function loadPowerUserSettings(settings, data) {
15541538 localStorage.removeItem(storage_keys.auto_connect_legacy);
15551539 }
15561540
1557- power_user.fast_ui_mode = fastUi === null ? true : fastUi == 'true';
15581541 power_user.movingUI = movingUI === null ? false : movingUI == 'true';
1559- power_user.noShadows = noShadows === null ? false : noShadows == 'true';
1560- power_user.hotswap_enabled = hotswap === null ? true : hotswap == 'true';
15611542 power_user.timer_enabled = timer === null ? true : timer == 'true';
15621543 power_user.timestamps_enabled = timestamps === null ? true : timestamps == 'true';
15631544 power_user.mesIDDisplay_enabled = mesIDDisplay === null ? true : mesIDDisplay == 'true';
@@ -1565,8 +1546,6 @@ async function loadPowerUserSettings(settings, data) {
15651546 power_user.expand_message_actions = expandMessageActions === null ? true : expandMessageActions == 'true';
15661547 power_user.enableZenSliders = enableZenSliders === null ? false : enableZenSliders == 'true';
15671548 power_user.enableLabMode = enableLabMode === null ? false : enableLabMode == 'true';
1568- power_user.avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? avatar_styles.ROUND);
1569- //power_user.chat_display = Number(localStorage.getItem(storage_keys.chat_display) ?? chat_styles.DEFAULT);
15701549 power_user.chat_width = Number(localStorage.getItem(storage_keys.chat_width) ?? 50);
15711550 power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
15721551 power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 10);
@@ -3299,7 +3278,6 @@ $(document).ready(() => {
32993278 // Settings that go to local storage
33003279 $('#fast_ui_mode').change(function () {
33013280 power_user.fast_ui_mode = $(this).prop('checked');
3302- localStorage.setItem(storage_keys.fast_ui_mode, power_user.fast_ui_mode);
33033281 switchUiMode();
33043282 saveSettingsDebounced();
33053283 });
@@ -3326,8 +3304,7 @@ $(document).ready(() => {
33263304
33273305 $('#noShadowsmode').change(function () {
33283306 power_user.noShadows = $(this).prop('checked');
3329- localStorage.setItem(storage_keys.noShadows, power_user.noShadows);
3307+ applyNoShadows();
3330- noShadows();
33313308 saveSettingsDebounced();
33323309 });
33333310
@@ -3336,7 +3313,6 @@ $(document).ready(() => {
33363313 $('#avatar_style').on('change', function () {
33373314 const value = $(this).find(':selected').val();
33383315 power_user.avatar_style = Number(value);
3339- localStorage.setItem(storage_keys.avatar_style, power_user.avatar_style);
33403316 applyAvatarStyle();
33413317 saveSettingsDebounced();
33423318 });
@@ -3719,8 +3695,8 @@ $(document).ready(() => {
37193695 $('#hotswapEnabled').on('input', function () {
37203696 const value = !!$(this).prop('checked');
37213697 power_user.hotswap_enabled = value;
3722- localStorage.setItem(storage_keys.hotswap_enabled, Boolean(power_user.hotswap_enabled));
37233698 switchHotswap();
3699+ saveSettingsDebounced();
37243700 });
37253701
37263702 $('#prefer_character_prompt').on('input', function () {