Skip to content

Commit 447dd18

Browse files
committed
Read injected.js from main process.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 9a200dc commit 447dd18

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

app/common/typed-ipc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type MainMessage = {
77
"fetch-user-agent": () => string;
88
"focus-app": () => void;
99
"focus-this-webview": () => void;
10+
"get-injected-js": () => string;
1011
"permission-callback": (permissionCallbackId: number, grant: boolean) => void;
1112
"quit-app": () => void;
1213
"realm-icon-changed": (serverURL: string, iconURL: string) => void;

app/main/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {IpcMainEvent, WebContents} from "electron/main";
22
import {BrowserWindow, app, dialog, powerMonitor, session} from "electron/main";
3+
import fs from "node:fs";
34
import path from "node:path";
45
import process from "node:process";
56

@@ -202,6 +203,13 @@ function createMainWindow(): BrowserWindow {
202203
configureSpellChecker();
203204
ipcMain.on("configure-spell-checker", configureSpellChecker);
204205

206+
ipcMain.on("get-injected-js", (event) => {
207+
event.returnValue = fs.readFileSync(
208+
path.join(bundlePath, "injected.js"),
209+
"utf8",
210+
);
211+
});
212+
205213
AppMenu.setMenu({
206214
tabs: [],
207215
});

app/renderer/js/preload.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import {contextBridge, webFrame} from "electron/renderer";
2-
import fs from "node:fs";
3-
import path from "node:path";
4-
5-
import {bundlePath} from "../../common/paths.js";
62

73
import electron_bridge, {bridgeEvents} from "./electron-bridge.js";
84
import * as NetworkError from "./pages/network.js";
@@ -79,6 +75,4 @@ window.addEventListener("load", () => {
7975
});
8076

8177
(async () =>
82-
webFrame.executeJavaScript(
83-
fs.readFileSync(path.join(bundlePath, "injected.js"), "utf8"),
84-
))();
78+
webFrame.executeJavaScript(ipcRenderer.sendSync("get-injected-js")))();

0 commit comments

Comments
 (0)