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) => {
313313 }
314314});
315315
316-//showLoader(); <-- must wait for poweruser (called from firstinit()), so moved it in there
317-
318316// Configure toast library:
319317toastr.options.escapeHtml = true; // Prevent raw HTML inserts
320318toastr.options.timeOut = 4000; // How long the toast will display without user interaction
@@ -968,11 +966,11 @@ async function firstLoadInit() {
968966 const tokenData = await tokenResponse.json();
969967 token = tokenData.token;
970968 } catch {
971- hideLoader();
972969 toastr.error(t`Couldn't get CSRF token. Please refresh the page.`, t`Error`, { timeOut: 0, extendedTimeOut: 0, preventDuplicates: true });
973970 throw new Error('Initialization failed');
974971 }
975972
973+ showLoader();
976974 initLibraryShims();
977975 addShowdownPatch(showdown);
978976 reloadMarkdownProcessor();
@@ -990,7 +988,6 @@ async function firstLoadInit() {
990988 await initPresetManager();
991989 await getSystemMessages();
992990 await getSettings();
993- showLoader();
994991 initKeyboard();
995992 initDynamicStyles();
996993 initTags();
public/scripts/popup.js+2 -10
@@ -1,6 +1,6 @@
11import dialogPolyfill from '../lib/dialog-polyfill.esm.js';
22import { shouldSendOnEnter } from './RossAscends-mods.js';
33import { power_user, toastPositionClasses } from './power-user.js';
44import { removeFromArray, runAfterAnimation, uuidv4 } from './utils.js';
55
66/** @readonly */
@@ -725,15 +725,6 @@ export function fixToastrForDialogs() {
725725 if (!toastContainer) {
726726 toastContainer = document.createElement('div');
727727 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);
737728 }
738729
739730 // Check if toastr is already a child. If not, we need to move it inside this dialog.
@@ -752,6 +743,7 @@ export function fixToastrForDialogs() {
752743 toastContainer.remove();
753744 } else {
754745 document.body.appendChild(toastContainer);
746+ toastContainer.classList.remove(...toastPositionClasses);
755747 toastContainer.classList.add(toastr.options.positionClass);
756748 }
757749 }
public/scripts/power-user.js+18 -33
@@ -52,7 +52,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
5252import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';
5353import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
5454import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
5555import { POPUP_TYPE, callGenericPopup, fixToastrForDialogs } from './popup.js';
5656import { loadSystemPrompts } from './sysprompt.js';
5757import { fuzzySearchCategories } from './filters.js';
5858import { accountStorage } from './util/AccountStorage.js';
@@ -70,6 +70,15 @@ export {
7070 applyPowerUserSettings,
7171};
7272
73+export 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+
7382export const MAX_CONTEXT_DEFAULT = 8192;
7483export const MAX_RESPONSE_DEFAULT = 2048;
7584const MAX_CONTEXT_UNLOCKED = 512 * 1024;
@@ -81,6 +90,7 @@ const maxContextStep = 64;
8190const 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}}';
8291const defaultExampleSeparator = '***';
8392const defaultChatStart = '***';
93+const defaultToastPosition = 'toast-top-center';
8494
8595const avatar_styles = {
8696 ROUND: 0,
@@ -137,7 +147,7 @@ let power_user = {
137147 fast_ui_mode: true,
138148 avatar_style: avatar_styles.ROUND,
139149 chat_display: chat_styles.DEFAULT,
140150 toastr_position: 'toast-top-center'defaultToastPosition,
141151 chat_width: 50,
142152 never_resize_avatars: false,
143153 show_card_avatar_urls: false,
@@ -1046,39 +1056,13 @@ function applyChatDisplay() {
10461056}
10471057
10481058function applyToastrPosition() {
1049-
1059+ 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- }
10801062 }
10811063
1064+ toastr.options.positionClass = power_user.toastr_position;
1065+ fixToastrForDialogs();
10821066 $('#toastr_position').val(power_user.toastr_position).prop('selected', true);
10831067}
10841068
@@ -1739,6 +1723,7 @@ async function loadPowerUserSettings(settings, data) {
17391723 loadMovingUIState();
17401724 loadCharListState();
17411725 toggleMDHotkeyIconDisplay();
1726+ applyToastrPosition();
17421727}
17431728
17441729function toggleMDHotkeyIconDisplay() {