@@ -29,14 +29,14 @@ const isDev =
29
29
const port = 8080 ;
30
30
const selfHost = `http://localhost:${ port } ` ;
31
31
32
- // main.js is what controls the lifecycle of the electron application
32
+ // main.js is what controls the lifecycle of the electron applicaton
33
33
34
34
// Keep a global reference of the window object, if you don't, the window will
35
35
// be closed automatically when the JavaScript object is garbage collected.
36
36
let win ;
37
37
let menuBuilder ;
38
38
39
- // function to create a new browser window
39
+ // function to create a new broswer window
40
40
// this function will be called when Electron has initialized itself
41
41
async function createWindow ( ) {
42
42
if ( isDev ) {
@@ -55,24 +55,25 @@ async function createWindow() {
55
55
// full screen
56
56
width : 1920 ,
57
57
height : 1080 ,
58
+ minWidth : 980 ,
58
59
// window title
59
60
title : `ReacType` ,
60
- // the browser window will not display initially as it's loading
61
+ // the browser window will not display intiially as it's loading
61
62
// once the browser window renders, a function is called below that hides the splash screen and displays the browser window
62
63
show : false ,
63
64
// icon: path.join(__dirname, '../src/public/icons/png/256x256.png'),
64
65
webPreferences : {
65
66
zoomFactor : 0.7 ,
66
67
// enable devtools when in development mode
67
68
devTools : isDev ,
68
- // crucial security feature - blocks rendering process from having access to node modules
69
+ // crucial security feature - blocks rendering process from having access to node moduels
69
70
nodeIntegration : false ,
70
71
// web workers will not have access to node
71
72
nodeIntegrationInWorker : false ,
72
- // disallow experimental feature to allow node.js support in sub-frames (i-frames /child windows)
73
+ // disallow experimental feature to allow node.js suppport in subframes (iframes /child windows)
73
74
nodeIntegrationInSubFrames : false ,
74
- // runs electron apis and preload script in a separate JS context
75
- // separate context has access to document/window but has it's own built-ins and is isolate from changes to global environment by loaded page
75
+ // runs electron apis and preload script in a seperate JS context
76
+ // sepearate context has access to document/window but has it's own built-ins and is isolate from chagnes to gloval environment by locaded page
76
77
// Electron API only available from preload, not loaded page
77
78
contextIsolation : true ,
78
79
// disables remote module. critical for ensuring that rendering process doesn't have access to node functionality
@@ -100,7 +101,7 @@ async function createWindow() {
100
101
101
102
// Load app
102
103
if ( isDev ) {
103
- // load app from web-dev server
104
+ // load app from webdev server
104
105
win . loadURL ( selfHost ) ;
105
106
} else {
106
107
// load local file if in production
@@ -223,8 +224,10 @@ app.on('web-contents-created', (event, contents) => {
223
224
selfHost ,
224
225
'http://localhost:5000' ,
225
226
'https://reactype.herokuapp.com' ,
226
- 'https://github.com/'
227
+ 'https://github.com/' ,
228
+ 'https://nextjs.org' ,
227
229
] ;
230
+ console . log ( 'parsed URL origin' , parsedUrl . origin ) ;
228
231
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
229
232
if ( ! validOrigins . includes ( parsedUrl . origin ) ) {
230
233
console . error (
@@ -233,7 +236,7 @@ app.on('web-contents-created', (event, contents) => {
233
236
// if the requested URL is not in the whitelisted array, then don't navigate there
234
237
event . preventDefault ( ) ;
235
238
return ;
236
- }
239
+ } else console . log ( `Successful navigation to ${ parsedUrl } ` ) ;
237
240
} ) ;
238
241
239
242
contents . on ( 'will-redirect' , ( event , navigationUrl ) => {
@@ -242,8 +245,8 @@ app.on('web-contents-created', (event, contents) => {
242
245
selfHost ,
243
246
'http://localhost:5000' ,
244
247
'https://reactype.herokuapp.com' ,
245
- 'https://github.com' ,
246
- 'app ://rse/'
248
+ 'https://github.com/ ' ,
249
+ 'https ://nextjs.org' ,
247
250
] ;
248
251
249
252
// Log and prevent the app from redirecting to a new page
@@ -257,12 +260,12 @@ app.on('web-contents-created', (event, contents) => {
257
260
258
261
event . preventDefault ( ) ;
259
262
return ;
260
- }
263
+ } else console . log ( 'Succesful link sent to browser' ) ;
261
264
} ) ;
262
265
263
266
// https://electronjs.org/docs/tutorial/security#11-verify-webview-options-before-creation
264
267
// The web-view is used to embed guest content in a page
265
- // This event listener deletes web-views if they happen to occur in the app
268
+ // This event listener deletes webviews if they happen to occur in the app
266
269
// https://www.electronjs.org/docs/api/web-contents#event-will-attach-webview
267
270
contents . on ( 'will-attach-webview' , ( event , webPreferences , params ) => {
268
271
// Strip away preload scripts if unused or verify their location is legitimate
@@ -276,12 +279,26 @@ app.on('web-contents-created', (event, contents) => {
276
279
// https://electronjs.org/docs/tutorial/security#13-disable-or-limit-creation-of-new-windows
277
280
contents . on ( 'new-window' , async ( event , navigationUrl ) => {
278
281
// Log and prevent opening up a new window
279
- console . error (
280
- `The application tried to open a new window at the following address: '${ navigationUrl } '. This attempt was blocked.`
281
- ) ;
282
-
283
- event . preventDefault ( ) ;
284
- return ;
282
+ const parsedUrl = new URL ( navigationUrl ) ;
283
+ const validOrigins = [
284
+ selfHost ,
285
+ 'http://localhost:5000' ,
286
+ 'https://reactype.herokuapp.com' ,
287
+ 'https://github.com/' ,
288
+ 'https://nextjs.org' ,
289
+ ] ;
290
+ console . log ( 'parsed URL origin' , parsedUrl . origin ) ;
291
+ // Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
292
+ if ( ! validOrigins . includes ( parsedUrl . origin ) ) {
293
+ console . error (
294
+ `The application tried to open a new window at the following address: '${ navigationUrl } '. This attempt was blocked.`
295
+ ) ;
296
+ // if the requested URL is not in the whitelisted array, then don't navigate there
297
+ event . preventDefault ( ) ;
298
+ return ;
299
+ } else console . log ( `Successful new window to ${ parsedUrl } ` ) ;
300
+ // event.preventDefault();
301
+ // return;
285
302
} ) ;
286
303
} ) ;
287
304
@@ -360,9 +377,15 @@ ipcMain.on('delete_cookie', event => {
360
377
. catch ( err => console . log ( 'Error deleting cookie:' , err ) ) ;
361
378
} ) ;
362
379
363
- // opens new window for github oauth when button on sign in page is clicked
380
+ // opens new window for github oauth when button on signin page is clicked
364
381
ipcMain . on ( 'github' , event => {
365
- // create new browser window object with size, title, security options
382
+ // your github applications credentials
383
+ const options = {
384
+ client_id : 'your_client_id' ,
385
+ client_secret : 'your_client_secret' ,
386
+ scopes : [ 'user:email' , 'notifications' ]
387
+ } ;
388
+ // create new browserwindow object with size, title, security options
366
389
const github = new BrowserWindow ( {
367
390
width : 800 ,
368
391
height : 600 ,
@@ -376,8 +399,11 @@ ipcMain.on('github', event => {
376
399
zoomFactor : 1.0
377
400
}
378
401
} ) ;
402
+ const githubUrl = 'https://github.com/login/oauth/authorize?' ;
403
+ const authUrl =
404
+ githubUrl + 'client_id=' + options . client_id + '&scope=' + options . scopes ;
379
405
// redirects to relevant server endpoint
380
- github . loadURL ( ` ${ serverUrl } /github` ) ;
406
+ github . loadURL ( authUrl ) ;
381
407
// show window
382
408
github . show ( ) ;
383
409
// if final callback is reached and we get a redirect from server back to our app, close oauth window
@@ -399,10 +425,11 @@ ipcMain.on('github', event => {
399
425
} ) ;
400
426
401
427
ipcMain . on ( 'tutorial' , event => {
402
- // create new browser window object with size, title, security options
428
+ // create new browserwindow object with size, title, security options
403
429
const tutorial = new BrowserWindow ( {
404
430
width : 800 ,
405
431
height : 600 ,
432
+ minWidth : 661 ,
406
433
title : 'Tutorial' ,
407
434
webPreferences : {
408
435
nodeIntegration : false ,
@@ -435,8 +462,4 @@ ipcMain.on('tutorial', event => {
435
462
// });
436
463
} ) ;
437
464
438
-
439
-
440
-
441
-
442
465
//module.exports = dialog;
0 commit comments