Display loader earlier, init toast classes in power-user

34490c9614912c4cd8c6612180b2aa04be8ce513

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +21 -47Ignore whitespace
public/script.js+1 -4
@@ -313,8 +313,6 @@ await new Promise((resolve) => {
313 }313 }
314});314});
315315
316//showLoader(); <-- must wait for poweruser (called from firstinit()), so moved it in there
317
318// Configure toast library:316// Configure toast library:
319toastr.options.escapeHtml = true; // Prevent raw HTML inserts317toastr.options.escapeHtml = true; // Prevent raw HTML inserts
320toastr.options.timeOut = 4000; // How long the toast will display without user interaction318toastr.options.timeOut = 4000; // How long the toast will display without user interaction
@@ -968,11 +966,11 @@ async function firstLoadInit() {
968 const tokenData = await tokenResponse.json();966 const tokenData = await tokenResponse.json();
969 token = tokenData.token;967 token = tokenData.token;
970 } catch {968 } catch {
971 hideLoader();
972 toastr.error(t`Couldn't get CSRF token. Please refresh the page.`, t`Error`, { timeOut: 0, extendedTimeOut: 0, preventDuplicates: true });969 toastr.error(t`Couldn't get CSRF token. Please refresh the page.`, t`Error`, { timeOut: 0, extendedTimeOut: 0, preventDuplicates: true });
973 throw new Error('Initialization failed');970 throw new Error('Initialization failed');
974 }971 }
975972
973 showLoader();
976 initLibraryShims();974 initLibraryShims();
977 addShowdownPatch(showdown);975 addShowdownPatch(showdown);
978 reloadMarkdownProcessor();976 reloadMarkdownProcessor();
@@ -990,7 +988,6 @@ async function firstLoadInit() {
990 await initPresetManager();988 await initPresetManager();
991 await getSystemMessages();989 await getSystemMessages();
992 await getSettings();990 await getSettings();
993 showLoader();
994 initKeyboard();991 initKeyboard();
995 initDynamicStyles();992 initDynamicStyles();
996 initTags();993 initTags();
public/scripts/popup.js+2 -10
@@ -1,6 +1,6 @@
1import dialogPolyfill from '../lib/dialog-polyfill.esm.js';1import dialogPolyfill from '../lib/dialog-polyfill.esm.js';
2import { shouldSendOnEnter } from './RossAscends-mods.js';2import { shouldSendOnEnter } from './RossAscends-mods.js';
3import { power_user } from './power-user.js';3import { power_user, toastPositionClasses } from './power-user.js';
4import { removeFromArray, runAfterAnimation, uuidv4 } from './utils.js';4import { removeFromArray, runAfterAnimation, uuidv4 } from './utils.js';
55
6/** @readonly */6/** @readonly */
@@ -725,15 +725,6 @@ export function fixToastrForDialogs() {
725 if (!toastContainer) {725 if (!toastContainer) {
726 toastContainer = document.createElement('div');726 toastContainer = document.createElement('div');
727 toastContainer.setAttribute('id', 'toast-container');727 toastContainer.setAttribute('id', 'toast-container');
728 if (power_user.toastr_position) {
729 toastr.options.positionClass = (power_user.toastr_position);
730 } else {
731 console.warn('Did not find poweruser.toastr_position; defaulting to top center');
732 power_user.toastr_position = 'toast-top-center';
733 toastr.options.positionClass = (power_user.toastr_position);
734 $(`#toastr_position option[value=${power_user.toastr_position}]`).attr('selected', true);
735 }
736 //if (toastr.options.positionClass) toastContainer.classList.add(toastr.options.positionClass);
737 }728 }
738729
739 // Check if toastr is already a child. If not, we need to move it inside this dialog.730 // Check if toastr is already a child. If not, we need to move it inside this dialog.
@@ -752,6 +743,7 @@ export function fixToastrForDialogs() {
752 toastContainer.remove();743 toastContainer.remove();
753 } else {744 } else {
754 document.body.appendChild(toastContainer);745 document.body.appendChild(toastContainer);
746 toastContainer.classList.remove(...toastPositionClasses);
755 toastContainer.classList.add(toastr.options.positionClass);747 toastContainer.classList.add(toastr.options.positionClass);
756 }748 }
757 }749 }
public/scripts/power-user.js+18 -33
@@ -52,7 +52,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
52import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';52import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';
53import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';53import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
54import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';54import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
55import { POPUP_TYPE, callGenericPopup } from './popup.js';55import { POPUP_TYPE, callGenericPopup, fixToastrForDialogs } from './popup.js';
56import { loadSystemPrompts } from './sysprompt.js';56import { loadSystemPrompts } from './sysprompt.js';
57import { fuzzySearchCategories } from './filters.js';57import { fuzzySearchCategories } from './filters.js';
58import { accountStorage } from './util/AccountStorage.js';58import { accountStorage } from './util/AccountStorage.js';
@@ -70,6 +70,15 @@ export {
70 applyPowerUserSettings,70 applyPowerUserSettings,
71};71};
7272
73export const toastPositionClasses = [
74 'toast-top-left',
75 'toast-top-center',
76 'toast-top-right',
77 'toast-bottom-left',
78 'toast-bottom-center',
79 'toast-bottom-right',
80];
81
73export const MAX_CONTEXT_DEFAULT = 8192;82export const MAX_CONTEXT_DEFAULT = 8192;
74export const MAX_RESPONSE_DEFAULT = 2048;83export const MAX_RESPONSE_DEFAULT = 2048;
75const MAX_CONTEXT_UNLOCKED = 512 * 1024;84const MAX_CONTEXT_UNLOCKED = 512 * 1024;
@@ -81,6 +90,7 @@ const maxContextStep = 64;
81const defaultStoryString = '{{#if system}}{{system}}\n{{/if}}{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{char}}\'s personality: {{personality}}\n{{/if}}{{#if scenario}}Scenario: {{scenario}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}';90const defaultStoryString = '{{#if system}}{{system}}\n{{/if}}{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{char}}\'s personality: {{personality}}\n{{/if}}{{#if scenario}}Scenario: {{scenario}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}';
82const defaultExampleSeparator = '***';91const defaultExampleSeparator = '***';
83const defaultChatStart = '***';92const defaultChatStart = '***';
93const defaultToastPosition = 'toast-top-center';
8494
85const avatar_styles = {95const avatar_styles = {
86 ROUND: 0,96 ROUND: 0,
@@ -137,7 +147,7 @@ let power_user = {
137 fast_ui_mode: true,147 fast_ui_mode: true,
138 avatar_style: avatar_styles.ROUND,148 avatar_style: avatar_styles.ROUND,
139 chat_display: chat_styles.DEFAULT,149 chat_display: chat_styles.DEFAULT,
140 toastr_position: 'toast-top-center',150 toastr_position: defaultToastPosition,
141 chat_width: 50,151 chat_width: 50,
142 never_resize_avatars: false,152 never_resize_avatars: false,
143 show_card_avatar_urls: false,153 show_card_avatar_urls: false,
@@ -1046,39 +1056,13 @@ function applyChatDisplay() {
1046}1056}
10471057
1048function applyToastrPosition() {1058function applyToastrPosition() {
10491059 if (!toastPositionClasses.includes(power_user.toastr_position)) {
1050 if (!power_user.toastr_position) {1060 power_user.toastr_position = defaultToastPosition;
1051 power_user.toastr_position = 'toast-top-center';1061 console.warn(`applyToastrPosition: invalid toastr position, defaulting to ${defaultToastPosition}`);
1052 console.warn('applyToastrPosition: missing toastr position, defaulting to top-center');
1053 }
1054
1055 switch (power_user.toastr_position) {
1056 case 'toast-top-left': {
1057 toastr.options.positionClass = 'toast-top-left';
1058 break;
1059 }
1060 case 'toast-top-center': {
1061 toastr.options.positionClass = 'toast-top-center';
1062 break;
1063 }
1064 case 'toast-top-right': {
1065 toastr.options.positionClass = 'toast-top-right';
1066 break;
1067 }
1068 case 'toast-bottom-left': {
1069 toastr.options.positionClass = 'toast-bottom-left';
1070 break;
1071 }
1072 case 'toast-bottom-center': {
1073 toastr.options.positionClass = 'toast-bottom-center';
1074 break;
1075 }
1076 case 'toast-bottom-right': {
1077 toastr.options.positionClass = 'toast-bottom-right';
1078 break;
1079 }
1080 }1062 }
10811063
1064 toastr.options.positionClass = power_user.toastr_position;
1065 fixToastrForDialogs();
1082 $('#toastr_position').val(power_user.toastr_position).prop('selected', true);1066 $('#toastr_position').val(power_user.toastr_position).prop('selected', true);
1083}1067}
10841068
@@ -1739,6 +1723,7 @@ async function loadPowerUserSettings(settings, data) {
1739 loadMovingUIState();1723 loadMovingUIState();
1740 loadCharListState();1724 loadCharListState();
1741 toggleMDHotkeyIconDisplay();1725 toggleMDHotkeyIconDisplay();
1726 applyToastrPosition();
1742}1727}
17431728
1744function toggleMDHotkeyIconDisplay() {1729function toggleMDHotkeyIconDisplay() {