-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
29 lines (28 loc) · 1.41 KB
/
Copy pathpreload.js
File metadata and controls
29 lines (28 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// preload.js
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("electronAPI", {
// Get app version from Electron
getAppVersion: () => ipcRenderer.invoke("get-app-version"),
// Launch a game using generic command
launchGame: (command, gameId, useCwd) => ipcRenderer.invoke("launch-game", command, gameId, useCwd),
// Launch a game via steam:// protocol (anti-cheat safe)
// steamUrl: e.g. "steam://rungameid/730"
// gameId: internal game ID for play time tracking
// exeName: optional exe name for tasklist polling (e.g. "cs2.exe")
launchSteamUrl: (steamUrl, gameId, exeName) =>
ipcRenderer.invoke("launch-steam-url", steamUrl, gameId, exeName),
// Listen for when a game process exits
// Callback receives: { gameId, elapsedSeconds }
onGameClosed: (callback) => {
const handler = (_event, data) => callback(data);
ipcRenderer.on("game-closed", handler);
return () => ipcRenderer.removeListener("game-closed", handler);
},
// Play history persistence
// Loads the entire play-history.json from disk
loadPlayHistory: () => ipcRenderer.invoke("load-play-history"),
// Saves the entire play-history.json to disk
savePlayHistory: (history) => ipcRenderer.invoke("save-play-history", history),
// Gets history for a single game by name (returns null if not found)
getGameHistory: (gameName) => ipcRenderer.invoke("get-game-history", gameName),
});