Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Itch object to HTML games using contextBridge #2507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/main/inject/inject-game.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import querystring from "querystring";
import urlParser from "url";
import { webFrame } from "electron";
import { contextBridge } from "electron";

declare function atob(b64: string): string;

Expand All @@ -13,11 +13,6 @@ interface Itch {
args: string[];
}

type ExtendedGlobal = typeof global & {
Itch: Itch;
};
const extendedGlobal = global as ExtendedGlobal;

(function () {
try {
console.log(
Expand All @@ -42,9 +37,10 @@ const extendedGlobal = global as ExtendedGlobal;
const jsonSource = atob(
Array.isArray(itchObjectBase64) ? itchObjectBase64[0] : itchObjectBase64
);
extendedGlobal.Itch = JSON.parse(jsonSource);
const Itch: Itch = JSON.parse(jsonSource);
contextBridge.exposeInMainWorld("Itch", Itch);
console.log("Loaded itch environment!");
console.dir(extendedGlobal.Itch);
console.dir(Itch);
} catch (e) {
console.error("While loading itch environment: ", e);
} finally {
Expand Down