mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-25 16:45:42 +00:00
* tgchat (#52426) Replaces goonchat with a tgui based chat panel Fixes #52898 Fixes #52663 It is as fast as goonchat was (if not faster in certain circumstances), and is very extensible. It has all the necessary code for sorting messages into categories, which means that one of the next features will be multiple tab support. Additional features that you will get with tgchat right now: Massively faster server-side performance compared to goonchat, especially if batching multiple messages to one client. Message persistence across rounds and reconnects. (All messages are stored client-side in IndexedDB) More robust scroll tracking. If you scroll up, it will not change the scroll position on new messages like goonchat did. Multiple message combining. (Currently set to combine up to 5 messages over last 5 seconds). If using the highlighting feature, it highlights the whole message as well as the matching word. "Now playing" widget, with preview of the song title, a knob for adjusting the volume and a stop button. Architecture is as following: ``` to_chat() -+ | SSchat (queue, batching) | window.send_message() | v +-------------+ | tgui-panel | |+-----------+| || tgchat || |+-----------+| +-------------+ ``` Subsystem is basically goonchat, but without all the garbage that slows the servers down (string concatenation, double urlencoding, sanitizing, etc). Now, instead of all that, it's being slowed down by json_encode in /datum/tgui_window/proc/send_message, which IMO is completely worth it, and allows sending various templates and widgets to tgchat. /datum/tgui_window abstracts the whole window away from you, establishes a nice message-passing interface between DM and JS, with two message queues on each side, automatically loads js/css assets for you, basically does everything. You as a developer only have to worry about sending/receiving messages and write javascript. tgui-panel is a slimmed down version of tgui, and functions as a container for various widgets, and tgchat is one of them. It of course can be expanded with more stuff. It's also a separate entry point and a JS bundle, so it's not bloating the main tgui bundle, and is currently sitting at about 230kB. * tgchat Co-authored-by: Aleksej Komarov <stylemistake@gmail.com>
118 lines
3.0 KiB
JavaScript
118 lines
3.0 KiB
JavaScript
/**
|
|
* @file
|
|
* @copyright 2020 Aleksej Komarov
|
|
* @license MIT
|
|
*/
|
|
|
|
import { createLogger } from 'common/logging.js';
|
|
import fs from 'fs';
|
|
import os from 'os';
|
|
import { basename } from 'path';
|
|
import { promisify } from 'util';
|
|
import { resolveGlob, resolvePath } from './util.js';
|
|
import { regQuery } from './winreg.js';
|
|
import { DreamSeeker } from './dreamseeker.js';
|
|
|
|
const logger = createLogger('reloader');
|
|
|
|
const HOME = os.homedir();
|
|
const SEARCH_LOCATIONS = [
|
|
// Custom location
|
|
process.env.BYOND_CACHE,
|
|
// Windows
|
|
`${HOME}/*/BYOND/cache`,
|
|
// Wine
|
|
`${HOME}/.wine/drive_c/users/*/*/BYOND/cache`,
|
|
// Lutris
|
|
`${HOME}/Games/byond/drive_c/users/*/*/BYOND/cache`,
|
|
// WSL
|
|
`/mnt/c/Users/*/*/BYOND/cache`,
|
|
];
|
|
|
|
let cacheRoot;
|
|
|
|
export const findCacheRoot = async () => {
|
|
if (cacheRoot) {
|
|
return cacheRoot;
|
|
}
|
|
logger.log('looking for byond cache');
|
|
// Find BYOND cache folders
|
|
for (let pattern of SEARCH_LOCATIONS) {
|
|
if (!pattern) {
|
|
continue;
|
|
}
|
|
const paths = await resolveGlob(pattern);
|
|
if (paths.length > 0) {
|
|
cacheRoot = paths[0];
|
|
onCacheRootFound(cacheRoot);
|
|
return cacheRoot;
|
|
}
|
|
}
|
|
// Query the Windows Registry
|
|
if (process.platform === 'win32') {
|
|
logger.log('querying windows registry');
|
|
let userpath = await regQuery(
|
|
'HKCU\\Software\\Dantom\\BYOND',
|
|
'userpath');
|
|
if (userpath) {
|
|
cacheRoot = userpath
|
|
.replace(/\\$/, '')
|
|
.replace(/\\/g, '/')
|
|
+ '/cache';
|
|
onCacheRootFound(cacheRoot);
|
|
return cacheRoot;
|
|
}
|
|
}
|
|
logger.log('found no cache directories');
|
|
};
|
|
|
|
const onCacheRootFound = cacheRoot => {
|
|
logger.log(`found cache at '${cacheRoot}'`);
|
|
// Plant dummy
|
|
fs.closeSync(fs.openSync(cacheRoot + '/dummy', 'w'));
|
|
};
|
|
|
|
export const reloadByondCache = async bundleDir => {
|
|
const cacheRoot = await findCacheRoot();
|
|
if (!cacheRoot) {
|
|
return;
|
|
}
|
|
// Find tmp folders in cache
|
|
const cacheDirs = await resolveGlob(cacheRoot, './tmp*');
|
|
if (cacheDirs.length === 0) {
|
|
logger.log('found no tmp folder in cache');
|
|
return;
|
|
}
|
|
// Get dreamseeker instances
|
|
const pids = cacheDirs.map(cacheDir => (
|
|
parseInt(cacheDir.split('/cache/tmp').pop(), 10)
|
|
));
|
|
const dssPromise = DreamSeeker.getInstancesByPids(pids);
|
|
// Copy assets
|
|
const assets = await resolveGlob(bundleDir, './*.+(bundle|chunk|hot-update).*');
|
|
for (let cacheDir of cacheDirs) {
|
|
// Clear garbage
|
|
const garbage = await resolveGlob(cacheDir, './*.+(bundle|chunk|hot-update).*');
|
|
for (let file of garbage) {
|
|
await promisify(fs.unlink)(file);
|
|
}
|
|
// Copy assets
|
|
for (let asset of assets) {
|
|
const destination = resolvePath(cacheDir, basename(asset));
|
|
await promisify(fs.copyFile)(asset, destination);
|
|
}
|
|
logger.log(`copied ${assets.length} files to '${cacheDir}'`);
|
|
}
|
|
// Notify dreamseeker
|
|
const dss = await dssPromise;
|
|
if (dss.length > 0) {
|
|
logger.log(`notifying dreamseeker`);
|
|
for (let dreamseeker of dss) {
|
|
dreamseeker.topic({
|
|
tgui: 1,
|
|
type: 'cacheReloaded',
|
|
});
|
|
}
|
|
}
|
|
};
|