mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-28 09:50:14 +01:00
Fix chat bg gens not saving. Remove module worker pattern and global function from chat bg plugin
This commit is contained in:
parent
f468a33d60
commit
c110ebe02b
@ -285,6 +285,7 @@ export const event_types = {
|
|||||||
CHARACTER_EDITED: 'character_edited',
|
CHARACTER_EDITED: 'character_edited',
|
||||||
USER_MESSAGE_RENDERED: 'user_message_rendered',
|
USER_MESSAGE_RENDERED: 'user_message_rendered',
|
||||||
CHARACTER_MESSAGE_RENDERED: 'character_message_rendered',
|
CHARACTER_MESSAGE_RENDERED: 'character_message_rendered',
|
||||||
|
FORCE_SET_BACKGROUND: 'force_set_background,'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const eventSource = new EventEmitter();
|
export const eventSource = new EventEmitter();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { generateQuietPrompt } from "../../../script.js";
|
import { eventSource, event_types, generateQuietPrompt } from "../../../script.js";
|
||||||
import { getContext, saveMetadataDebounced } from "../../extensions.js";
|
import { getContext, saveMetadataDebounced } from "../../extensions.js";
|
||||||
import { registerSlashCommand } from "../../slash-commands.js";
|
import { registerSlashCommand } from "../../slash-commands.js";
|
||||||
import { stringFormat } from "../../utils.js";
|
import { stringFormat } from "../../utils.js";
|
||||||
@ -6,8 +6,10 @@ export { MODULE_NAME };
|
|||||||
|
|
||||||
const MODULE_NAME = 'backgrounds';
|
const MODULE_NAME = 'backgrounds';
|
||||||
const METADATA_KEY = 'custom_background';
|
const METADATA_KEY = 'custom_background';
|
||||||
const UPDATE_INTERVAL = 1000;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} background
|
||||||
|
*/
|
||||||
function forceSetBackground(background) {
|
function forceSetBackground(background) {
|
||||||
saveBackgroundMetadata(background);
|
saveBackgroundMetadata(background);
|
||||||
setCustomBackground();
|
setCustomBackground();
|
||||||
@ -168,9 +170,9 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addSettings();
|
addSettings();
|
||||||
setInterval(moduleWorker, UPDATE_INTERVAL);
|
|
||||||
registerSlashCommand('lockbg', onLockBackgroundClick, ['bglock'], " – locks a background for the currently selected chat", true, true);
|
registerSlashCommand('lockbg', onLockBackgroundClick, ['bglock'], " – locks a background for the currently selected chat", true, true);
|
||||||
registerSlashCommand('unlockbg', onUnlockBackgroundClick, ['bgunlock'], ' – unlocks a background for the currently selected chat', true, true);
|
registerSlashCommand('unlockbg', onUnlockBackgroundClick, ['bgunlock'], ' – unlocks a background for the currently selected chat', true, true);
|
||||||
registerSlashCommand('autobg', autoBackgroundCommand, ['bgauto'], ' – automatically changes the background based on the chat context using the AI request prompt', true, true);
|
registerSlashCommand('autobg', autoBackgroundCommand, ['bgauto'], ' – automatically changes the background based on the chat context using the AI request prompt', true, true);
|
||||||
window['forceSetBackground'] = forceSetBackground;
|
eventSource.on(event_types.FORCE_SET_BACKGROUND, forceSetBackground);
|
||||||
|
eventSource.on(event_types.CHAT_CHANGED, moduleWorker);
|
||||||
});
|
});
|
||||||
|
@ -890,21 +890,17 @@ async function generatePicture(_, trigger, message, callback) {
|
|||||||
extension_settings.sd.height = Math.round(extension_settings.sd.width * 1.5 / 64) * 64;
|
extension_settings.sd.height = Math.round(extension_settings.sd.width * 1.5 / 64) * 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background images are always landscape
|
if (generationType == generationMode.BACKGROUND) {
|
||||||
if (generationType == generationMode.BACKGROUND && aspectRatio <= 1) {
|
// Background images are always landscape
|
||||||
// Round to nearest multiple of 64
|
if (aspectRatio <= 1) {
|
||||||
extension_settings.sd.width = Math.round(extension_settings.sd.height * 1.8 / 64) * 64;
|
// Round to nearest multiple of 64
|
||||||
|
extension_settings.sd.width = Math.round(extension_settings.sd.height * 1.8 / 64) * 64;
|
||||||
|
}
|
||||||
const callbackOriginal = callback;
|
const callbackOriginal = callback;
|
||||||
callback = async function (prompt, base64Image) {
|
callback = async function (prompt, base64Image) {
|
||||||
const imagePath = base64Image;
|
const imagePath = base64Image;
|
||||||
const imgUrl = `url("${encodeURI(base64Image)}")`;
|
const imgUrl = `url("${encodeURI(base64Image)}")`;
|
||||||
|
eventSource.emit(event_types.FORCE_SET_BACKGROUND, imgUrl);
|
||||||
if (typeof window['forceSetBackground'] === 'function') {
|
|
||||||
window['forceSetBackground'](imgUrl);
|
|
||||||
} else {
|
|
||||||
toastr.info('Background image will not be preserved.', '"Chat backgrounds" extension is disabled.');
|
|
||||||
$('#bg_custom').css('background-image', imgUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof callbackOriginal === 'function') {
|
if (typeof callbackOriginal === 'function') {
|
||||||
callbackOriginal(prompt, imagePath);
|
callbackOriginal(prompt, imagePath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user