diff --git a/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts b/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts index 0a56d36b66..1817e49b57 100644 --- a/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts +++ b/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts @@ -4,6 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import createSyncBoxInjectable from "../../sync-box/create-sync-box.injectable"; +import type { UpdateChannel } from "../../../main/update-app/update-channels"; const discoveredUpdateVersionInjectable = getInjectable({ id: "discovered-update-version", @@ -11,7 +12,9 @@ const discoveredUpdateVersionInjectable = getInjectable({ instantiate: (di) => { const createSyncBox = di.inject(createSyncBoxInjectable); - return createSyncBox("discovered-update-version"); + return createSyncBox<{ version: string; updateChannel: UpdateChannel }>( + "discovered-update-version", + ); }, }); diff --git a/src/common/application-update/progress-of-update-download/progress-of-update-download.injectable.ts b/src/common/application-update/progress-of-update-download/progress-of-update-download.injectable.ts index 36fb0171f6..9aa2f965d9 100644 --- a/src/common/application-update/progress-of-update-download/progress-of-update-download.injectable.ts +++ b/src/common/application-update/progress-of-update-download/progress-of-update-download.injectable.ts @@ -11,7 +11,7 @@ const progressOfUpdateDownloadInjectable = getInjectable({ instantiate: (di) => { const createSyncBox = di.inject(createSyncBoxInjectable); - return createSyncBox("progress-of-update-download"); + return createSyncBox("progress-of-update-download"); }, }); diff --git a/src/common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable.ts b/src/common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable.ts index b19ba47345..ab829cba7a 100644 --- a/src/common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable.ts +++ b/src/common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable.ts @@ -11,7 +11,7 @@ const updateIsBeingDownloadedInjectable = getInjectable({ instantiate: (di) => { const createSyncBox = di.inject(createSyncBoxInjectable); - return createSyncBox("update-is-being-downloaded"); + return createSyncBox("update-is-being-downloaded"); }, }); diff --git a/src/common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable.ts b/src/common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable.ts index 3ab1439cd0..45d8b37369 100644 --- a/src/common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable.ts +++ b/src/common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable.ts @@ -11,7 +11,7 @@ const updatesAreBeingDiscoveredInjectable = getInjectable({ instantiate: (di) => { const createSyncBox = di.inject(createSyncBoxInjectable); - return createSyncBox("updates-are-being-discovered"); + return createSyncBox("updates-are-being-discovered"); }, }); diff --git a/src/common/channel/channel-injection-token.ts b/src/common/channel/channel-injection-token.ts index 1cc73f0841..0b346b2341 100644 --- a/src/common/channel/channel-injection-token.ts +++ b/src/common/channel/channel-injection-token.ts @@ -4,10 +4,11 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; -export interface Channel { +export interface Channel { id: string; + _template?: TInstance; } -export const channelInjectionToken = getInjectionToken({ +export const channelInjectionToken = getInjectionToken>({ id: "channel", }); diff --git a/src/common/channel/channel-listener-injection-token.ts b/src/common/channel/channel-listener-injection-token.ts index 6ce3268663..db7672f906 100644 --- a/src/common/channel/channel-listener-injection-token.ts +++ b/src/common/channel/channel-listener-injection-token.ts @@ -3,13 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectionToken } from "@ogre-tools/injectable"; +import type { Channel } from "./channel-injection-token"; -export interface ChannelListener { - channel: any; - handler: (value: any) => void; +export interface ChannelListener> { + channel: TChannel; + handler: (value: TChannel["_template"]) => void; } -export const channelListenerInjectionToken = getInjectionToken( +export const channelListenerInjectionToken = getInjectionToken>>( { id: "channel-listener", }, diff --git a/src/common/channel/channel.test.ts b/src/common/channel/channel.test.ts index d55dda1d4f..508cec128b 100644 --- a/src/common/channel/channel.test.ts +++ b/src/common/channel/channel.test.ts @@ -6,6 +6,7 @@ import type { DiContainer } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable"; import type { LensWindow } from "../../main/start-main-application/lens-window/application-window/lens-window-injection-token"; import { lensWindowInjectionToken } from "../../main/start-main-application/lens-window/application-window/lens-window-injection-token"; +import type { SendToAgnosticChannel } from "./send-to-agnostic-channel-injection-token"; import { sendToAgnosticChannelInjectionToken } from "./send-to-agnostic-channel-injection-token"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { channelListenerInjectionToken } from "./channel-listener-injection-token"; @@ -13,12 +14,14 @@ import createLensWindowInjectable from "../../main/start-main-application/lens-w import type { Channel } from "./channel-injection-token"; import { channelInjectionToken } from "./channel-injection-token"; +type TestChannel = Channel; + describe("channel", () => { describe("messaging from main to renderer, given listener for channel in a window and application has started", () => { - let testChannel: Channel; + let testChannel: TestChannel; let testListenerInWindowMock: jest.Mock; let mainDi: DiContainer; - let sendToAgnosticChannel: (channel: Channel, message: any) => void; + let sendToAgnosticChannel: SendToAgnosticChannel; beforeEach(async () => { const applicationBuilder = getApplicationBuilder(); @@ -96,11 +99,11 @@ describe("channel", () => { }); describe("messaging from renderer to main, given listener for channel in a main and application has started", () => { - let testChannel: Channel; + let testChannel: TestChannel; let testListenerInMainMock: jest.Mock; let rendererDi: DiContainer; let mainDi: DiContainer; - let sendToAgnosticChannel: (channel: Channel, message: any) => void; + let sendToAgnosticChannel: SendToAgnosticChannel; beforeEach(async () => { const applicationBuilder = getApplicationBuilder(); diff --git a/src/common/channel/enlist-channel-listener-injection-token.ts b/src/common/channel/enlist-channel-listener-injection-token.ts index 7f02254826..6b72ca4ac1 100644 --- a/src/common/channel/enlist-channel-listener-injection-token.ts +++ b/src/common/channel/enlist-channel-listener-injection-token.ts @@ -3,9 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectionToken } from "@ogre-tools/injectable"; +import type { Channel } from "./channel-injection-token"; -export const enlistChannelListenerInjectionToken = getInjectionToken< - (channel: any, handler: any) => () => void - >({ - id: "enlist-channel-listener", - }); +export type EnlistChannelListener = >( + channel: TChannel, + handler: (value: TChannel["_template"]) => void +) => () => void; + +export const enlistChannelListenerInjectionToken = + getInjectionToken({ + id: "enlist-channel-listener", + }); diff --git a/src/common/channel/send-to-agnostic-channel-injection-token.ts b/src/common/channel/send-to-agnostic-channel-injection-token.ts index 8322d2b39e..901e51b94b 100644 --- a/src/common/channel/send-to-agnostic-channel-injection-token.ts +++ b/src/common/channel/send-to-agnostic-channel-injection-token.ts @@ -5,6 +5,12 @@ import { getInjectionToken } from "@ogre-tools/injectable"; import type { Channel } from "./channel-injection-token"; -export const sendToAgnosticChannelInjectionToken = getInjectionToken<(channel: Channel, message: any) => void>({ - id: "send-to-agnostic-channel", -}); +export type SendToAgnosticChannel = >( + channel: TChannel, + message: TChannel["_template"] +) => void; + +export const sendToAgnosticChannelInjectionToken = + getInjectionToken({ + id: "send-to-agnostic-channel", + }); diff --git a/src/common/sync-box/create-sync-box.injectable.ts b/src/common/sync-box/create-sync-box.injectable.ts index 752d7e4fd1..914b1e2b41 100644 --- a/src/common/sync-box/create-sync-box.injectable.ts +++ b/src/common/sync-box/create-sync-box.injectable.ts @@ -17,7 +17,7 @@ const createSyncBoxInjectable = getInjectable({ const sendToAgnosticChannel = di.inject(sendToAgnosticChannelInjectionToken); const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id); - return (id: string): SyncBox => { + return (id: string): SyncBox => { const state = getSyncBoxState(id); return { @@ -37,7 +37,6 @@ const createSyncBoxInjectable = getInjectable({ export default createSyncBoxInjectable; - export interface SyncBox { id: string; value: IComputedValue; diff --git a/src/common/sync-box/sync-box-channel-listener.injectable.ts b/src/common/sync-box/sync-box-channel-listener.injectable.ts index 899d19b76a..8019f93046 100644 --- a/src/common/sync-box/sync-box-channel-listener.injectable.ts +++ b/src/common/sync-box/sync-box-channel-listener.injectable.ts @@ -3,14 +3,16 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { SyncBoxChannel } from "./sync-box-channel.injectable"; import syncBoxChannelInjectable from "./sync-box-channel.injectable"; +import type { ChannelListener } from "../channel/channel-listener-injection-token"; import { channelListenerInjectionToken } from "../channel/channel-listener-injection-token"; import syncBoxStateInjectable from "./sync-box-state.injectable"; const syncBoxChannelListenerInjectable = getInjectable({ id: "sync-box-channel-listener", - instantiate: (di) => { + instantiate: (di): ChannelListener => { const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id); return { diff --git a/src/common/sync-box/sync-box-channel.injectable.ts b/src/common/sync-box/sync-box-channel.injectable.ts index e167a55ac1..7b9262f607 100644 --- a/src/common/sync-box/sync-box-channel.injectable.ts +++ b/src/common/sync-box/sync-box-channel.injectable.ts @@ -3,12 +3,15 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { Channel } from "../channel/channel-injection-token"; import { channelInjectionToken } from "../channel/channel-injection-token"; +export type SyncBoxChannel = Channel<{ id: string; value: unknown }>; + const syncBoxChannelInjectable = getInjectable({ id: "sync-box-channel", - instantiate: () => ({ + instantiate: (): SyncBoxChannel => ({ id: "sync-box-channel", }), diff --git a/src/common/sync-box/sync-box.test.ts b/src/common/sync-box/sync-box.test.ts index 14f1473efc..ea97fbc967 100644 --- a/src/common/sync-box/sync-box.test.ts +++ b/src/common/sync-box/sync-box.test.ts @@ -24,7 +24,7 @@ describe("sync-box", () => { instantiate: (di) => { const createSyncBox = di.inject(createSyncBoxInjectable); - return createSyncBox("some-state"); + return createSyncBox("some-state"); }, }); diff --git a/src/main/channel/channel-listeners/enlist-channel-listener.injectable.ts b/src/main/channel/channel-listeners/enlist-channel-listener.injectable.ts index a2ffac1c73..87ddf28860 100644 --- a/src/main/channel/channel-listeners/enlist-channel-listener.injectable.ts +++ b/src/main/channel/channel-listeners/enlist-channel-listener.injectable.ts @@ -13,7 +13,7 @@ const enlistChannelListenerInjectable = getInjectable({ instantiate: (di) => { const ipcMain = di.inject(ipcMainInjectable); - return (channel: any, handler: any) => { + return (channel, handler) => { const nativeCallback = (_: IpcMainEvent, message: unknown) => handler(message); diff --git a/src/renderer/channel/channel-listeners/enlist-channel-listener.injectable.ts b/src/renderer/channel/channel-listeners/enlist-channel-listener.injectable.ts index ad6dcc8749..0cc8a5c854 100644 --- a/src/renderer/channel/channel-listeners/enlist-channel-listener.injectable.ts +++ b/src/renderer/channel/channel-listeners/enlist-channel-listener.injectable.ts @@ -13,7 +13,7 @@ const enlistChannelListenerInjectable = getInjectable({ instantiate: (di) => { const ipcRenderer = di.inject(ipcRendererInjectable); - return (channel: any, handler: any) => { + return (channel, handler) => { const nativeCallback = (_: IpcRendererEvent, message: unknown) => handler(message);