From e1deff67fc7056f99861c3e35ef7ad7d9f6f5b4c Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 5 Jan 2024 20:27:19 +0200 Subject: [PATCH] Migrate auto-connect and auto-load from localStorage --- public/scripts/RossAscends-mods.js | 24 ++++++++---------------- public/scripts/power-user.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 46e76e97f..7b76ba010 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -47,8 +47,6 @@ var LeftNavPanel = document.getElementById('left-nav-panel'); var WorldInfo = document.getElementById('WorldInfo'); var SelectedCharacterTab = document.getElementById('rm_button_selected_ch'); -var AutoConnectCheckbox = document.getElementById('auto-connect-checkbox'); -var AutoLoadChatCheckbox = document.getElementById('auto-load-chat-checkbox'); var connection_made = false; var retry_delay = 500; @@ -368,7 +366,7 @@ function RA_autoconnect(PrevApi) { setTimeout(RA_autoconnect, 100); return; } - if (online_status === 'no_connection' && LoadLocalBool('AutoConnectEnabled')) { + if (online_status === 'no_connection' && power_user.auto_connect) { switch (main_api) { case 'kobold': if (api_server && isValidUrl(api_server)) { @@ -719,21 +717,19 @@ export function initRossMods() { RA_checkOnlineStatus(); }, 100); - // read the state of AutoConnect and AutoLoadChat. - $(AutoConnectCheckbox).prop('checked', LoadLocalBool('AutoConnectEnabled')); - $(AutoLoadChatCheckbox).prop('checked', LoadLocalBool('AutoLoadChatEnabled')); + if (power_user.auto_load_chat) { + RA_autoloadchat(); + } - setTimeout(function () { - if (LoadLocalBool('AutoLoadChatEnabled') == true) { RA_autoloadchat(); } - }, 200); + if (power_user.auto_connect) { + RA_autoconnect(); + } - - //Autoconnect on page load if enabled, or when api type is changed - if (LoadLocalBool('AutoConnectEnabled') == true) { RA_autoconnect(); } $('#main_api').change(function () { var PrevAPI = main_api; setTimeout(() => RA_autoconnect(PrevAPI), 100); }); + $('#api_button').click(function () { setTimeout(RA_checkOnlineStatus, 100); }); //toggle pin class when lock toggle clicked @@ -855,10 +851,6 @@ export function initRossMods() { OpenNavPanels(); }, 300); - //save AutoConnect and AutoLoadChat prefs - $(AutoConnectCheckbox).on('change', function () { SaveLocal('AutoConnectEnabled', $(AutoConnectCheckbox).prop('checked')); }); - $(AutoLoadChatCheckbox).on('change', function () { SaveLocal('AutoLoadChatEnabled', $(AutoLoadChatCheckbox).prop('checked')); }); - $(SelectedCharacterTab).click(function () { SaveLocal('SelectedNavTab', 'rm_button_selected_ch'); }); $('#rm_button_characters').click(function () { SaveLocal('SelectedNavTab', 'rm_button_characters'); }); diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 84fad8c65..0dce2e8d4 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -235,6 +235,8 @@ let power_user = { restore_user_input: true, reduced_motion: false, compact_input_area: true, + auto_connect: false, + auto_load_chat: false, }; let themes = []; @@ -277,6 +279,8 @@ const storage_keys = { enableLabMode: 'enableLabMode', reduced_motion: 'reduced_motion', compact_input_area: 'compact_input_area', + auto_connect_legacy: 'AutoConnectEnabled', + auto_load_chat_legacy: 'AutoLoadChatEnabled', }; const contextControls = [ @@ -1377,6 +1381,19 @@ function loadPowerUserSettings(settings, data) { const expandMessageActions = localStorage.getItem(storage_keys.expand_message_actions); const enableZenSliders = localStorage.getItem(storage_keys.enableZenSliders); const enableLabMode = localStorage.getItem(storage_keys.enableLabMode); + const autoLoadChat = localStorage.getItem(storage_keys.auto_load_chat_legacy); + const autoConnect = localStorage.getItem(storage_keys.auto_connect_legacy); + + if (autoLoadChat) { + power_user.auto_load_chat = autoLoadChat === 'true'; + localStorage.removeItem(storage_keys.auto_load_chat_legacy); + } + + if (autoConnect) { + power_user.auto_connect = autoConnect === 'true'; + localStorage.removeItem(storage_keys.auto_connect_legacy); + } + power_user.fast_ui_mode = fastUi === null ? true : fastUi == 'true'; power_user.movingUI = movingUI === null ? false : movingUI == 'true'; power_user.noShadows = noShadows === null ? false : noShadows == 'true'; @@ -1504,6 +1521,8 @@ function loadPowerUserSettings(settings, data) { $('#border-color-picker').attr('color', power_user.border_color); $('#ui_mode_select').val(power_user.ui_mode).find(`option[value="${power_user.ui_mode}"]`).attr('selected', true); $('#reduced_motion').prop('checked', power_user.reduced_motion); + $('#auto-connect-checkbox').prop('checked', power_user.auto_connect); + $('#auto-load-chat-checkbox').prop('checked', power_user.auto_load_chat); for (const theme of themes) { const option = document.createElement('option'); @@ -3199,6 +3218,16 @@ $(document).ready(() => { saveSettingsDebounced(); }); + $('#auto-connect-checkbox').on('input', function () { + power_user.auto_connect = !!$(this).prop('checked'); + saveSettingsDebounced(); + }); + + $('#auto-load-chat-checkbox').on('input', function () { + power_user.auto_load_chat = !!$(this).prop('checked'); + saveSettingsDebounced(); + }); + $(document).on('click', '#debug_table [data-debug-function]', function () { const functionId = $(this).data('debug-function'); const functionRecord = debug_functions.find(f => f.functionId === functionId);