2024-04-21 08:26:29 +03:00
|
|
|
// See the Electron documentation for details on how to use preload scripts:
|
|
|
|
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
|
|
|
|
import { contextBridge, ipcRenderer } from "electron";
|
|
|
|
|
|
|
|
import type {
|
|
|
|
GameShop,
|
2024-05-20 04:21:11 +03:00
|
|
|
DownloadProgress,
|
2024-04-21 08:26:29 +03:00
|
|
|
UserPreferences,
|
2024-05-24 02:26:21 +03:00
|
|
|
AppUpdaterEvent,
|
|
|
|
StartGameDownloadPayload,
|
2024-06-21 00:09:49 +03:00
|
|
|
GameRunning,
|
2024-04-21 08:26:29 +03:00
|
|
|
} from "@types";
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("electron", {
|
|
|
|
/* Torrenting */
|
2024-05-24 02:26:21 +03:00
|
|
|
startGameDownload: (payload: StartGameDownloadPayload) =>
|
|
|
|
ipcRenderer.invoke("startGameDownload", payload),
|
2024-04-21 08:26:29 +03:00
|
|
|
cancelGameDownload: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("cancelGameDownload", gameId),
|
|
|
|
pauseGameDownload: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("pauseGameDownload", gameId),
|
|
|
|
resumeGameDownload: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("resumeGameDownload", gameId),
|
2024-05-20 04:21:11 +03:00
|
|
|
onDownloadProgress: (cb: (value: DownloadProgress) => void) => {
|
2024-04-21 08:26:29 +03:00
|
|
|
const listener = (
|
|
|
|
_event: Electron.IpcRendererEvent,
|
2024-05-20 04:21:11 +03:00
|
|
|
value: DownloadProgress
|
2024-04-21 08:26:29 +03:00
|
|
|
) => cb(value);
|
|
|
|
ipcRenderer.on("on-download-progress", listener);
|
|
|
|
return () => ipcRenderer.removeListener("on-download-progress", listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Catalogue */
|
|
|
|
searchGames: (query: string) => ipcRenderer.invoke("searchGames", query),
|
2024-06-03 04:12:05 +03:00
|
|
|
getCatalogue: () => ipcRenderer.invoke("getCatalogue"),
|
2024-04-21 08:26:29 +03:00
|
|
|
getGameShopDetails: (objectID: string, shop: GameShop, language: string) =>
|
|
|
|
ipcRenderer.invoke("getGameShopDetails", objectID, shop, language),
|
|
|
|
getRandomGame: () => ipcRenderer.invoke("getRandomGame"),
|
|
|
|
getHowLongToBeat: (objectID: string, shop: GameShop, title: string) =>
|
|
|
|
ipcRenderer.invoke("getHowLongToBeat", objectID, shop, title),
|
|
|
|
getGames: (take?: number, prevCursor?: number) =>
|
|
|
|
ipcRenderer.invoke("getGames", take, prevCursor),
|
2024-05-13 01:43:00 +03:00
|
|
|
searchGameRepacks: (query: string) =>
|
|
|
|
ipcRenderer.invoke("searchGameRepacks", query),
|
2024-04-21 08:26:29 +03:00
|
|
|
|
|
|
|
/* User preferences */
|
|
|
|
getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"),
|
|
|
|
updateUserPreferences: (preferences: UserPreferences) =>
|
|
|
|
ipcRenderer.invoke("updateUserPreferences", preferences),
|
2024-05-06 00:13:28 +03:00
|
|
|
autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled),
|
2024-05-28 16:01:28 +03:00
|
|
|
authenticateRealDebrid: (apiToken: string) =>
|
|
|
|
ipcRenderer.invoke("authenticateRealDebrid", apiToken),
|
2024-04-21 08:26:29 +03:00
|
|
|
|
2024-06-03 04:12:05 +03:00
|
|
|
/* Download sources */
|
|
|
|
getDownloadSources: () => ipcRenderer.invoke("getDownloadSources"),
|
|
|
|
validateDownloadSource: (url: string) =>
|
|
|
|
ipcRenderer.invoke("validateDownloadSource", url),
|
|
|
|
addDownloadSource: (url: string) =>
|
|
|
|
ipcRenderer.invoke("addDownloadSource", url),
|
|
|
|
removeDownloadSource: (id: number) =>
|
|
|
|
ipcRenderer.invoke("removeDownloadSource", id),
|
2024-06-05 16:18:40 +03:00
|
|
|
syncDownloadSources: () => ipcRenderer.invoke("syncDownloadSources"),
|
2024-06-03 04:12:05 +03:00
|
|
|
|
2024-04-21 08:26:29 +03:00
|
|
|
/* Library */
|
2024-06-06 02:29:42 +03:00
|
|
|
addGameToLibrary: (objectID: string, title: string, shop: GameShop) =>
|
|
|
|
ipcRenderer.invoke("addGameToLibrary", objectID, title, shop),
|
2024-06-05 22:42:45 +03:00
|
|
|
createGameShortcut: (id: number) =>
|
|
|
|
ipcRenderer.invoke("createGameShortcut", id),
|
2024-06-04 23:33:21 +03:00
|
|
|
updateExecutablePath: (id: number, executablePath: string) =>
|
|
|
|
ipcRenderer.invoke("updateExecutablePath", id, executablePath),
|
2024-04-21 08:26:29 +03:00
|
|
|
getLibrary: () => ipcRenderer.invoke("getLibrary"),
|
|
|
|
openGameInstaller: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("openGameInstaller", gameId),
|
2024-06-04 23:33:21 +03:00
|
|
|
openGameInstallerPath: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("openGameInstallerPath", gameId),
|
|
|
|
openGameExecutablePath: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("openGameExecutablePath", gameId),
|
2024-04-21 08:26:29 +03:00
|
|
|
openGame: (gameId: number, executablePath: string) =>
|
|
|
|
ipcRenderer.invoke("openGame", gameId, executablePath),
|
|
|
|
closeGame: (gameId: number) => ipcRenderer.invoke("closeGame", gameId),
|
2024-04-29 13:01:34 +03:00
|
|
|
removeGameFromLibrary: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("removeGameFromLibrary", gameId),
|
2024-05-30 02:40:39 +03:00
|
|
|
removeGame: (gameId: number) => ipcRenderer.invoke("removeGame", gameId),
|
2024-04-21 08:26:29 +03:00
|
|
|
deleteGameFolder: (gameId: number) =>
|
|
|
|
ipcRenderer.invoke("deleteGameFolder", gameId),
|
|
|
|
getGameByObjectID: (objectID: string) =>
|
|
|
|
ipcRenderer.invoke("getGameByObjectID", objectID),
|
2024-06-21 00:09:49 +03:00
|
|
|
onGamesRunning: (
|
|
|
|
cb: (
|
|
|
|
gamesRunning: Pick<GameRunning, "id" | "sessionDurationInMillis">[]
|
|
|
|
) => void
|
|
|
|
) => {
|
|
|
|
const listener = (_event: Electron.IpcRendererEvent, gamesRunning) =>
|
|
|
|
cb(gamesRunning);
|
2024-06-19 20:37:26 +03:00
|
|
|
ipcRenderer.on("on-games-running", listener);
|
|
|
|
return () => ipcRenderer.removeListener("on-games-running", listener);
|
2024-04-21 08:26:29 +03:00
|
|
|
},
|
2024-06-19 04:35:57 +03:00
|
|
|
onLibraryBatchComplete: (cb: () => void) => {
|
|
|
|
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
|
|
|
ipcRenderer.on("on-library-batch-complete", listener);
|
|
|
|
return () =>
|
|
|
|
ipcRenderer.removeListener("on-library-batch-complete", listener);
|
|
|
|
},
|
2024-04-21 08:26:29 +03:00
|
|
|
|
|
|
|
/* Hardware */
|
2024-04-21 07:02:17 +03:00
|
|
|
getDiskFreeSpace: (path: string) =>
|
|
|
|
ipcRenderer.invoke("getDiskFreeSpace", path),
|
2024-04-21 08:26:29 +03:00
|
|
|
|
|
|
|
/* Misc */
|
|
|
|
ping: () => ipcRenderer.invoke("ping"),
|
|
|
|
getVersion: () => ipcRenderer.invoke("getVersion"),
|
|
|
|
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
2024-06-28 01:00:12 +03:00
|
|
|
isPortableVersion: () => ipcRenderer.invoke("isPortableVersion"),
|
2024-04-21 08:26:29 +03:00
|
|
|
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
|
|
|
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
|
|
|
ipcRenderer.invoke("showOpenDialog", options),
|
|
|
|
platform: process.platform,
|
2024-05-19 07:39:50 +03:00
|
|
|
|
2024-05-27 03:49:32 +03:00
|
|
|
/* Auto update */
|
2024-05-24 02:26:21 +03:00
|
|
|
onAutoUpdaterEvent: (cb: (value: AppUpdaterEvent) => void) => {
|
2024-05-19 20:15:07 +03:00
|
|
|
const listener = (
|
|
|
|
_event: Electron.IpcRendererEvent,
|
2024-05-24 02:26:21 +03:00
|
|
|
value: AppUpdaterEvent
|
2024-05-19 20:15:07 +03:00
|
|
|
) => cb(value);
|
|
|
|
|
|
|
|
ipcRenderer.on("autoUpdaterEvent", listener);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
ipcRenderer.removeListener("autoUpdaterEvent", listener);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
checkForUpdates: () => ipcRenderer.invoke("checkForUpdates"),
|
|
|
|
restartAndInstallUpdate: () => ipcRenderer.invoke("restartAndInstallUpdate"),
|
2024-06-12 04:09:24 +03:00
|
|
|
|
|
|
|
/* Profile */
|
2024-06-16 01:52:37 +03:00
|
|
|
getMe: () => ipcRenderer.invoke("getMe"),
|
2024-06-18 03:55:43 +03:00
|
|
|
updateProfile: (displayName: string, newProfileImagePath: string | null) =>
|
|
|
|
ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath),
|
2024-06-16 19:58:24 +03:00
|
|
|
|
|
|
|
/* User */
|
2024-06-17 01:51:09 +03:00
|
|
|
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
|
2024-06-16 19:58:24 +03:00
|
|
|
|
|
|
|
/* Auth */
|
2024-06-17 04:19:36 +03:00
|
|
|
signOut: () => ipcRenderer.invoke("signOut"),
|
2024-06-20 15:22:12 +03:00
|
|
|
openAuthWindow: () => ipcRenderer.invoke("openAuthWindow"),
|
2024-06-21 04:37:49 +03:00
|
|
|
getSessionHash: () => ipcRenderer.invoke("getSessionHash"),
|
2024-06-16 19:58:24 +03:00
|
|
|
onSignIn: (cb: () => void) => {
|
|
|
|
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
|
|
|
ipcRenderer.on("on-signin", listener);
|
|
|
|
return () => ipcRenderer.removeListener("on-signin", listener);
|
|
|
|
},
|
|
|
|
onSignOut: (cb: () => void) => {
|
|
|
|
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
|
|
|
ipcRenderer.on("on-signout", listener);
|
|
|
|
return () => ipcRenderer.removeListener("on-signout", listener);
|
|
|
|
},
|
2024-04-21 08:26:29 +03:00
|
|
|
});
|