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 { ipcMain } from "electron";
|
||||||
import { IpcPrefix, IpcRegistrar } from "./ipc-registrar";
|
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 { LensMainExtension } from "../lens-main-extension";
|
||||||
import type { Disposer } from "../../common/utils";
|
import type { Disposer } from "../../common/utils";
|
||||||
import { once } from "lodash";
|
import { once } from "lodash";
|
||||||
import { ipcMainHandle } from "../../common/ipc";
|
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 {
|
export abstract class IpcMain extends IpcRegistrar {
|
||||||
|
private readonly dependencies: Dependencies;
|
||||||
|
|
||||||
constructor(extension: LensMainExtension) {
|
constructor(extension: LensMainExtension) {
|
||||||
super(extension);
|
super(extension);
|
||||||
|
|
||||||
|
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.main);
|
||||||
|
|
||||||
|
this.dependencies = {
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
|
};
|
||||||
|
|
||||||
// Call the static method on the bottom child class.
|
// Call the static method on the bottom child class.
|
||||||
extension[Disposers].push(() => (this.constructor as typeof IpcMain).resetInstance());
|
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 {
|
listen(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => any): Disposer {
|
||||||
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
||||||
const cleanup = once(() => {
|
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);
|
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);
|
ipcMain.addListener(prefixedChannel, listener);
|
||||||
this.extension[Disposers].push(cleanup);
|
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 {
|
handle(channel: string, handler: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any): void {
|
||||||
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
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);
|
ipcMainHandle(prefixedChannel, handler);
|
||||||
this.extension[Disposers].push(() => {
|
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);
|
return ipcMain.removeHandler(prefixedChannel);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,13 +11,13 @@ import type { LensProtocolRouterMain } from "../lens-protocol-router-main/lens-p
|
|||||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||||
import lensProtocolRouterMainInjectable from "../lens-protocol-router-main/lens-protocol-router-main.injectable";
|
import lensProtocolRouterMainInjectable from "../lens-protocol-router-main/lens-protocol-router-main.injectable";
|
||||||
import extensionsStoreInjectable from "../../../extensions/extensions-store/extensions-store.injectable";
|
import extensionsStoreInjectable from "../../../extensions/extensions-store/extensions-store.injectable";
|
||||||
import { LensExtension } from "../../../extensions/lens-extension";
|
import type { LensExtension, LensExtensionId } from "../../../extensions/lens-extension";
|
||||||
import type { LensExtensionId } from "../../../extensions/lens-extension";
|
|
||||||
import type { ObservableMap } from "mobx";
|
import type { ObservableMap } from "mobx";
|
||||||
import { runInAction } from "mobx";
|
import { runInAction } from "mobx";
|
||||||
import extensionInstancesInjectable from "../../../extensions/extension-loader/extension-instances.injectable";
|
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 directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable";
|
import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable";
|
||||||
|
import { LensMainExtension } from "../../../extensions/lens-main-extension";
|
||||||
|
|
||||||
function throwIfDefined(val: any): void {
|
function throwIfDefined(val: any): void {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
@ -77,7 +77,7 @@ describe("protocol router tests", () => {
|
|||||||
|
|
||||||
it("should broadcast external route when called with valid host", async () => {
|
it("should broadcast external route when called with valid host", async () => {
|
||||||
const extId = uuid.v4();
|
const extId = uuid.v4();
|
||||||
const ext = new LensExtension({
|
const ext = new LensMainExtension({
|
||||||
id: extId,
|
id: extId,
|
||||||
manifestPath: "/foo/bar",
|
manifestPath: "/foo/bar",
|
||||||
manifest: {
|
manifest: {
|
||||||
@ -143,7 +143,7 @@ describe("protocol router tests", () => {
|
|||||||
let called: any = 0;
|
let called: any = 0;
|
||||||
|
|
||||||
const extId = uuid.v4();
|
const extId = uuid.v4();
|
||||||
const ext = new LensExtension({
|
const ext = new LensMainExtension({
|
||||||
id: extId,
|
id: extId,
|
||||||
manifestPath: "/foo/bar",
|
manifestPath: "/foo/bar",
|
||||||
manifest: {
|
manifest: {
|
||||||
@ -184,7 +184,7 @@ describe("protocol router tests", () => {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const extId = uuid.v4();
|
const extId = uuid.v4();
|
||||||
const ext = new LensExtension({
|
const ext = new LensMainExtension({
|
||||||
id: extId,
|
id: extId,
|
||||||
manifestPath: "/foo/bar",
|
manifestPath: "/foo/bar",
|
||||||
manifest: {
|
manifest: {
|
||||||
@ -210,7 +210,7 @@ describe("protocol router tests", () => {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const extId = uuid.v4();
|
const extId = uuid.v4();
|
||||||
const ext = new LensExtension({
|
const ext = new LensMainExtension({
|
||||||
id: extId,
|
id: extId,
|
||||||
manifestPath: "/foo/bar",
|
manifestPath: "/foo/bar",
|
||||||
manifest: {
|
manifest: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user