diff --git a/desktop/src/app/preload.ts b/desktop/src/app/preload.ts index 74bcb048..d406fbed 100644 --- a/desktop/src/app/preload.ts +++ b/desktop/src/app/preload.ts @@ -1,8 +1,11 @@ import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron"; +import type { WorkAdventureDesktopApi } from "./types"; -contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", { +const api: WorkAdventureDesktopApi = { desktop: true, notify: (txt: string) => ipcRenderer.send("app:notify", txt), onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) => ipcRenderer.on("app:on-muted-key-press", callback), -}); +}; + +contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", api); diff --git a/desktop/src/app/types.ts b/desktop/src/app/types.ts new file mode 100644 index 00000000..a76f834f --- /dev/null +++ b/desktop/src/app/types.ts @@ -0,0 +1,7 @@ +import type { IpcRendererEvent } from "electron"; + +export type WorkAdventureDesktopApi = { + desktop: boolean; + notify: (txt: string) => void; + onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) => void; +}; diff --git a/desktop/src/settings.ts b/desktop/src/settings.ts index fb61621c..3e923247 100644 --- a/desktop/src/settings.ts +++ b/desktop/src/settings.ts @@ -1,11 +1,6 @@ import ElectronLog from "electron-log"; import Settings from "electron-settings"; - -type Server = { - _id: string; - name: string; - url: string; -}; +import type { Server } from "./sidebar/types"; type SettingsData = { log_level: ElectronLog.LogLevel; diff --git a/desktop/src/sidebar/preload.ts b/desktop/src/sidebar/preload.ts index 71ba33ed..3d159deb 100644 --- a/desktop/src/sidebar/preload.ts +++ b/desktop/src/sidebar/preload.ts @@ -1,10 +1,13 @@ import { contextBridge, ipcRenderer } from "electron"; +import type { WorkAdventureSidebarApi } from "./types"; -contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", { +const api: WorkAdventureSidebarApi = { desktop: true, getServers: () => ipcRenderer.invoke("sidebar:getServers"), selectServer: (serverId: string) => ipcRenderer.invoke("sidebar:selectServer", serverId), addServer: (serverName: string, serverUrl: string) => ipcRenderer.invoke("sidebar:addServer", serverName, serverUrl), -}); +}; + +contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", api); diff --git a/desktop/src/sidebar/types.ts b/desktop/src/sidebar/types.ts new file mode 100644 index 00000000..79114d1e --- /dev/null +++ b/desktop/src/sidebar/types.ts @@ -0,0 +1,12 @@ +export type Server = { + _id: string; + name: string; + url: string; +}; + +export type WorkAdventureSidebarApi = { + desktop: boolean; + getServers: () => Promise; + selectServer: (serverId: string) => Promise; + addServer: (serverName: string, serverUrl: string) => Promise; +};