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 {
84 context_presets,84 context_presets,
85 resetMovableStyles,85 resetMovableStyles,
86 forceCharacterEditorTokenize,86 forceCharacterEditorTokenize,
87 applyPowerUserSettings,
87} from './scripts/power-user.js';88} from './scripts/power-user.js';
8889
89import {90import {
@@ -6450,6 +6451,8 @@ export async function getSettings() {
6450 // Load power user settings6451 // Load power user settings
6451 await loadPowerUserSettings(settings, data);6452 await loadPowerUserSettings(settings, data);
64526453
6454 applyPowerUserSettings();
6455
6453 // Load character tags6456 // Load character tags
6454 loadTagsSettings(settings);6457 loadTagsSettings(settings);
64556458
public/scripts/power-user.js+9 -33
@@ -60,6 +60,7 @@ export {
60 power_user,60 power_user,
61 send_on_enter_options,61 send_on_enter_options,
62 getContextSettings,62 getContextSettings,
63 applyPowerUserSettings,
63};64};
6465
65export const MAX_CONTEXT_DEFAULT = 8192;66export const MAX_CONTEXT_DEFAULT = 8192;
@@ -300,8 +301,6 @@ let movingUIPresets = [];
300export let context_presets = [];301export let context_presets = [];
301302
302const storage_keys = {303const storage_keys = {
303 fast_ui_mode: 'TavernAI_fast_ui_mode',
304 avatar_style: 'TavernAI_avatar_style',
305 chat_display: 'TavernAI_chat_display',304 chat_display: 'TavernAI_chat_display',
306 chat_width: 'chat_width',305 chat_width: 'chat_width',
307 font_scale: 'TavernAI_font_scale',306 font_scale: 'TavernAI_font_scale',
@@ -323,9 +322,7 @@ const storage_keys = {
323322
324 waifuMode: 'TavernAI_waifuMode',323 waifuMode: 'TavernAI_waifuMode',
325 movingUI: 'TavernAI_movingUI',324 movingUI: 'TavernAI_movingUI',
326 noShadows: 'TavernAI_noShadows',
327325
328 hotswap_enabled: 'HotswapEnabled',
329 timer_enabled: 'TimerEnabled',326 timer_enabled: 'TimerEnabled',
330 timestamps_enabled: 'TimestampsEnabled',327 timestamps_enabled: 'TimestampsEnabled',
331 timestamp_model_icon: 'TimestampModelIcon',328 timestamp_model_icon: 'TimestampModelIcon',
@@ -458,8 +455,6 @@ function fixMarkdown(text, forDisplay) {
458}455}
459456
460function switchHotswap() {457function switchHotswap() {
461 const value = localStorage.getItem(storage_keys.hotswap_enabled);
462 power_user.hotswap_enabled = value === null ? true : value == 'true';
463 $('body').toggleClass('no-hotswap', !power_user.hotswap_enabled);458 $('body').toggleClass('no-hotswap', !power_user.hotswap_enabled);
464 $('#hotswapEnabled').prop('checked', power_user.hotswap_enabled);459 $('#hotswapEnabled').prop('checked', power_user.hotswap_enabled);
465}460}
@@ -971,8 +966,6 @@ async function CreateZenSliders(elmnt) {
971 }966 }
972}967}
973function switchUiMode() {968function switchUiMode() {
974 const fastUi = localStorage.getItem(storage_keys.fast_ui_mode);
975 power_user.fast_ui_mode = fastUi === null ? true : fastUi == 'true';
976 $('body').toggleClass('no-blur', power_user.fast_ui_mode);969 $('body').toggleClass('no-blur', power_user.fast_ui_mode);
977 $('#fast_ui_mode').prop('checked', power_user.fast_ui_mode);970 $('#fast_ui_mode').prop('checked', power_user.fast_ui_mode);
978 if (power_user.fast_ui_mode) {971 if (power_user.fast_ui_mode) {
@@ -1039,9 +1032,7 @@ function switchMovingUI() {
1039 }1032 }
1040}1033}
10411034
1042function noShadows() {1035function applyNoShadows() {
1043 const noShadows = localStorage.getItem(storage_keys.noShadows);
1044 power_user.noShadows = noShadows === null ? false : noShadows == 'true';
1045 $('body').toggleClass('noShadows', power_user.noShadows);1036 $('body').toggleClass('noShadows', power_user.noShadows);
1046 $('#noShadowsmode').prop('checked', power_user.noShadows);1037 $('#noShadowsmode').prop('checked', power_user.noShadows);
1047 if (power_user.noShadows) {1038 if (power_user.noShadows) {
@@ -1055,12 +1046,9 @@ function noShadows() {
1055}1046}
10561047
1057function applyAvatarStyle() {1048function applyAvatarStyle() {
1058 power_user.avatar_style = Number(localStorage.getItem(storage_keys.avatar_style) ?? avatar_styles.ROUND);
1059 $('body').toggleClass('big-avatars', power_user.avatar_style === avatar_styles.RECTANGULAR);1049 $('body').toggleClass('big-avatars', power_user.avatar_style === avatar_styles.RECTANGULAR);
1060 $('body').toggleClass('square-avatars', power_user.avatar_style === avatar_styles.SQUARE);1050 $('body').toggleClass('square-avatars', power_user.avatar_style === avatar_styles.SQUARE);
1061 $('#avatar_style').val(power_user.avatar_style).prop('selected', true);1051 $('#avatar_style').val(power_user.avatar_style).prop('selected', true);
1062 //$(`input[name="avatar_style"][value="${power_user.avatar_style}"]`).prop("checked", true);
1063
1064}1052}
10651053
1066function applyChatDisplay() {1054function applyChatDisplay() {
@@ -1255,7 +1243,6 @@ async function applyTheme(name) {
1255 {1243 {
1256 key: 'fast_ui_mode',1244 key: 'fast_ui_mode',
1257 action: async () => {1245 action: async () => {
1258 localStorage.setItem(storage_keys.fast_ui_mode, power_user.fast_ui_mode);
1259 switchUiMode();1246 switchUiMode();
1260 },1247 },
1261 },1248 },
@@ -1276,15 +1263,13 @@ async function applyTheme(name) {
1276 {1263 {
1277 key: 'avatar_style',1264 key: 'avatar_style',
1278 action: async () => {1265 action: async () => {
1279 localStorage.setItem(storage_keys.avatar_style, power_user.avatar_style);
1280 applyAvatarStyle();1266 applyAvatarStyle();
1281 },1267 },
1282 },1268 },
1283 {1269 {
1284 key: 'noShadows',1270 key: 'noShadows',
1285 action: async () => {1271 action: async () => {
1286 localStorage.setItem(storage_keys.noShadows, power_user.noShadows);1272 applyNoShadows();
1287 noShadows();
1288 },1273 },
1289 },1274 },
1290 {1275 {
@@ -1365,7 +1350,6 @@ async function applyTheme(name) {
1365 {1350 {
1366 key: 'hotswap_enabled',1351 key: 'hotswap_enabled',
1367 action: async () => {1352 action: async () => {
1368 localStorage.setItem(storage_keys.hotswap_enabled, Boolean(power_user.hotswap_enabled));
1369 switchHotswap();1353 switchHotswap();
1370 },1354 },
1371 },1355 },
@@ -1449,6 +1433,7 @@ async function showDebugMenu() {
1449 callGenericPopup(template, POPUP_TYPE.TEXT, '', { wide: true, large: true, allowVerticalScrolling: true });1433 callGenericPopup(template, POPUP_TYPE.TEXT, '', { wide: true, large: true, allowVerticalScrolling: true });
1450}1434}
14511435
1436function applyPowerUserSettings() {
1452 switchUiMode();1437 switchUiMode();
1453 applyFontScale('forced');1438 applyFontScale('forced');
1454 applyThemeColor();1439 applyThemeColor();
@@ -1458,7 +1443,7 @@ applyBlurStrength();
1458 applyShadowWidth();1443 applyShadowWidth();
1459 applyCustomCSS();1444 applyCustomCSS();
1460 switchMovingUI();1445 switchMovingUI();
1461noShadows();1446 applyNoShadows();
1462 switchHotswap();1447 switchHotswap();
1463 switchTimer();1448 switchTimer();
1464 switchTimestamps();1449 switchTimestamps();
@@ -1467,6 +1452,8 @@ switchMesIDDisplay();
1467 switchHideChatAvatars();1452 switchHideChatAvatars();
1468 switchTokenCount();1453 switchTokenCount();
1469 switchMessageActions();1454 switchMessageActions();
1455}
1456
14701457
1471function getExampleMessagesBehavior() {1458function getExampleMessagesBehavior() {
1472 if (power_user.strip_examples) {1459 if (power_user.strip_examples) {
@@ -1530,10 +1517,7 @@ async function loadPowerUserSettings(settings, data) {
1530 }1517 }
15311518
1532 // These are still local storage1519 // These are still local storage
1533 const fastUi = localStorage.getItem(storage_keys.fast_ui_mode);
1534 const movingUI = localStorage.getItem(storage_keys.movingUI);1520 const movingUI = localStorage.getItem(storage_keys.movingUI);
1535 const noShadows = localStorage.getItem(storage_keys.noShadows);
1536 const hotswap = localStorage.getItem(storage_keys.hotswap_enabled);
1537 const timer = localStorage.getItem(storage_keys.timer_enabled);1521 const timer = localStorage.getItem(storage_keys.timer_enabled);
1538 const timestamps = localStorage.getItem(storage_keys.timestamps_enabled);1522 const timestamps = localStorage.getItem(storage_keys.timestamps_enabled);
1539 const mesIDDisplay = localStorage.getItem(storage_keys.mesIDDisplay_enabled);1523 const mesIDDisplay = localStorage.getItem(storage_keys.mesIDDisplay_enabled);
@@ -1554,10 +1538,7 @@ async function loadPowerUserSettings(settings, data) {
1554 localStorage.removeItem(storage_keys.auto_connect_legacy);1538 localStorage.removeItem(storage_keys.auto_connect_legacy);
1555 }1539 }
15561540
1557 power_user.fast_ui_mode = fastUi === null ? true : fastUi == 'true';
1558 power_user.movingUI = movingUI === null ? false : movingUI == 'true';1541 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';
1561 power_user.timer_enabled = timer === null ? true : timer == 'true';1542 power_user.timer_enabled = timer === null ? true : timer == 'true';
1562 power_user.timestamps_enabled = timestamps === null ? true : timestamps == 'true';1543 power_user.timestamps_enabled = timestamps === null ? true : timestamps == 'true';
1563 power_user.mesIDDisplay_enabled = mesIDDisplay === null ? true : mesIDDisplay == 'true';1544 power_user.mesIDDisplay_enabled = mesIDDisplay === null ? true : mesIDDisplay == 'true';
@@ -1565,8 +1546,6 @@ async function loadPowerUserSettings(settings, data) {
1565 power_user.expand_message_actions = expandMessageActions === null ? true : expandMessageActions == 'true';1546 power_user.expand_message_actions = expandMessageActions === null ? true : expandMessageActions == 'true';
1566 power_user.enableZenSliders = enableZenSliders === null ? false : enableZenSliders == 'true';1547 power_user.enableZenSliders = enableZenSliders === null ? false : enableZenSliders == 'true';
1567 power_user.enableLabMode = enableLabMode === null ? false : enableLabMode == 'true';1548 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);
1570 power_user.chat_width = Number(localStorage.getItem(storage_keys.chat_width) ?? 50);1549 power_user.chat_width = Number(localStorage.getItem(storage_keys.chat_width) ?? 50);
1571 power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);1550 power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
1572 power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 10);1551 power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 10);
@@ -3299,7 +3278,6 @@ $(document).ready(() => {
3299 // Settings that go to local storage3278 // Settings that go to local storage
3300 $('#fast_ui_mode').change(function () {3279 $('#fast_ui_mode').change(function () {
3301 power_user.fast_ui_mode = $(this).prop('checked');3280 power_user.fast_ui_mode = $(this).prop('checked');
3302 localStorage.setItem(storage_keys.fast_ui_mode, power_user.fast_ui_mode);
3303 switchUiMode();3281 switchUiMode();
3304 saveSettingsDebounced();3282 saveSettingsDebounced();
3305 });3283 });
@@ -3326,8 +3304,7 @@ $(document).ready(() => {
33263304
3327 $('#noShadowsmode').change(function () {3305 $('#noShadowsmode').change(function () {
3328 power_user.noShadows = $(this).prop('checked');3306 power_user.noShadows = $(this).prop('checked');
3329 localStorage.setItem(storage_keys.noShadows, power_user.noShadows);3307 applyNoShadows();
3330 noShadows();
3331 saveSettingsDebounced();3308 saveSettingsDebounced();
3332 });3309 });
33333310
@@ -3336,7 +3313,6 @@ $(document).ready(() => {
3336 $('#avatar_style').on('change', function () {3313 $('#avatar_style').on('change', function () {
3337 const value = $(this).find(':selected').val();3314 const value = $(this).find(':selected').val();
3338 power_user.avatar_style = Number(value);3315 power_user.avatar_style = Number(value);
3339 localStorage.setItem(storage_keys.avatar_style, power_user.avatar_style);
3340 applyAvatarStyle();3316 applyAvatarStyle();
3341 saveSettingsDebounced();3317 saveSettingsDebounced();
3342 });3318 });
@@ -3719,8 +3695,8 @@ $(document).ready(() => {
3719 $('#hotswapEnabled').on('input', function () {3695 $('#hotswapEnabled').on('input', function () {
3720 const value = !!$(this).prop('checked');3696 const value = !!$(this).prop('checked');
3721 power_user.hotswap_enabled = value;3697 power_user.hotswap_enabled = value;
3722 localStorage.setItem(storage_keys.hotswap_enabled, Boolean(power_user.hotswap_enabled));
3723 switchHotswap();3698 switchHotswap();
3699 saveSettingsDebounced();
3724 });3700 });
37253701
3726 $('#prefer_character_prompt').on('input', function () {3702 $('#prefer_character_prompt').on('input', function () {