mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'dev' of https://github.com/Cohee1207/SillyTavern into dev
This commit is contained in:
71
public/scripts/eventemitter.js
Normal file
71
public/scripts/eventemitter.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/* Polyfill indexOf. */
|
||||
var indexOf;
|
||||
|
||||
if (typeof Array.prototype.indexOf === 'function') {
|
||||
indexOf = function (haystack, needle) {
|
||||
return haystack.indexOf(needle);
|
||||
};
|
||||
} else {
|
||||
indexOf = function (haystack, needle) {
|
||||
var i = 0, length = haystack.length, idx = -1, found = false;
|
||||
|
||||
while (i < length && !found) {
|
||||
if (haystack[i] === needle) {
|
||||
idx = i;
|
||||
found = true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return idx;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/* Polyfill EventEmitter. */
|
||||
var EventEmitter = function () {
|
||||
this.events = {};
|
||||
};
|
||||
|
||||
EventEmitter.prototype.on = function (event, listener) {
|
||||
if (typeof this.events[event] !== 'object') {
|
||||
this.events[event] = [];
|
||||
}
|
||||
|
||||
this.events[event].push(listener);
|
||||
};
|
||||
|
||||
EventEmitter.prototype.removeListener = function (event, listener) {
|
||||
var idx;
|
||||
|
||||
if (typeof this.events[event] === 'object') {
|
||||
idx = indexOf(this.events[event], listener);
|
||||
|
||||
if (idx > -1) {
|
||||
this.events[event].splice(idx, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EventEmitter.prototype.emit = function (event) {
|
||||
var i, listeners, length, args = [].slice.call(arguments, 1);
|
||||
|
||||
if (typeof this.events[event] === 'object') {
|
||||
listeners = this.events[event].slice();
|
||||
length = listeners.length;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
listeners[i].apply(this, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EventEmitter.prototype.once = function (event, listener) {
|
||||
this.on(event, function g () {
|
||||
this.removeListener(event, g);
|
||||
listener.apply(this, arguments);
|
||||
});
|
||||
};
|
||||
|
||||
export { EventEmitter }
|
@@ -1,4 +1,4 @@
|
||||
import { callPopup, saveSettings, saveSettingsDebounced } from "../script.js";
|
||||
import { callPopup, eventSource, event_types, saveSettings, saveSettingsDebounced } from "../script.js";
|
||||
import { isSubsetOf } from "./utils.js";
|
||||
export {
|
||||
getContext,
|
||||
@@ -162,6 +162,7 @@ async function connectToApi(baseUrl) {
|
||||
const data = await getExtensionsResult.json();
|
||||
modules = data.modules;
|
||||
await activateExtensions();
|
||||
eventSource.emit(event_types.EXTRAS_CONNECTED, modules);
|
||||
}
|
||||
|
||||
updateStatus(getExtensionsResult.ok);
|
||||
|
@@ -5,7 +5,9 @@ import {
|
||||
hideSwipeButtons,
|
||||
showSwipeButtons,
|
||||
callPopup,
|
||||
getRequestHeaders
|
||||
getRequestHeaders,
|
||||
event_types,
|
||||
eventSource
|
||||
} from "../../../script.js";
|
||||
import { getApiUrl, getContext, extension_settings, defaultRequestArgs, modules } from "../../extensions.js";
|
||||
import { stringFormat, initScrollHeight, resetScrollHeight } from "../../utils.js";
|
||||
@@ -611,6 +613,9 @@ jQuery(async () => {
|
||||
initScrollHeight($("#sd_negative_prompt"));
|
||||
})
|
||||
|
||||
await loadSettings();
|
||||
eventSource.on(event_types.EXTRAS_CONNECTED, async () => {
|
||||
await Promise.all([loadSamplers(), loadModels()]);
|
||||
});
|
||||
|
||||
await loadSettings();
|
||||
});
|
Reference in New Issue
Block a user