Skip to content

Commit

Permalink
Upgrade Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanhunt authored and abrasive committed Apr 3, 2023
1 parent 356a5bb commit c755449
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
14 changes: 12 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const url = require('url');
const request = require('request');
const qrcode = require('qrcode');
const { base32, base64 } = require('rfc4648');
const path = require("node:path");

let win
let client_id='g2c2pjLUThOaBumECqbf'
Expand Down Expand Up @@ -166,9 +167,18 @@ function createWindow () {
if (error) console.error('Failed to register protocol')
})

win = new BrowserWindow({ width: 800, height: 600 })
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
preload: path.join(__dirname, "preload.js")
}
})

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

ipcMain.on('code', (event, arg) => {
verifyCode(arg);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start": "electron ."
},
"devDependencies": {
"electron": "^4.1.4",
"electron": "^23.2.1",
"qrcode": "^1.3.3",
"request": "^2.88.0",
"rfc4648": "^1.2.0"
Expand Down
25 changes: 25 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {
contextBridge,
ipcRenderer
} = require("electron");

// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
"api", {
send: (channel, data) => {
// whitelist channels
let validChannels = ["toMain"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = ["fromMain"];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);

1 comment on commit c755449

@AidanGG
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you actually using preload.js? ui.html still has a require('electron') that completely stops this app from working due to this update.

Please sign in to comment.