extract types for ipc
This commit is contained in:
parent
c891fcb1bd
commit
a86bf32ee2
@ -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
7
desktop/src/app/types.ts
Normal 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;
|
||||
};
|
@ -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;
|
||||
|
@ -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);
|
||||
|
12
desktop/src/sidebar/types.ts
Normal file
12
desktop/src/sidebar/types.ts
Normal 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>;
|
||||
};
|
Loading…
Reference in New Issue
Block a user