mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b79f906ad5
commit
7cda0792b7
@ -4,16 +4,31 @@
|
||||
*/
|
||||
import { ipcMain } from "electron";
|
||||
import { IpcPrefix, IpcRegistrar } from "./ipc-registrar";
|
||||
import { Disposers, lensExtensionDependencies } from "../lens-extension";
|
||||
import { Disposers } from "../lens-extension";
|
||||
import type { LensMainExtension } from "../lens-main-extension";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import { once } from "lodash";
|
||||
import { ipcMainHandle } from "../../common/ipc";
|
||||
import type { Logger } from "../common-api";
|
||||
import { Environments, getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
readonly logger: Logger;
|
||||
}
|
||||
|
||||
export abstract class IpcMain extends IpcRegistrar {
|
||||
private readonly dependencies: Dependencies;
|
||||
|
||||
constructor(extension: LensMainExtension) {
|
||||
super(extension);
|
||||
|
||||
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.main);
|
||||
|
||||
this.dependencies = {
|
||||
logger: di.inject(loggerInjectable),
|
||||
};
|
||||
|
||||
// Call the static method on the bottom child class.
|
||||
extension[Disposers].push(() => (this.constructor as typeof IpcMain).resetInstance());
|
||||
}
|
||||
@ -27,12 +42,12 @@ export abstract class IpcMain extends IpcRegistrar {
|
||||
listen(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => any): Disposer {
|
||||
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
||||
const cleanup = once(() => {
|
||||
this.extension[lensExtensionDependencies].logger.debug(`[IPC-RENDERER]: removing extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.dependencies.logger.debug(`[IPC-RENDERER]: removing extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
|
||||
return ipcMain.removeListener(prefixedChannel, listener);
|
||||
});
|
||||
|
||||
this.extension[lensExtensionDependencies].logger.debug(`[IPC-RENDERER]: adding extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.dependencies.logger.debug(`[IPC-RENDERER]: adding extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
ipcMain.addListener(prefixedChannel, listener);
|
||||
this.extension[Disposers].push(cleanup);
|
||||
|
||||
@ -47,10 +62,10 @@ export abstract class IpcMain extends IpcRegistrar {
|
||||
handle(channel: string, handler: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any): void {
|
||||
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
||||
|
||||
this.extension[lensExtensionDependencies].logger.debug(`[IPC-RENDERER]: adding extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.dependencies.logger.debug(`[IPC-RENDERER]: adding extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
ipcMainHandle(prefixedChannel, handler);
|
||||
this.extension[Disposers].push(() => {
|
||||
this.extension[lensExtensionDependencies].logger.debug(`[IPC-RENDERER]: removing extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.dependencies.logger.debug(`[IPC-RENDERER]: removing extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
|
||||
return ipcMain.removeHandler(prefixedChannel);
|
||||
});
|
||||
|
||||
@ -11,13 +11,13 @@ import type { LensProtocolRouterMain } from "../lens-protocol-router-main/lens-p
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import lensProtocolRouterMainInjectable from "../lens-protocol-router-main/lens-protocol-router-main.injectable";
|
||||
import extensionsStoreInjectable from "../../../extensions/extensions-store/extensions-store.injectable";
|
||||
import { LensExtension } from "../../../extensions/lens-extension";
|
||||
import type { LensExtensionId } from "../../../extensions/lens-extension";
|
||||
import type { LensExtension, LensExtensionId } from "../../../extensions/lens-extension";
|
||||
import type { ObservableMap } from "mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import extensionInstancesInjectable from "../../../extensions/extension-loader/extension-instances.injectable";
|
||||
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable";
|
||||
import { LensMainExtension } from "../../../extensions/lens-main-extension";
|
||||
|
||||
function throwIfDefined(val: any): void {
|
||||
if (val != null) {
|
||||
@ -77,7 +77,7 @@ describe("protocol router tests", () => {
|
||||
|
||||
it("should broadcast external route when called with valid host", async () => {
|
||||
const extId = uuid.v4();
|
||||
const ext = new LensExtension({
|
||||
const ext = new LensMainExtension({
|
||||
id: extId,
|
||||
manifestPath: "/foo/bar",
|
||||
manifest: {
|
||||
@ -143,7 +143,7 @@ describe("protocol router tests", () => {
|
||||
let called: any = 0;
|
||||
|
||||
const extId = uuid.v4();
|
||||
const ext = new LensExtension({
|
||||
const ext = new LensMainExtension({
|
||||
id: extId,
|
||||
manifestPath: "/foo/bar",
|
||||
manifest: {
|
||||
@ -184,7 +184,7 @@ describe("protocol router tests", () => {
|
||||
|
||||
{
|
||||
const extId = uuid.v4();
|
||||
const ext = new LensExtension({
|
||||
const ext = new LensMainExtension({
|
||||
id: extId,
|
||||
manifestPath: "/foo/bar",
|
||||
manifest: {
|
||||
@ -210,7 +210,7 @@ describe("protocol router tests", () => {
|
||||
|
||||
{
|
||||
const extId = uuid.v4();
|
||||
const ext = new LensExtension({
|
||||
const ext = new LensMainExtension({
|
||||
id: extId,
|
||||
manifestPath: "/foo/bar",
|
||||
manifest: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user