Some app cleanups

This commit is contained in:
WolverinDEV 2021-01-10 16:26:45 +01:00 committed by WolverinDEV
parent 20ea542598
commit 55f9c2737f
19 changed files with 159 additions and 193 deletions

View file

@ -1,25 +1,7 @@
import {ConnectionHandler, DisconnectReason} from "./ConnectionHandler"; import {ConnectionHandler, DisconnectReason} from "./ConnectionHandler";
import {Registry} from "./events"; import {Registry} from "./events";
import * as loader from "tc-loader";
import {Stage} from "tc-loader"; import {Stage} from "tc-loader";
import * as loader from "tc-loader";
export let server_connections: ConnectionManager;
class ReplaceableContainer {
placeholder: HTMLDivElement;
container: HTMLDivElement;
constructor(container: HTMLDivElement, placeholder?: HTMLDivElement) {
this.container = container;
this.placeholder = placeholder || document.createElement("div");
}
replaceWith(target: HTMLDivElement | undefined) {
target = target || this.placeholder;
this.container.replaceWith(target);
this.container = target;
}
}
export interface ConnectionManagerEvents { export interface ConnectionManagerEvents {
notify_handler_created: { notify_handler_created: {
@ -51,22 +33,18 @@ export class ConnectionManager {
private connectionHandlers: ConnectionHandler[] = []; private connectionHandlers: ConnectionHandler[] = [];
private activeConnectionHandler: ConnectionHandler | undefined; private activeConnectionHandler: ConnectionHandler | undefined;
private containerChannelVideo: ReplaceableContainer;
constructor() { constructor() {
this.events_ = new Registry<ConnectionManagerEvents>(); this.events_ = new Registry<ConnectionManagerEvents>();
this.events_.enableDebug("connection-manager"); this.events_.enableDebug("connection-manager");
/* FIXME! */ this.setActiveConnectionHandler(undefined);
this.containerChannelVideo = new ReplaceableContainer(document.getElementById("channel-video") as HTMLDivElement);
this.set_active_connection(undefined);
} }
events() : Registry<ConnectionManagerEvents> { events() : Registry<ConnectionManagerEvents> {
return this.events_; return this.events_;
} }
spawn_server_connection() : ConnectionHandler { spawnConnectionHandler() : ConnectionHandler {
const handler = new ConnectionHandler(); const handler = new ConnectionHandler();
handler.initialize_client_state(this.activeConnectionHandler); handler.initialize_client_state(this.activeConnectionHandler);
this.connectionHandlers.push(handler); this.connectionHandlers.push(handler);
@ -75,7 +53,7 @@ export class ConnectionManager {
return handler; return handler;
} }
destroy_server_connection(handler: ConnectionHandler) { destroyConnectionHandler(handler: ConnectionHandler) {
if(this.connectionHandlers.length <= 1) { if(this.connectionHandlers.length <= 1) {
throw "cannot deleted the last connection handler"; throw "cannot deleted the last connection handler";
} }
@ -91,7 +69,7 @@ export class ConnectionManager {
} }
if(handler === this.activeConnectionHandler) { if(handler === this.activeConnectionHandler) {
this.set_active_connection_(this.connectionHandlers[0]); this.doSetActiveConnectionHandler(this.connectionHandlers[0]);
} }
this.events_.fire("notify_handler_deleted", { handler: handler, handlerId: handler.handlerId }); this.events_.fire("notify_handler_deleted", { handler: handler, handlerId: handler.handlerId });
@ -99,7 +77,7 @@ export class ConnectionManager {
handler.destroy(); handler.destroy();
} }
set_active_connection(handler: ConnectionHandler) { setActiveConnectionHandler(handler: ConnectionHandler) {
if(handler && this.connectionHandlers.indexOf(handler) == -1) { if(handler && this.connectionHandlers.indexOf(handler) == -1) {
throw "Handler hasn't been registered or is already obsolete!"; throw "Handler hasn't been registered or is already obsolete!";
} }
@ -108,7 +86,21 @@ export class ConnectionManager {
return; return;
} }
this.set_active_connection_(handler); this.doSetActiveConnectionHandler(handler);
}
private doSetActiveConnectionHandler(handler: ConnectionHandler) {
const oldHandler = this.activeConnectionHandler;
this.activeConnectionHandler = handler;
this.events_.fire("notify_active_handler_changed", {
oldHandler: oldHandler,
newHandler: handler,
oldHandlerId: oldHandler?.handlerId,
newHandlerId: handler?.handlerId
});
oldHandler?.events().fire("notify_visibility_changed", { visible: false });
handler?.events().fire("notify_visibility_changed", { visible: true });
} }
swapHandlerOrder(handlerA: ConnectionHandler, handlerB: ConnectionHandler) { swapHandlerOrder(handlerA: ConnectionHandler, handlerB: ConnectionHandler) {
@ -125,37 +117,20 @@ export class ConnectionManager {
this.events().fire("notify_handler_order_changed"); this.events().fire("notify_handler_order_changed");
} }
private set_active_connection_(handler: ConnectionHandler) {
/*
this.containerChannelVideo.replaceWith(handler?.video_frame.getContainer());
*/
const oldHandler = this.activeConnectionHandler;
this.activeConnectionHandler = handler;
this.events_.fire("notify_active_handler_changed", {
oldHandler: oldHandler,
newHandler: handler,
oldHandlerId: oldHandler?.handlerId,
newHandlerId: handler?.handlerId
});
oldHandler?.events().fire("notify_visibility_changed", { visible: false });
handler?.events().fire("notify_visibility_changed", { visible: true });
}
findConnection(handlerId: string) : ConnectionHandler | undefined { findConnection(handlerId: string) : ConnectionHandler | undefined {
return this.connectionHandlers.find(e => e.handlerId === handlerId); return this.connectionHandlers.find(e => e.handlerId === handlerId);
} }
active_connection() : ConnectionHandler | undefined { getActiveConnectionHandler() : ConnectionHandler | undefined {
return this.activeConnectionHandler; return this.activeConnectionHandler;
} }
all_connections() : ConnectionHandler[] { getAllConnectionHandlers() : ConnectionHandler[] {
return this.connectionHandlers; return this.connectionHandlers;
} }
} }
export let server_connections: ConnectionManager;
loader.register_task(Stage.JAVASCRIPT_INITIALIZING, { loader.register_task(Stage.JAVASCRIPT_INITIALIZING, {
name: "server manager init", name: "server manager init",
function: async () => { function: async () => {

View file

@ -1,10 +1,10 @@
import {EventType, KeyDescriptor, KeyEvent, KeyHook} from "./PPTListener";
import * as ppt from "tc-backend/ppt"; import * as ppt from "tc-backend/ppt";
import {Settings, settings} from "./settings";
import * as log from "./log"; import * as log from "./log";
import {LogCategory} from "./log"; import {LogCategory, logWarn} from "./log";
import {KeyDescriptor, KeyHook} from "./PPTListener";
import {Settings, settings} from "./settings";
import {server_connections} from "tc-shared/ConnectionManager"; import {server_connections} from "tc-shared/ConnectionManager";
import { tr } from "./i18n/localize"; import {tr} from "./i18n/localize";
export interface KeyControl { export interface KeyControl {
category: string; category: string;
@ -33,51 +33,51 @@ export const KeyTypes: {[key: string]:KeyControl} = {
"disconnect-current": { "disconnect-current": {
category: "connection", category: "connection",
description: "Disconnect from the current server", description: "Disconnect from the current server",
handler: () => server_connections.active_connection()?.disconnectFromServer(), handler: () => server_connections.getActiveConnectionHandler()?.disconnectFromServer(),
icon: "client-disconnect" icon: "client-disconnect"
}, },
"disconnect-all": { "disconnect-all": {
category: "connection", category: "connection",
description: "Disconnect from all connected servers", description: "Disconnect from all connected servers",
handler: () => server_connections.all_connections().forEach(e => e.disconnectFromServer()), handler: () => server_connections.getAllConnectionHandlers().forEach(e => e.disconnectFromServer()),
icon: "client-disconnect" icon: "client-disconnect"
}, },
"toggle-microphone": { "toggle-microphone": {
category: "microphone", category: "microphone",
description: "Toggle your microphone status", description: "Toggle your microphone status",
handler: () => server_connections.active_connection()?.toggleMicrophone(), handler: () => server_connections.getActiveConnectionHandler()?.toggleMicrophone(),
icon: "client-input_muted" icon: "client-input_muted"
}, },
"enable-microphone": { "enable-microphone": {
category: "microphone", category: "microphone",
description: "Enable your microphone", description: "Enable your microphone",
handler: () => server_connections.active_connection()?.setMicrophoneMuted(false), handler: () => server_connections.getActiveConnectionHandler()?.setMicrophoneMuted(false),
icon: "client-input_muted" icon: "client-input_muted"
}, },
"disable-microphone": { "disable-microphone": {
category: "microphone", category: "microphone",
description: "Disable your microphone", description: "Disable your microphone",
handler: () => server_connections.active_connection()?.setMicrophoneMuted(true), handler: () => server_connections.getActiveConnectionHandler()?.setMicrophoneMuted(true),
icon: "client-input_muted" icon: "client-input_muted"
}, },
"toggle-speaker": { "toggle-speaker": {
category: "speaker", category: "speaker",
description: "Toggle your speaker status", description: "Toggle your speaker status",
handler: () => server_connections.active_connection()?.toggleSpeakerMuted(), handler: () => server_connections.getActiveConnectionHandler()?.toggleSpeakerMuted(),
icon: "client-output_muted" icon: "client-output_muted"
}, },
"enable-speaker": { "enable-speaker": {
category: "speaker", category: "speaker",
description: "Enable your speakers", description: "Enable your speakers",
handler: () => server_connections.active_connection()?.setSpeakerMuted(false), handler: () => server_connections.getActiveConnectionHandler()?.setSpeakerMuted(false),
icon: "client-output_muted" icon: "client-output_muted"
}, },
"disable-speaker": { "disable-speaker": {
category: "speaker", category: "speaker",
description: "Disable your speakers", description: "Disable your speakers",
handler: () => server_connections.active_connection()?.setSpeakerMuted(true), handler: () => server_connections.getActiveConnectionHandler()?.setSpeakerMuted(true),
icon: "client-output_muted" icon: "client-output_muted"
}, },
@ -85,42 +85,42 @@ export const KeyTypes: {[key: string]:KeyControl} = {
"toggle-away-state": { "toggle-away-state": {
category: "away", category: "away",
description: "Toggle your away state", description: "Toggle your away state",
handler: () => server_connections.active_connection()?.toggleAway(), handler: () => server_connections.getActiveConnectionHandler()?.toggleAway(),
icon: "client-away" icon: "client-away"
}, },
"enable-away-state": { "enable-away-state": {
category: "away", category: "away",
description: "Enable away for the current server", description: "Enable away for the current server",
handler: () => server_connections.active_connection()?.setAway(true), handler: () => server_connections.getActiveConnectionHandler()?.setAway(true),
icon: "client-away" icon: "client-away"
}, },
"disable-away-state": { "disable-away-state": {
category: "away", category: "away",
description: "Disable away for the current server", description: "Disable away for the current server",
handler: () => server_connections.active_connection()?.setAway(false), handler: () => server_connections.getActiveConnectionHandler()?.setAway(false),
icon: "client-present" icon: "client-present"
}, },
"toggle-away-state-globally": { "toggle-away-state-globally": {
category: "away", category: "away",
description: "Toggle your away state for every server", description: "Toggle your away state for every server",
handler: () => server_connections.all_connections().forEach(e => e.toggleAway()), handler: () => server_connections.getAllConnectionHandlers().forEach(e => e.toggleAway()),
icon: "client-away" icon: "client-away"
}, },
"enable-away-state-globally": { "enable-away-state-globally": {
category: "away", category: "away",
description: "Enable away for every server", description: "Enable away for every server",
handler: () => server_connections.all_connections().forEach(e => e.setAway(true)), handler: () => server_connections.getAllConnectionHandlers().forEach(e => e.setAway(true)),
icon: "client-away" icon: "client-away"
}, },
"disable-away-state-globally": { "disable-away-state-globally": {
category: "away", category: "away",
description: "Disable away for every server", description: "Disable away for every server",
handler: () => server_connections.all_connections().forEach(e => e.setAway(false)), handler: () => server_connections.getAllConnectionHandlers().forEach(e => e.setAway(false)),
icon: "client-present" icon: "client-present"
}, },
}; };
let key_bindings: {[key: string]: { let keyBindings: {[key: string]: {
binding: KeyDescriptor, binding: KeyDescriptor,
hook: KeyHook hook: KeyHook
}} = {}; }} = {};
@ -132,7 +132,7 @@ interface Config {
} }
let config: Config; let config: Config;
export function initialize() { export function initializeKeyControl() {
let cfg: Config; let cfg: Config;
try { try {
cfg = JSON.parse(settings.getValue(Settings.KEY_KEYCONTROL_DATA)); cfg = JSON.parse(settings.getValue(Settings.KEY_KEYCONTROL_DATA));
@ -149,7 +149,14 @@ export function initialize() {
case 0: case 0:
cfg.version = 1; cfg.version = 1;
cfg.keys = {}; cfg.keys = {};
/* fall though wanted */
case 1:
/* config up to date */
break;
default: default:
logWarn(LogCategory.GENERAL, tr("Key control config has an invalid version:%o"), cfg.version);
break; break;
} }
config = cfg; config = cfg;
@ -158,20 +165,21 @@ export function initialize() {
if(typeof KeyTypes[key] !== "object") if(typeof KeyTypes[key] !== "object")
continue; continue;
bind_key(key, config.keys[key]); bindKey(key, config.keys[key]);
} }
} }
function save_config() { function saveConfig() {
settings.setValue(Settings.KEY_KEYCONTROL_DATA, JSON.stringify(config)); settings.setValue(Settings.KEY_KEYCONTROL_DATA, JSON.stringify(config));
} }
function bind_key(action: string, key: KeyDescriptor) { function bindKey(action: string, key: KeyDescriptor) {
const control = KeyTypes[action]; const control = KeyTypes[action];
if(typeof control === "undefined") if(typeof control === "undefined") {
throw "missing control event"; throw "missing control event";
}
key_bindings[action] = { keyBindings[action] = {
hook: Object.assign({ hook: Object.assign({
callback_press: () => control.handler(), callback_press: () => control.handler(),
callback_release: () => {}, callback_release: () => {},
@ -179,22 +187,23 @@ function bind_key(action: string, key: KeyDescriptor) {
}, key), }, key),
binding: key binding: key
}; };
ppt.register_key_hook(key_bindings[action].hook); ppt.register_key_hook(keyBindings[action].hook);
} }
export function set_key(action: string, key?: KeyDescriptor) { export function setKey(action: string, key?: KeyDescriptor) {
if(typeof key_bindings[action] !== "undefined") { if(typeof keyBindings[action] !== "undefined") {
ppt.unregister_key_hook(key_bindings[action].hook); ppt.unregister_key_hook(keyBindings[action].hook);
delete key_bindings[action]; delete keyBindings[action];
} }
if(key) { if(key) {
bind_key(action, key); bindKey(action, key);
config.keys[action] = key; config.keys[action] = key;
} else { } else {
delete config.keys[action]; delete config.keys[action];
} }
save_config(); saveConfig();
} }
export function key(action: string) : KeyDescriptor | undefined { return key_bindings[action]?.binding; } export function key(action: string) : KeyDescriptor | undefined { return keyBindings[action]?.binding; }

View file

@ -18,8 +18,8 @@ export const bookmarkEvents = new Registry<BookmarkEvents>();
export const boorkmak_connect = (mark: Bookmark, new_tab?: boolean) => { export const boorkmak_connect = (mark: Bookmark, new_tab?: boolean) => {
const profile = findConnectProfile(mark.connect_profile) || defaultConnectProfile(); const profile = findConnectProfile(mark.connect_profile) || defaultConnectProfile();
if(profile.valid()) { if(profile.valid()) {
const connection = (typeof(new_tab) !== "boolean" || !new_tab) ? server_connections.active_connection() : server_connections.spawn_server_connection(); const connection = (typeof(new_tab) !== "boolean" || !new_tab) ? server_connections.getActiveConnectionHandler() : server_connections.spawnConnectionHandler();
server_connections.set_active_connection(connection); server_connections.setActiveConnectionHandler(connection);
connection.startConnection( connection.startConnection(
mark.server_properties.server_address + ":" + mark.server_properties.server_port, mark.server_properties.server_address + ":" + mark.server_properties.server_port,
profile, profile,

View file

@ -238,7 +238,7 @@ export class ConnectionCommandHandler extends AbstractCommandHandler {
if(properties.virtualserver_ask_for_privilegekey) { if(properties.virtualserver_ask_for_privilegekey) {
createInputModal(tr("Use a privilege key"), tr("This is a newly created server for which administrator privileges have not yet been claimed.<br>Please enter the \"privilege key\" that was automatically generated when this server was created to gain administrator permissions."), message => message.length > 0, result => { createInputModal(tr("Use a privilege key"), tr("This is a newly created server for which administrator privileges have not yet been claimed.<br>Please enter the \"privilege key\" that was automatically generated when this server was created to gain administrator permissions."), message => message.length > 0, result => {
if(!result) return; if(!result) return;
const scon = server_connections.active_connection(); const scon = server_connections.getActiveConnectionHandler();
if(scon.serverConnection.connected) if(scon.serverConnection.connected)
scon.serverConnection.send_command("tokenuse", { scon.serverConnection.send_command("tokenuse", {

View file

@ -159,7 +159,7 @@ export function initialize(event_registry: Registry<ClientGlobalControlEvents>)
break; break;
case "server-echo-test": case "server-echo-test":
const connection = event.connection || server_connections.active_connection(); const connection = event.connection || server_connections.getActiveConnectionHandler();
if(connection) { if(connection) {
spawnEchoTestModal(connection); spawnEchoTestModal(connection);
} }
@ -181,7 +181,7 @@ export function initialize(event_registry: Registry<ClientGlobalControlEvents>)
}); });
event_registry.on("action_open_window_permissions", event => { event_registry.on("action_open_window_permissions", event => {
spawnPermissionEditorModal(event.connection ? event.connection : server_connections.active_connection(), event.defaultTab); spawnPermissionEditorModal(event.connection ? event.connection : server_connections.getActiveConnectionHandler(), event.defaultTab);
}); });
event_registry.on("action_toggle_video_broadcasting", event => { event_registry.on("action_toggle_video_broadcasting", event => {

View file

@ -338,7 +338,7 @@ export class AvatarManager extends AbstractAvatarManager {
} }
} }
(window as any).flush_avatar_cache = async () => { (window as any).flush_avatar_cache = async () => {
server_connections.all_connections().forEach(e => { server_connections.getAllConnectionHandlers().forEach(e => {
e.fileManager.avatars.flush_cache(); e.fileManager.avatars.flush_cache();
}); });
}; };
@ -385,7 +385,7 @@ class LocalAvatarManagerFactory extends AbstractAvatarManagerFactory {
if(message.type === "query-handlers") { if(message.type === "query-handlers") {
this.ipcChannel.sendMessage("notify-handlers", { this.ipcChannel.sendMessage("notify-handlers", {
handlers: server_connections.all_connections().map(e => e.handlerId) handlers: server_connections.getAllConnectionHandlers().map(e => e.handlerId)
}, remoteId); }, remoteId);
return; return;
} else if(message.type === "load-avatar") { } else if(message.type === "load-avatar") {

View file

@ -226,7 +226,7 @@ class IconManager extends AbstractIconManager {
logWarn(LogCategory.FILE_TRANSFER, tr("Received handler id hint for icon download, but handler %s does not exists. Trying others."), handlerIdHint); logWarn(LogCategory.FILE_TRANSFER, tr("Received handler id hint for icon download, but handler %s does not exists. Trying others."), handlerIdHint);
} }
const connections = server_connections.all_connections() const connections = server_connections.getAllConnectionHandlers()
.filter(handler => handler.connected) .filter(handler => handler.connected)
.filter(handler => handler.channelTree.server.properties.virtualserver_unique_identifier === icon.serverUniqueId); .filter(handler => handler.channelTree.server.properties.virtualserver_unique_identifier === icon.serverUniqueId);

View file

@ -1,58 +1,52 @@
import * as loader from "tc-loader"; import * as loader from "tc-loader";
import {Stage} from "tc-loader";
import {AppParameters, settings, Settings} from "tc-shared/settings";
import * as log from "tc-shared/log";
import {LogCategory} from "tc-shared/log";
import * as bipc from "./ipc/BrowserIPC"; import * as bipc from "./ipc/BrowserIPC";
import * as sound from "./sound/Sounds"; import * as sound from "./sound/Sounds";
import * as i18n from "./i18n/localize"; import * as i18n from "./i18n/localize";
import * as stats from "./stats";
import * as fidentity from "./profiles/identities/TeaForumIdentity";
import * as aplayer from "tc-backend/audio/player";
import * as ppt from "tc-backend/ppt";
import * as global_ev_handler from "./events/ClientGlobalControlHandler";
import {Stage} from "tc-loader";
import {AppParameters, settings, Settings} from "tc-shared/settings";
import {LogCategory, logError, logInfo} from "tc-shared/log";
import {tra} from "./i18n/localize"; import {tra} from "./i18n/localize";
import {ConnectionHandler} from "tc-shared/ConnectionHandler"; import {ConnectionHandler} from "tc-shared/ConnectionHandler";
import {createInfoModal} from "tc-shared/ui/elements/Modal"; import {createInfoModal} from "tc-shared/ui/elements/Modal";
import * as stats from "./stats";
import * as fidentity from "./profiles/identities/TeaForumIdentity";
import {defaultRecorder, RecorderProfile, setDefaultRecorder} from "tc-shared/voice/RecorderProfile"; import {defaultRecorder, RecorderProfile, setDefaultRecorder} from "tc-shared/voice/RecorderProfile";
import {spawnYesNo} from "tc-shared/ui/modal/ModalYesNo"; import {spawnYesNo} from "tc-shared/ui/modal/ModalYesNo";
import {formatMessage} from "tc-shared/ui/frames/chat"; import {formatMessage} from "tc-shared/ui/frames/chat";
import {openModalNewcomer} from "tc-shared/ui/modal/ModalNewcomer"; import {openModalNewcomer} from "tc-shared/ui/modal/ModalNewcomer";
import * as aplayer from "tc-backend/audio/player";
import * as ppt from "tc-backend/ppt";
import * as keycontrol from "./KeyControl";
import * as React from "react";
import * as global_ev_handler from "./events/ClientGlobalControlHandler";
import {global_client_actions} from "tc-shared/events/GlobalEvents"; import {global_client_actions} from "tc-shared/events/GlobalEvents";
import {FileTransferState, TransferProvider,} from "tc-shared/file/Transfer";
import {MenuEntryType, spawn_context_menu} from "tc-shared/ui/elements/ContextMenu"; import {MenuEntryType, spawn_context_menu} from "tc-shared/ui/elements/ContextMenu";
import {copyToClipboard} from "tc-shared/utils/helpers"; import {copyToClipboard} from "tc-shared/utils/helpers";
import {checkForUpdatedApp} from "tc-shared/update"; import {checkForUpdatedApp} from "tc-shared/update";
import {setupJSRender} from "tc-shared/ui/jsrender"; import {setupJSRender} from "tc-shared/ui/jsrender";
import {ConnectRequestData} from "tc-shared/ipc/ConnectHandler"; import {ConnectRequestData} from "tc-shared/ipc/ConnectHandler";
import "svg-sprites/client-icons"; import {defaultConnectProfile, findConnectProfile} from "tc-shared/profiles/ConnectionProfile";
import {server_connections} from "tc-shared/ConnectionManager";
import {spawnConnectModalNew} from "tc-shared/ui/modal/connect/Controller";
/* required import for init */ /* required import for init */
import "svg-sprites/client-icons";
import "../css/load-css" import "../css/load-css"
import "./proto"; import "./proto";
import "./ui/elements/ContextDivider";
import "./ui/elements/Tab";
import "./connection/CommandHandler";
import "./connection/ConnectionBase";
import "./video-viewer/Controller"; import "./video-viewer/Controller";
import "./profiles/ConnectionProfile"; import "./profiles/ConnectionProfile";
import "./update/UpdaterWeb"; import "./update/UpdaterWeb";
import "./file/LocalIcons"; import "./file/LocalIcons";
import "./ui/frames/menu-bar/MainMenu"; import "./connection/CommandHandler";
import "./connection/ConnectionBase";
import "./connection/rtc/Connection"; import "./connection/rtc/Connection";
import "./connection/rtc/video/Connection"; import "./connection/rtc/video/Connection";
import "./video/VideoSource"; import "./video/VideoSource";
import "./media/Video"; import "./media/Video";
import "./ui/AppController"; import "./ui/AppController";
import "./ui/frames/menu-bar/MainMenu";
import {defaultConnectProfile, findConnectProfile} from "tc-shared/profiles/ConnectionProfile";
import {server_connections} from "tc-shared/ConnectionManager";
import ContextMenuEvent = JQuery.ContextMenuEvent;
import "./ui/modal/connect/Controller"; import "./ui/modal/connect/Controller";
import {spawnConnectModalNew} from "tc-shared/ui/modal/connect/Controller"; import "./ui/elements/ContextDivider";
import "./ui/elements/Tab";
import {initializeKeyControl} from "./KeyControl";
let preventWelcomeUI = false; let preventWelcomeUI = false;
async function initialize() { async function initialize() {
@ -67,15 +61,8 @@ async function initialize() {
bipc.setup(); bipc.setup();
} }
async function initialize_app() { async function initializeApp() {
global_ev_handler.initialize(global_client_actions); global_ev_handler.initialize(global_client_actions);
/*
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "settings init",
priority: 10,
function: async () => global_ev_handler.load_default_states(client_control_events)
});
*/
if(!aplayer.initialize()) { if(!aplayer.initialize()) {
console.warn(tr("Failed to initialize audio controller!")); console.warn(tr("Failed to initialize audio controller!"));
@ -85,26 +72,25 @@ async function initialize_app() {
setDefaultRecorder(new RecorderProfile("default")); setDefaultRecorder(new RecorderProfile("default"));
defaultRecorder.initialize().catch(error => { defaultRecorder.initialize().catch(error => {
log.error(LogCategory.AUDIO, tr("Failed to initialize default recorder: %o"), error); logError(LogCategory.AUDIO, tr("Failed to initialize default recorder: %o"), error);
}); });
sound.initialize().then(() => { sound.initialize().then(() => {
log.info(LogCategory.AUDIO, tr("Sounds initialized")); logInfo(LogCategory.AUDIO, tr("Sounds initialized"));
}); });
sound.set_master_volume(settings.getValue(Settings.KEY_SOUND_MASTER_SOUNDS) / 100); sound.set_master_volume(settings.getValue(Settings.KEY_SOUND_MASTER_SOUNDS) / 100);
try { try {
await ppt.initialize(); await ppt.initialize();
} catch(error) { } catch(error) {
log.error(LogCategory.GENERAL, tr("Failed to initialize ppt!\nError: %o"), error); logError(LogCategory.GENERAL, tr("Failed to initialize ppt!\nError: %o"), error);
loader.critical_error(tr("Failed to initialize ppt!")); loader.critical_error(tr("Failed to initialize ppt!"));
return; return;
} }
} }
export function handle_connect_request(properties: ConnectRequestData, connection: ConnectionHandler) { export function handle_connect_request(properties: ConnectRequestData, connection: ConnectionHandler) {
const profile_uuid = properties.profile || (defaultConnectProfile() || { id: 'default' }).id; const profile = findConnectProfile(properties.profile) || defaultConnectProfile();
const profile = findConnectProfile(profile_uuid) || defaultConnectProfile();
const username = properties.username || profile.connectUsername(); const username = properties.username || profile.connectUsername();
const password = properties.password ? properties.password.value : ""; const password = properties.password ? properties.password.value : "";
@ -114,6 +100,7 @@ export function handle_connect_request(properties: ConnectRequestData, connectio
settings.setValue(Settings.KEY_USER_IS_NEW, false); settings.setValue(Settings.KEY_USER_IS_NEW, false);
if(!aplayer.initialized()) { if(!aplayer.initialized()) {
/* Trick the client into clicking somewhere on the site */
spawnYesNo(tra("Connect to {}", properties.address), tra("Would you like to connect to {}?", properties.address), result => { spawnYesNo(tra("Connect to {}", properties.address), tra("Would you like to connect to {}?", properties.address), result => {
if(result) { if(result) {
aplayer.on_ready(() => handle_connect_request(properties, connection)); aplayer.on_ready(() => handle_connect_request(properties, connection));
@ -123,6 +110,7 @@ export function handle_connect_request(properties: ConnectRequestData, connectio
}).open(); }).open();
return; return;
} }
connection.startConnection(properties.address, profile, true, { connection.startConnection(properties.address, profile, true, {
nickname: username, nickname: username,
password: password.length > 0 ? { password: password.length > 0 ? {
@ -130,7 +118,7 @@ export function handle_connect_request(properties: ConnectRequestData, connectio
hashed: password_hashed hashed: password_hashed
} : undefined } : undefined
}); });
server_connections.set_active_connection(connection); server_connections.setActiveConnectionHandler(connection);
} else { } else {
spawnConnectModalNew({ spawnConnectModalNew({
selectedAddress: properties.address, selectedAddress: properties.address,
@ -143,24 +131,26 @@ function main() {
/* initialize font */ /* initialize font */
{ {
const font = settings.getValue(Settings.KEY_FONT_SIZE); const font = settings.getValue(Settings.KEY_FONT_SIZE);
$(document.body).css("font-size", font + "px");
document.body.style.fontSize = font + "px";
settings.globalChangeListener(Settings.KEY_FONT_SIZE, value => { settings.globalChangeListener(Settings.KEY_FONT_SIZE, value => {
$(document.body).css("font-size", value + "px"); document.body.style.fontSize = value + "px";
}) });
} }
/* context menu prevent */ /* context menu prevent */
$(document).on('contextmenu', (event: ContextMenuEvent) => { document.addEventListener("contextmenu", event => {
if(event.isDefaultPrevented()) { if(event.defaultPrevented) {
return; return;
} }
if(event.target instanceof HTMLInputElement) { if(event.target instanceof HTMLInputElement) {
const target = event.target;
if((!!event.target.value || __build.target === "client") && !event.target.disabled && !event.target.readOnly && event.target.type !== "number") { if((!!event.target.value || __build.target === "client") && !event.target.disabled && !event.target.readOnly && event.target.type !== "number") {
spawn_context_menu(event.pageX, event.pageY, { spawn_context_menu(event.pageX, event.pageY, {
type: MenuEntryType.ENTRY, type: MenuEntryType.ENTRY,
name: tr("Copy"), name: tr("Copy"),
callback: () => copyToClipboard(event.target.value), callback: () => copyToClipboard(target.value),
icon_class: "client-copy", icon_class: "client-copy",
visible: !!event.target.value visible: !!event.target.value
}, { }, {
@ -168,7 +158,7 @@ function main() {
name: tr("Paste"), name: tr("Paste"),
callback: () => { callback: () => {
const { clipboard } = __non_webpack_require__('electron'); const { clipboard } = __non_webpack_require__('electron');
event.target.value = clipboard.readText(); target.value = clipboard.readText();
}, },
icon_class: "client-copy", icon_class: "client-copy",
visible: __build.target === "client", visible: __build.target === "client",
@ -185,13 +175,13 @@ function main() {
}); });
window.removeLoaderContextMenuHook(); window.removeLoaderContextMenuHook();
const initialHandler = server_connections.spawn_server_connection(); const initialHandler = server_connections.spawnConnectionHandler();
server_connections.set_active_connection(initialHandler); server_connections.setActiveConnectionHandler(initialHandler);
initialHandler.acquireInputHardware().then(() => {}); initialHandler.acquireInputHardware().then(() => {});
/** Setup the XF forum identity **/ /** Setup the XF forum identity **/
fidentity.update_forum(); fidentity.update_forum();
keycontrol.initialize(); initializeKeyControl();
stats.initialize({ stats.initialize({
verbose: true, verbose: true,
@ -199,8 +189,8 @@ function main() {
volatile_collection_only: false volatile_collection_only: false
}); });
stats.register_user_count_listener(status => { stats.registerUserCountListener(status => {
log.info(LogCategory.STATISTICS, tr("Received user count update: %o"), status); logInfo(LogCategory.STATISTICS, tr("Received user count update: %o"), status);
}); });
checkForUpdatedApp(); checkForUpdatedApp();
@ -215,10 +205,10 @@ const task_teaweb_starter: loader.Task = {
name: "voice app starter", name: "voice app starter",
function: async () => { function: async () => {
try { try {
await initialize_app(); await initializeApp();
main(); main();
if(!aplayer.initialized()) { if(!aplayer.initialized()) {
log.info(LogCategory.VOICE, tr("Initialize audio controller later!")); logInfo(LogCategory.VOICE, tr("Initialize audio controller later!"));
if(!aplayer.initializeFromGesture) { if(!aplayer.initializeFromGesture) {
console.error(tr("Missing aplayer.initializeFromGesture")); console.error(tr("Missing aplayer.initializeFromGesture"));
} else { } else {
@ -270,7 +260,7 @@ const task_connect_handler: loader.Task = {
closeable: false closeable: false
}).open(); }).open();
})); }));
log.info(LogCategory.CLIENT, tr("Executed connect successfully in another browser window. Closing this window")); logInfo(LogCategory.CLIENT, tr("Executed connect successfully in another browser window. Closing this window"));
const message = const message =
"You're connecting to {0} within the other TeaWeb instance.{:br:}" + "You're connecting to {0} within the other TeaWeb instance.{:br:}" +
@ -285,7 +275,7 @@ const task_connect_handler: loader.Task = {
).open(); ).open();
return; return;
} catch(error) { } catch(error) {
log.info(LogCategory.CLIENT, tr("Failed to execute connect within other TeaWeb instance. Using this one. Error: %o"), error); logInfo(LogCategory.CLIENT, tr("Failed to execute connect within other TeaWeb instance. Using this one. Error: %o"), error);
} }
if(chandler) { if(chandler) {
@ -296,7 +286,7 @@ const task_connect_handler: loader.Task = {
chandler.callback_execute = data => { chandler.callback_execute = data => {
preventWelcomeUI = true; preventWelcomeUI = true;
handle_connect_request(data, server_connections.spawn_server_connection()); handle_connect_request(data, server_connections.spawnConnectionHandler());
return true; return true;
} }
} }
@ -305,7 +295,7 @@ const task_connect_handler: loader.Task = {
preventWelcomeUI = true; preventWelcomeUI = true;
loader.register_task(loader.Stage.LOADED, { loader.register_task(loader.Stage.LOADED, {
priority: 0, priority: 0,
function: async () => handle_connect_request(connectData, server_connections.active_connection() || server_connections.spawn_server_connection()), function: async () => handle_connect_request(connectData, server_connections.getActiveConnectionHandler() || server_connections.spawnConnectionHandler()),
name: tr("default url connect") name: tr("default url connect")
}); });
loader.register_task(loader.Stage.LOADED, task_teaweb_starter); loader.register_task(loader.Stage.LOADED, task_teaweb_starter);
@ -365,18 +355,14 @@ loader.register_task(loader.Stage.LOADED, {
priority: 2000 priority: 2000
}); });
/* TODO: Remove this after the image preview has been rewritten into react */
loader.register_task(Stage.JAVASCRIPT_INITIALIZING,{ loader.register_task(Stage.JAVASCRIPT_INITIALIZING,{
name: "app init", name: "app init",
function: async () => { function: async () => {
try { //Initialize main template try {
const main = $("#tmpl_main").renderTag({ $("body").append($("#tmpl_main").renderTag());
multi_session: !settings.getValue(Settings.KEY_DISABLE_MULTI_SESSION),
app_version: __build.version
}).dividerfy();
$("body").append(main);
} catch(error) { } catch(error) {
log.error(LogCategory.GENERAL, error); logError(LogCategory.GENERAL, error);
loader.critical_error(tr("Failed to setup main page!")); loader.critical_error(tr("Failed to setup main page!"));
return; return;
} }

View file

@ -79,15 +79,11 @@ export function initialize(config: Config) {
connection.start_connection(); connection.start_connection();
} }
export function register_user_count_listener(listener: UserCountListener) { export function registerUserCountListener(listener: UserCountListener) {
user_count_listener.push(listener); user_count_listener.push(listener);
} }
export function all_user_count_listener() : UserCountListener[] { export function unregisterUserCountListener(listener: UserCountListener) {
return user_count_listener;
}
export function deregister_user_count_listener(listener: UserCountListener) {
user_count_listener.remove(listener); user_count_listener.remove(listener);
} }

View file

@ -46,7 +46,7 @@ export const YoutubeRenderer = (props: { children?: React.ReactElement | React.R
callback: () => { callback: () => {
global_client_actions.fire("action_w2g", { global_client_actions.fire("action_w2g", {
videoUrl: props.url, videoUrl: props.url,
handlerId: server_connections.active_connection().handlerId handlerId: server_connections.getActiveConnectionHandler().handlerId
}); });
}, },
name: tr("Watch video"), name: tr("Watch video"),
@ -72,7 +72,7 @@ export const YoutubeRenderer = (props: { children?: React.ReactElement | React.R
<button className={cssStyle.playButton} onClick={() => { <button className={cssStyle.playButton} onClick={() => {
global_client_actions.fire("action_w2g", { global_client_actions.fire("action_w2g", {
videoUrl: props.url, videoUrl: props.url,
handlerId: server_connections.active_connection().handlerId handlerId: server_connections.getActiveConnectionHandler().handlerId
}); });
}}> }}>
<HTMLRenderer purify={false}>{playIcon}</HTMLRenderer> <HTMLRenderer purify={false}>{playIcon}</HTMLRenderer>

View file

@ -82,7 +82,7 @@ export class AppController {
initializeConnectionListController(this.connectionListEvents); initializeConnectionListController(this.connectionListEvents);
this.listener.push(server_connections.events().on("notify_active_handler_changed", event => this.setConnectionHandler(event.newHandler))); this.listener.push(server_connections.events().on("notify_active_handler_changed", event => this.setConnectionHandler(event.newHandler)));
this.setConnectionHandler(server_connections.active_connection()); this.setConnectionHandler(server_connections.getActiveConnectionHandler());
this.sideBarController = new SideBarController(); this.sideBarController = new SideBarController();
this.serverLogController = new ServerEventLogController(); this.serverLogController = new ServerEventLogController();

View file

@ -14,7 +14,7 @@ export function initializeConnectionListController(events: Registry<ConnectionLi
}); });
events.on("query_handler_list", () => { events.on("query_handler_list", () => {
events.fire_react("notify_handler_list", { handlerIds: server_connections.all_connections().map(e => e.handlerId), activeHandlerId: server_connections.active_connection()?.handlerId }); events.fire_react("notify_handler_list", { handlerIds: server_connections.getAllConnectionHandlers().map(e => e.handlerId), activeHandlerId: server_connections.getActiveConnectionHandler()?.handlerId });
}); });
events.on("notify_destroy", server_connections.events().on("notify_handler_created", event => { events.on("notify_destroy", server_connections.events().on("notify_handler_created", event => {
let listeners = []; let listeners = [];
@ -66,7 +66,7 @@ export function initializeConnectionListController(events: Registry<ConnectionLi
return; return;
} }
server_connections.set_active_connection(handler); server_connections.setActiveConnectionHandler(handler);
}); });
events.on("notify_destroy", server_connections.events().on("notify_active_handler_changed", event => { events.on("notify_destroy", server_connections.events().on("notify_active_handler_changed", event => {
events.fire_react("notify_active_handler", { handlerId: event.newHandlerId }); events.fire_react("notify_active_handler", { handlerId: event.newHandlerId });
@ -79,7 +79,7 @@ export function initializeConnectionListController(events: Registry<ConnectionLi
return; return;
} }
server_connections.destroy_server_connection(handler); server_connections.destroyConnectionHandler(handler);
}); });

View file

@ -45,7 +45,7 @@ class InfoController {
public getMode() : ControlBarMode { return this.mode; } public getMode() : ControlBarMode { return this.mode; }
public initialize() { public initialize() {
server_connections.all_connections().forEach(handler => this.registerGlobalHandlerEvents(handler)); server_connections.getAllConnectionHandlers().forEach(handler => this.registerGlobalHandlerEvents(handler));
const events = this.globalEvents; const events = this.globalEvents;
events.push(server_connections.events().on("notify_handler_created", event => { events.push(server_connections.events().on("notify_handler_created", event => {
@ -68,11 +68,11 @@ class InfoController {
events.push(server_connections.events().on("notify_active_handler_changed", event => this.setConnectionHandler(event.newHandler))); events.push(server_connections.events().on("notify_active_handler_changed", event => this.setConnectionHandler(event.newHandler)));
} }
this.setConnectionHandler(server_connections.active_connection()); this.setConnectionHandler(server_connections.getActiveConnectionHandler());
} }
public destroy() { public destroy() {
server_connections.all_connections().forEach(handler => this.unregisterGlobalHandlerEvents(handler)); server_connections.getAllConnectionHandlers().forEach(handler => this.unregisterGlobalHandlerEvents(handler));
this.unregisterCurrentHandlerEvents(); this.unregisterCurrentHandlerEvents();
this.globalEvents.forEach(callback => callback()); this.globalEvents.forEach(callback => callback());
@ -165,7 +165,7 @@ class InfoController {
} }
public sendConnectionState() { public sendConnectionState() {
const globallyConnected = server_connections.all_connections().findIndex(e => e.connected) !== -1; const globallyConnected = server_connections.getAllConnectionHandlers().findIndex(e => e.connected) !== -1;
const locallyConnected = this.currentHandler?.connected; const locallyConnected = this.currentHandler?.connected;
const multisession = !settings.getValue(Settings.KEY_DISABLE_MULTI_SESSION); const multisession = !settings.getValue(Settings.KEY_DISABLE_MULTI_SESSION);
@ -201,12 +201,12 @@ class InfoController {
} }
public sendAwayState() { public sendAwayState() {
const globalAwayCount = server_connections.all_connections().filter(handler => handler.isAway()).length; const globalAwayCount = server_connections.getAllConnectionHandlers().filter(handler => handler.isAway()).length;
const awayLocally = !!this.currentHandler?.isAway(); const awayLocally = !!this.currentHandler?.isAway();
this.events.fire_react("notify_away_state", { this.events.fire_react("notify_away_state", {
state: { state: {
globallyAway: globalAwayCount === server_connections.all_connections().length ? "full" : globalAwayCount > 0 ? "partial" : "none", globallyAway: globalAwayCount === server_connections.getAllConnectionHandlers().length ? "full" : globalAwayCount > 0 ? "partial" : "none",
locallyAway: awayLocally locallyAway: awayLocally
} }
}); });
@ -325,7 +325,7 @@ export function initializeControlBarController(events: Registry<ControlBarEvents
events.on("action_connection_connect", event => global_client_actions.fire("action_open_window_connect", { newTab: event.newTab })); events.on("action_connection_connect", event => global_client_actions.fire("action_open_window_connect", { newTab: event.newTab }));
events.on("action_connection_disconnect", event => { events.on("action_connection_disconnect", event => {
(event.generally ? server_connections.all_connections() : [infoHandler.getCurrentHandler()]).filter(e => !!e).forEach(connection => { (event.generally ? server_connections.getAllConnectionHandlers() : [infoHandler.getCurrentHandler()]).filter(e => !!e).forEach(connection => {
connection.disconnectFromServer().then(() => {}); connection.disconnectFromServer().then(() => {});
}); });
}); });
@ -346,7 +346,7 @@ export function initializeControlBarController(events: Registry<ControlBarEvents
if(event.away) { if(event.away) {
const setAway = message => { const setAway = message => {
const value = typeof message === "string" ? message : true; const value = typeof message === "string" ? message : true;
(event.globally ? server_connections.all_connections() : [server_connections.active_connection()]).filter(e => !!e).forEach(connection => { (event.globally ? server_connections.getAllConnectionHandlers() : [server_connections.getActiveConnectionHandler()]).filter(e => !!e).forEach(connection => {
connection.setAway(value); connection.setAway(value);
}); });
settings.setValue(Settings.KEY_CLIENT_STATE_AWAY, true); settings.setValue(Settings.KEY_CLIENT_STATE_AWAY, true);
@ -362,7 +362,7 @@ export function initializeControlBarController(events: Registry<ControlBarEvents
setAway(undefined); setAway(undefined);
} }
} else { } else {
for(const connection of event.globally ? server_connections.all_connections() : [server_connections.active_connection()]) { for(const connection of event.globally ? server_connections.getAllConnectionHandlers() : [server_connections.getActiveConnectionHandler()]) {
if(!connection) continue; if(!connection) continue;
connection.setAway(false); connection.setAway(false);

View file

@ -26,7 +26,7 @@ const VersionsRenderer = () => (
/* FIXME: Outsource this! */ /* FIXME: Outsource this! */
const RtcStatus = () => { const RtcStatus = () => {
const statusController = useMemo(() => new StatusController(new Registry<ConnectionStatusEvents>()), []); const statusController = useMemo(() => new StatusController(new Registry<ConnectionStatusEvents>()), []);
statusController.setConnectionHandler(server_connections.active_connection()); statusController.setConnectionHandler(server_connections.getActiveConnectionHandler());
server_connections.events().reactUse("notify_active_handler_changed", event => { server_connections.events().reactUse("notify_active_handler_changed", event => {
statusController.setConnectionHandler(event.newHandler); statusController.setConnectionHandler(event.newHandler);

View file

@ -20,7 +20,7 @@ import { tr } from "tc-shared/i18n/localize";
function renderConnectionItems() { function renderConnectionItems() {
const items: MenuBarEntry[] = []; const items: MenuBarEntry[] = [];
const currentConnectionConnected = !!server_connections.active_connection()?.connected; const currentConnectionConnected = !!server_connections.getActiveConnectionHandler()?.connected;
items.push({ items.push({
type: "normal", type: "normal",
label: tr("Connect to a server"), label: tr("Connect to a server"),
@ -33,15 +33,15 @@ function renderConnectionItems() {
label: tr("Disconnect from current server"), label: tr("Disconnect from current server"),
icon: ClientIcon.Disconnect, icon: ClientIcon.Disconnect,
disabled: !currentConnectionConnected, disabled: !currentConnectionConnected,
click: () => server_connections.active_connection()?.disconnectFromServer() click: () => server_connections.getActiveConnectionHandler()?.disconnectFromServer()
}); });
items.push({ items.push({
type: "normal", type: "normal",
label: tr("Disconnect from all servers"), label: tr("Disconnect from all servers"),
icon: ClientIcon.Disconnect, icon: ClientIcon.Disconnect,
disabled: server_connections.all_connections().findIndex(e => e.connected) === -1, disabled: server_connections.getAllConnectionHandlers().findIndex(e => e.connected) === -1,
click: () => server_connections.all_connections().forEach(connection => connection.disconnectFromServer()) click: () => server_connections.getAllConnectionHandlers().forEach(connection => connection.disconnectFromServer())
}); });
if(__build.target === "client") { if(__build.target === "client") {
@ -89,8 +89,8 @@ function renderBookmarkItems() {
type: "normal", type: "normal",
icon: ClientIcon.BookmarkAdd, icon: ClientIcon.BookmarkAdd,
label: tr("Add current server to bookmarks"), label: tr("Add current server to bookmarks"),
disabled: !server_connections.active_connection()?.connected, disabled: !server_connections.getActiveConnectionHandler()?.connected,
click: () => add_server_to_bookmarks(server_connections.active_connection()) click: () => add_server_to_bookmarks(server_connections.getActiveConnectionHandler())
}); });
const rootMarks = bookmarks().content; const rootMarks = bookmarks().content;
@ -105,7 +105,7 @@ function renderBookmarkItems() {
function renderPermissionItems() : MenuBarEntry[] { function renderPermissionItems() : MenuBarEntry[] {
const items: MenuBarEntry[] = []; const items: MenuBarEntry[] = [];
const currentConnectionConnected = !!server_connections.active_connection()?.connected; const currentConnectionConnected = !!server_connections.getActiveConnectionHandler()?.connected;
items.push({ items.push({
type: "normal", type: "normal",
label: tr("Server Groups"), label: tr("Server Groups"),
@ -170,7 +170,7 @@ function renderPermissionItems() : MenuBarEntry[] {
function renderToolItems() : MenuBarEntry[] { function renderToolItems() : MenuBarEntry[] {
const items: MenuBarEntry[] = []; const items: MenuBarEntry[] = [];
const currentConnectionConnected = !!server_connections.active_connection()?.connected; const currentConnectionConnected = !!server_connections.getActiveConnectionHandler()?.connected;
if(__build.target === "web") { if(__build.target === "web") {
items.push({ items.push({
type: "normal", type: "normal",
@ -341,7 +341,7 @@ class MenuBarUpdateListener {
this.generalHandlerEvents.push(bookmarkEvents.on("notify_bookmarks_updated", () => { this.generalHandlerEvents.push(bookmarkEvents.on("notify_bookmarks_updated", () => {
updateMenuBar(); updateMenuBar();
})) }))
server_connections.all_connections().forEach(handler => this.registerHandlerEvents(handler)); server_connections.getAllConnectionHandlers().forEach(handler => this.registerHandlerEvents(handler));
} }
destroy() { destroy() {

View file

@ -140,7 +140,7 @@ export namespace callbacks {
let client: ClientEntry; let client: ClientEntry;
const current_connection = server_connections.active_connection(); const current_connection = server_connections.getActiveConnectionHandler();
if(current_connection && current_connection.channelTree) { if(current_connection && current_connection.channelTree) {
if(!client && client_id) { if(!client && client_id) {
client = current_connection.channelTree.findClient(client_id); client = current_connection.channelTree.findClient(client_id);
@ -176,7 +176,7 @@ export namespace callbacks {
export function callback_context_channel(element: JQuery) { export function callback_context_channel(element: JQuery) {
const channel_id = parseInt(element.attr("channel-id") || "0"); const channel_id = parseInt(element.attr("channel-id") || "0");
const current_connection = server_connections.active_connection(); const current_connection = server_connections.getActiveConnectionHandler();
let channel: ChannelEntry; let channel: ChannelEntry;
if(current_connection && current_connection.channelTree) { if(current_connection && current_connection.channelTree) {
channel = current_connection.channelTree.findChannel(channel_id); channel = current_connection.channelTree.findChannel(channel_id);

View file

@ -410,10 +410,10 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
let connection: ConnectionHandler; let connection: ConnectionHandler;
if(event.newTab) { if(event.newTab) {
connection = server_connections.spawn_server_connection(); connection = server_connections.spawnConnectionHandler();
server_connections.set_active_connection(connection); server_connections.setActiveConnectionHandler(connection);
} else { } else {
connection = server_connections.active_connection(); connection = server_connections.getActiveConnectionHandler();
} }
if(!connection) { if(!connection) {

View file

@ -365,7 +365,7 @@ function initialize_controller(event_registry: Registry<KeyMapEvents>) {
event_registry.on("set_keymap", event => { event_registry.on("set_keymap", event => {
try { try {
keycontrol.set_key(event.action, event.key); keycontrol.setKey(event.action, event.key);
event_registry.fire_react("set_keymap_result", {status: "success", action: event.action, key: event.key}); event_registry.fire_react("set_keymap_result", {status: "success", action: event.action, key: event.key});
} catch (error) { } catch (error) {
console.warn("Failed to change key for action %s: %o", event.action, error); console.warn("Failed to change key for action %s: %o", event.action, error);

View file

@ -27,8 +27,8 @@ class FileTransferModal extends InternalModal {
this.remoteBrowseEvents.enableDebug("remote-file-browser"); this.remoteBrowseEvents.enableDebug("remote-file-browser");
this.transferInfoEvents.enableDebug("transfer-info"); this.transferInfoEvents.enableDebug("transfer-info");
initializeRemoteFileBrowserController(server_connections.active_connection(), this.remoteBrowseEvents); initializeRemoteFileBrowserController(server_connections.getActiveConnectionHandler(), this.remoteBrowseEvents);
initializeTransferInfoController(server_connections.active_connection(), this.transferInfoEvents); initializeTransferInfoController(server_connections.getActiveConnectionHandler(), this.transferInfoEvents);
} }
protected onInitialize() { protected onInitialize() {