reorganized imports a bit

This commit is contained in:
antelle 2021-04-19 23:33:16 +02:00
parent 5bbc9003f4
commit b4f93adf05
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 21 additions and 24 deletions

View File

@ -1,11 +1,6 @@
import { Launcher } from 'comp/launcher'; import { Launcher } from 'comp/launcher';
import { Logger } from 'util/logger'; import { Logger } from 'util/logger';
import { import { ProtocolHandlers, ProtocolImpl } from './protocol-impl';
ProtocolHandlers,
initProtocolImpl,
cleanupProtocolImpl,
deleteProtocolImplConnection
} from './protocol-impl';
import { RuntimeInfo } from 'const/runtime-info'; import { RuntimeInfo } from 'const/runtime-info';
import { AppSettingsModel } from 'models/app-settings-model'; import { AppSettingsModel } from 'models/app-settings-model';
import { Features } from 'util/features'; import { Features } from 'util/features';
@ -40,7 +35,7 @@ const BrowserExtensionConnector = {
init(appModel) { init(appModel) {
const sendEvent = this.sendEvent.bind(this); const sendEvent = this.sendEvent.bind(this);
initProtocolImpl({ appModel, logger, sendEvent }); ProtocolImpl.init({ appModel, logger, sendEvent });
this.browserWindowMessage = this.browserWindowMessage.bind(this); this.browserWindowMessage = this.browserWindowMessage.bind(this);
@ -75,7 +70,7 @@ const BrowserExtensionConnector = {
this.stopWebMessageListener(); this.stopWebMessageListener();
} }
cleanupProtocolImpl(); ProtocolImpl.cleanup();
connections.clear(); connections.clear();
logger.info('Stopped'); logger.info('Stopped');
@ -198,7 +193,7 @@ const BrowserExtensionConnector = {
socketClosed(socketId) { socketClosed(socketId) {
connections.delete(socketId); connections.delete(socketId);
deleteProtocolImplConnection(socketId); ProtocolImpl.deleteConnection(socketId);
}, },
async socketRequest(socketId, request) { async socketRequest(socketId, request) {

View File

@ -29,25 +29,27 @@ let logger;
let appModel; let appModel;
let sendEvent; let sendEvent;
function initProtocolImpl(vars) { const ProtocolImpl = {
appModel = vars.appModel; init(vars) {
logger = vars.logger; appModel = vars.appModel;
sendEvent = vars.sendEvent; logger = vars.logger;
sendEvent = vars.sendEvent;
setupListeners(); setupListeners();
} },
function cleanupProtocolImpl() { cleanup() {
connectedClients.clear(); connectedClients.clear();
} },
function deleteProtocolImplConnection(connectionId) { deleteConnection(connectionId) {
for (const client of connectedClients.values()) { for (const client of connectedClients.values()) {
if (client.connection.connectionId === connectionId) { if (client.connection.connectionId === connectionId) {
connectedClients.delete(client); connectedClients.delete(client);
}
} }
} }
} };
function setupListeners() { function setupListeners() {
Events.on('file-opened', () => { Events.on('file-opened', () => {
@ -406,4 +408,4 @@ const ProtocolHandlers = {
} }
}; };
export { ProtocolHandlers, initProtocolImpl, cleanupProtocolImpl, deleteProtocolImplConnection }; export { ProtocolHandlers, ProtocolImpl };