Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address linter issues
Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
  • Loading branch information
tsmaeder committed Dec 13, 2023
commit b09f6af69e80e4cafd9d1c2b6b5f50daa60611fa
4 changes: 2 additions & 2 deletions packages/core/src/browser/messaging/connection-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { Channel, Event } from "../../common";
import { Channel, Event } from '../../common';

export const ConnectionSource = Symbol('ConnectionSource');

Expand All @@ -23,4 +23,4 @@ export const ConnectionSource = Symbol('ConnectionSource');
*/
export interface ConnectionSource {
onConnectionDidOpen: Event<Channel>;
}
}
9 changes: 4 additions & 5 deletions packages/core/src/browser/messaging/frontend-id-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from "inversify";
import { generateUuid } from "../../common/uuid";
import { injectable } from 'inversify';
import { generateUuid } from '../../common/uuid';

export const FrontendIdProvider = Symbol('FrontendIdProvider');

/**
* A FronendIdProvider computes an id for an instance of the front end that may be reconnected to a back end
* A FronendIdProvider computes an id for an instance of the front end that may be reconnected to a back end
* connection context.
*/
export interface FrontendIdProvider {
Expand All @@ -34,5 +34,4 @@ export class BrowserFrontendIdProvider implements FrontendIdProvider {
getId(): string {
return this.id;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import { WebSocketConnectionProvider } from './ws-connection-provider';
const backendServiceProvider = Symbol('backendServiceProvider');

export const messagingFrontendModule = new ContainerModule(bind => {
bind(ConnectionCloseService).toDynamicValue(ctx => {
return WebSocketConnectionProvider.createProxy(ctx.container, connectionCloseServicePath);
}).inSingletonScope();
bind(ConnectionCloseService).toDynamicValue(ctx => WebSocketConnectionProvider.createProxy(ctx.container, connectionCloseServicePath)).inSingletonScope();
bind(BrowserFrontendIdProvider).toSelf().inSingletonScope();
bind(FrontendIdProvider).toService(BrowserFrontendIdProvider);
bind(WebsocketConnectionSource).toSelf().inSingletonScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { ChannelMultiplexer } from '../../common/message-rpc/channel';
import { Deferred } from '../../common/promise-util';
import { ConnectionSource } from './connection-source';


export const LocalConnectionProvider = Symbol('LocalConnectionProvider');
export const RemoteConnectionProvider = Symbol('RemoteConnectionProvider');

Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/browser/messaging/ws-connection-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ export class WebSocketConnectionProvider {
createProxy<T extends object>(path: string, factory: RpcProxyFactory<T>): RpcProxy<T> {
return this.remoteConnectionProvider.createProxy(path, factory);
}


}
29 changes: 15 additions & 14 deletions packages/core/src/browser/messaging/ws-connection-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { AbstractChannel, Channel, Disposable, DisposableCollection, Emitter, Event, servicesPath } from "../../common";
import { ConnectionSource } from "./connection-source";
import { Socket, io } from "socket.io-client";
import { Endpoint } from "../endpoint";
import { ForwardingChannel } from "../../common/message-rpc/channel";
import { Uint8ArrayReadBuffer, Uint8ArrayWriteBuffer } from "../../common/message-rpc/uint8-array-message-buffer";
import { inject, injectable } from "inversify";
import { FrontendIdProvider } from "./frontend-id-provider";
import { FrontendApplicationConfigProvider } from "../frontend-application-config-provider";
import { SocketWriteBuffer } from "../../common/messaging/socket-write-buffer";
import { ConnectionManagementMessages } from "../../common/messaging/connection-management";
import { AbstractChannel, Channel, Disposable, DisposableCollection, Emitter, Event, servicesPath } from '../../common';
import { ConnectionSource } from './connection-source';
import { Socket, io } from 'socket.io-client';
import { Endpoint } from '../endpoint';
import { ForwardingChannel } from '../../common/message-rpc/channel';
import { Uint8ArrayReadBuffer, Uint8ArrayWriteBuffer } from '../../common/message-rpc/uint8-array-message-buffer';
import { inject, injectable } from 'inversify';
import { FrontendIdProvider } from './frontend-id-provider';
import { FrontendApplicationConfigProvider } from '../frontend-application-config-provider';
import { SocketWriteBuffer } from '../../common/messaging/socket-write-buffer';
import { ConnectionManagementMessages } from '../../common/messaging/connection-management';

@injectable()
export class WebsocketConnectionSource implements ConnectionSource {
Expand Down Expand Up @@ -74,7 +74,7 @@ export class WebsocketConnectionSource implements ConnectionSource {

this._socket.on('disconnect', () => {
this.onSocketDidCloseEmitter.fire();
})
});

this._socket.on('error', reason => {
if (this.currentChannel) {
Expand All @@ -83,7 +83,7 @@ export class WebsocketConnectionSource implements ConnectionSource {
});
}

protected handleSocketConnected() {
protected handleSocketConnected(): void {
if (this.currentChannel) {
const reconnectListener = (hasConnection: boolean) => {
this._socket.off(ConnectionManagementMessages.RECONNECT, reconnectListener);
Expand Down Expand Up @@ -122,6 +122,7 @@ export class WebsocketConnectionSource implements ConnectionSource {
protected createChannel(): AbstractChannel {
const toDispose = new DisposableCollection();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const messageHandler = (data: any) => {
this.onIncomingMessageActivityEmitter.fire();
if (this.currentChannel) {
Expand Down Expand Up @@ -202,4 +203,4 @@ export class WebsocketConnectionSource implements ConnectionSource {
}
return pathname + 'socket.io';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export namespace ConnectionManagementMessages {
*/
export interface ConnectionCloseService {
markForClose(frontEndId: string): Promise<void>;
}
}
6 changes: 3 additions & 3 deletions packages/core/src/common/messaging/socket-write-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SocketWriteBuffer {
private disconnectedBuffer: Uint8Array | undefined;
private bufferWritePosition = 0;

buffer(data: Uint8Array) {
buffer(data: Uint8Array): void {
this.ensureWriteBuffer(data.byteLength);
this.disconnectedBuffer?.set(data, this.bufferWritePosition);
this.bufferWritePosition += data.byteLength;
Expand All @@ -44,7 +44,7 @@ export class SocketWriteBuffer {
}
}

flush(socket: WebSocket) {
flush(socket: WebSocket): void {
if (this.disconnectedBuffer) {
socket.send(this.disconnectedBuffer.slice(0, this.bufferWritePosition));
this.disconnectedBuffer = undefined;
Expand All @@ -54,4 +54,4 @@ export class SocketWriteBuffer {
drain(): void {
this.disconnectedBuffer = undefined;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from "inversify";
import { FrontendIdProvider } from "../../browser/messaging/frontend-id-provider";
import { injectable } from 'inversify';
import { FrontendIdProvider } from '../../browser/messaging/frontend-id-provider';

@injectable()
export class ElectronFrontendIdProvider implements FrontendIdProvider {
getId(): string {
return window.electronTheiaCore.WindowMetadata.webcontentId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ export namespace ElectronIpcConnectionProvider {
export function createProxy<T extends object>(container: interfaces.Container, path: string, arg?: object): RpcProxy<T> {
return container.get<ServiceConnectionProvider>(ElectronMainConnectionProvider).createProxy<T>(path, arg);
}


}

@injectable()
export class ElectronIpcConnectionSource implements ConnectionSource, FrontendApplicationContribution {
protected readonly onConnectionDidOpenEmitter: Emitter<Channel> = new Emitter();
onConnectionDidOpen: Event<Channel> = this.onConnectionDidOpenEmitter.event;


onStart(): MaybePromise<void> {
const channel = new ElectronIpcRendererChannel();
this.onConnectionDidOpenEmitter.fire(channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const backendServiceProvider = Symbol('backendServiceProvider2');
const localServiceProvider = Symbol('localServiceProvider');

export const messagingFrontendModule = new ContainerModule(bind => {
bind(ConnectionCloseService).toDynamicValue(ctx => {
return WebSocketConnectionProvider.createProxy(ctx.container, connectionCloseServicePath);
}).inSingletonScope();
bind(ConnectionCloseService).toDynamicValue(ctx => WebSocketConnectionProvider.createProxy(ctx.container, connectionCloseServicePath)).inSingletonScope();
bind(ElectronWebSocketConnectionSource).toSelf().inSingletonScope();
bind(WebsocketConnectionSource).toService(ElectronWebSocketConnectionSource);
bind(ElectronIpcConnectionSource).toSelf().inSingletonScope();
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/electron-browser/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
CHANNEL_ON_WINDOW_EVENT, CHANNEL_GET_ZOOM_LEVEL, CHANNEL_SET_ZOOM_LEVEL, CHANNEL_IS_FULL_SCREENABLE, CHANNEL_TOGGLE_FULL_SCREEN,
CHANNEL_IS_FULL_SCREEN, CHANNEL_SET_MENU_BAR_VISIBLE, CHANNEL_REQUEST_CLOSE, CHANNEL_SET_TITLE_STYLE, CHANNEL_RESTART,
CHANNEL_REQUEST_RELOAD, CHANNEL_APP_STATE_CHANGED, CHANNEL_SHOW_ITEM_IN_FOLDER, CHANNEL_READ_CLIPBOARD, CHANNEL_WRITE_CLIPBOARD,
CHANNEL_KEYBOARD_LAYOUT_CHANGED, CHANNEL_IPC_CONNECTION, InternalMenuDto, CHANNEL_REQUEST_SECONDARY_CLOSE, CHANNEL_SET_BACKGROUND_COLOR, CHANNEL_WC_METADATA, CHANNEL_ABOUT_TO_CLOSE
CHANNEL_KEYBOARD_LAYOUT_CHANGED, CHANNEL_IPC_CONNECTION, InternalMenuDto, CHANNEL_REQUEST_SECONDARY_CLOSE, CHANNEL_SET_BACKGROUND_COLOR,
CHANNEL_WC_METADATA, CHANNEL_ABOUT_TO_CLOSE
} from '../electron-common/electron-api';

// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down Expand Up @@ -125,7 +126,7 @@ const api: TheiaCoreAPI = {
const h = (event: Electron.IpcRendererEvent, replyChannel: string) => {
handler();
event.sender.send(replyChannel);
}
};

ipcRenderer.on(CHANNEL_ABOUT_TO_CLOSE, h);
return Disposable.create(() => ipcRenderer.off(CHANNEL_ABOUT_TO_CLOSE, h));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/electron-common/electron-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const CHANNEL_MINIMIZE = 'Minimize';
export const CHANNEL_MAXIMIZE = 'Maximize';
export const CHANNEL_IS_MAXIMIZED = 'IsMaximized';

export const CHANNEL_ABOUT_TO_CLOSE = "AboutToClose";
export const CHANNEL_ABOUT_TO_CLOSE = 'AboutToClose';

export const CHANNEL_UNMAXIMIZE = 'UnMaximize';
export const CHANNEL_ON_WINDOW_EVENT = 'OnWindowEvent';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
TheiaRendererAPI.onIpcData((sender, data) => this.handleIpcEvent(sender, data));
}


// eslint-disable-next-line @typescript-eslint/no-explicit-any
ipcChannel(spec: string, callback: (params: any, channel: Channel) => void): void {
this.channelHandlers.push(spec, callback);
Expand Down Expand Up @@ -99,7 +98,7 @@ export class ElectronMessagingContribution implements ElectronMainApplicationCon
return mainChannel;
}

protected deleteChannel(senderId: number, reason: string) {
protected deleteChannel(senderId: number, reason: string): void {
const channel = this.openChannels.get(senderId);
if (channel) {
this.openChannels.delete(senderId);
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/node/messaging/messaging-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export const messagingBackendModule = new ContainerModule(bind => {

bind(ConnectionHandler).toDynamicValue(context => {
const connectionService = context.container.get<WebsocketFrontendConnectionService>(FrontendConnectionService);
return new RpcConnectionHandler<object>(connectionCloseServicePath, () => {
return {
markForClose: (channelId: string) => {
connectionService.markForClose(channelId);
}
};
});
return new RpcConnectionHandler<object>(connectionCloseServicePath, () => ({
markForClose: (channelId: string) => {
connectionService.markForClose(channelId);
}
}));
}).inSingletonScope();
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class WebsocketFrontendConnectionService implements FrontendConnectionSer
}

protected async handleConnection(socket: Socket, channelCreatedHandler: (channel: Channel) => void): Promise<void> {
// eslint-disable-next-line prefer-const
let reconnectListener: (frontEndId: string) => void;
const initialConnectListener = (frontEndId: string) => {
socket.off(ConnectionManagementMessages.INITIAL_CONNECT, initialConnectListener);
Expand Down Expand Up @@ -119,7 +120,7 @@ export class WebsocketFrontendConnectionService implements FrontendConnectionSer
return channel;
}

markForClose(channelId: string) {
markForClose(channelId: string): void {
this.channelsMarkedForClose.add(channelId);
}
}
Expand All @@ -140,20 +141,21 @@ class ReconnectableSocketChannel extends AbstractChannel {
}));
socket.on('error', errorHandler);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const dataListener = (data: any) => {
// In the browser context socketIO receives binary messages as ArrayBuffers.
// So we have to convert them to a Uint8Array before delegating the message to the read buffer.
const buffer = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
this.onMessageEmitter.fire(() => new Uint8ArrayReadBuffer(buffer));
}
};
this.disposables.push(Disposable.create(() => {
socket.off('message', dataListener);
}));
socket.on('message', dataListener);
this.socketBuffer.flush(socket);
}

disconnect() {
disconnect(): void {
this.disposables.dispose();
this.socket = undefined;
}
Expand Down