File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const url = require('url');
33const request = require ( 'request' ) ;
44const qrcode = require ( 'qrcode' ) ;
55const { base32, base64 } = require ( 'rfc4648' ) ;
6+ const path = require ( "node:path" ) ;
67
78let win
89let 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 ) ;
Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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+ ) ;
You can’t perform that action at this time.
0 commit comments