Migrate auto-connect and auto-load from localStorage

This commit is contained in:
Cohee 2024-01-05 20:27:19 +02:00
parent d5e3f5491d
commit e1deff67fc
2 changed files with 37 additions and 16 deletions

View File

@ -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'); });

View File

@ -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);