Skip to content

Commit c755449

Browse files
lachlanhuntabrasive
authored andcommitted
Upgrade Electron
1 parent 356a5bb commit c755449

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

main.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const url = require('url');
33
const request = require('request');
44
const qrcode = require('qrcode');
55
const { base32, base64 } = require('rfc4648');
6+
const path = require("node:path");
67

78
let win
89
let client_id='g2c2pjLUThOaBumECqbf'
@@ -166,9 +167,18 @@ function createWindow () {
166167
if (error) console.error('Failed to register protocol')
167168
})
168169

169-
win = new BrowserWindow({ width: 800, height: 600 })
170+
win = new BrowserWindow({
171+
width: 800,
172+
height: 600,
173+
webPreferences: {
174+
nodeIntegration: false,
175+
contextIsolation: true,
176+
enableRemoteModule: false,
177+
preload: path.join(__dirname, "preload.js")
178+
}
179+
})
170180

171-
win.loadURL(`file://${__dirname}/instructions.html`)
181+
win.loadFile(path.join(__dirname, "instructions.html"));
172182

173183
ipcMain.on('code', (event, arg) => {
174184
verifyCode(arg);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start": "electron ."
1313
},
1414
"devDependencies": {
15-
"electron": "^4.1.4",
15+
"electron": "^23.2.1",
1616
"qrcode": "^1.3.3",
1717
"request": "^2.88.0",
1818
"rfc4648": "^1.2.0"

preload.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {
2+
contextBridge,
3+
ipcRenderer
4+
} = require("electron");
5+
6+
// Expose protected methods that allow the renderer process to use
7+
// the ipcRenderer without exposing the entire object
8+
contextBridge.exposeInMainWorld(
9+
"api", {
10+
send: (channel, data) => {
11+
// whitelist channels
12+
let validChannels = ["toMain"];
13+
if (validChannels.includes(channel)) {
14+
ipcRenderer.send(channel, data);
15+
}
16+
},
17+
receive: (channel, func) => {
18+
let validChannels = ["fromMain"];
19+
if (validChannels.includes(channel)) {
20+
// Deliberately strip event as it includes `sender`
21+
ipcRenderer.on(channel, (event, ...args) => func(...args));
22+
}
23+
}
24+
}
25+
);

0 commit comments

Comments
 (0)