extract types for ipc

This commit is contained in:
Anton Bracke 2022-02-18 10:26:21 +01:00
parent c891fcb1bd
commit a86bf32ee2
No known key found for this signature in database
GPG Key ID: B1222603899C6B25
5 changed files with 30 additions and 10 deletions

View File

@ -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);

7
desktop/src/app/types.ts Normal file
View File

@ -0,0 +1,7 @@
import type { IpcRendererEvent } from "electron";
export type WorkAdventureDesktopApi = {
desktop: boolean;
notify: (txt: string) => void;
onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) => void;
};

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1,12 @@
export type Server = {
_id: string;
name: string;
url: string;
};
export type WorkAdventureSidebarApi = {
desktop: boolean;
getServers: () => Promise<Server[]>;
selectServer: (serverId: string) => Promise<Error | boolean>;
addServer: (serverName: string, serverUrl: string) => Promise<boolean>;
};