@@ -12,7 +12,7 @@ const {
12
12
dialog,
13
13
BrowserWindow,
14
14
session,
15
- ipcMain,
15
+ ipcMain
16
16
} = require ( 'electron' ) ;
17
17
// The splash screen is what appears while the app is loading
18
18
// const { initSplashScreen, OfficeTemplate } = require('electron-splashscreen');
@@ -21,7 +21,7 @@ const { resolve } = require('app-root-path');
21
21
// to install react dev tool extension
22
22
const {
23
23
default : installExtension ,
24
- REACT_DEVELOPER_TOOLS ,
24
+ REACT_DEVELOPER_TOOLS
25
25
} = require ( 'electron-devtools-installer' ) ;
26
26
const debug = require ( 'electron-debug' ) ;
27
27
@@ -31,7 +31,8 @@ const Protocol = require('./protocol');
31
31
const MenuBuilder = require ( './menu' ) ;
32
32
33
33
// mode that the app is running in
34
- const isDev = process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
34
+ const isDev =
35
+ process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
35
36
const port = 8080 ;
36
37
const selfHost = `http://localhost:${ port } ` ;
37
38
@@ -44,9 +45,9 @@ let menuBuilder;
44
45
// this function will be called when Electron has initialized itself
45
46
async function createWindow ( ) {
46
47
// install react dev tools if we are in development mode
47
- // this will happen before creating the browser window. it returns a Boolean whether the protocol of scheme 'app://' was successfully registered and a file (index-prod.html) was sent as the response
48
- protocol . registerBufferProtocol ( Protocol . scheme , Protocol . requestHandler ) ;
49
-
48
+ // this will happen before creating the browser window. it returns a Boolean whether the protocol of scheme 'app://' was successfully registered and a file (index-prod.html) was sent as the response
49
+ protocol . registerBufferProtocol ( Protocol . scheme , Protocol . requestHandler ) ;
50
+
50
51
// Create the browser window.
51
52
win = new BrowserWindow ( {
52
53
// full screen
@@ -61,7 +62,7 @@ async function createWindow() {
61
62
show : false ,
62
63
webPreferences : {
63
64
zoomFactor : 0.7 ,
64
- // enable devtools when in development mode
65
+ // enable devtools when in development mode
65
66
devTools : true ,
66
67
// crucial security feature - blocks rendering process from having access to node modules
67
68
nodeIntegration : false ,
@@ -77,8 +78,8 @@ async function createWindow() {
77
78
enableRemoteModule : false ,
78
79
// path of preload script. preload is how the renderer page will have access to electron functionality
79
80
preload : path . join ( __dirname , 'preload.js' ) ,
80
- nativeWindowOpen : true ,
81
- } ,
81
+ nativeWindowOpen : true
82
+ }
82
83
} ) ;
83
84
84
85
// Splash screen that appears while loading
@@ -118,12 +119,12 @@ async function createWindow() {
118
119
} ) ;
119
120
}
120
121
121
- // Emitted when the window is closed.
122
+ // Emitted when the window is closed.
122
123
win . on ( 'closed' , ( ) => {
123
124
// Dereference the window object, usually you would store windows
124
125
// in an array if your app supports multi windows, this is the time
125
126
// when you should delete the corresponding element.
126
- win = null ;
127
+ app . quit ( ) ;
127
128
} ) ;
128
129
129
130
menuBuilder = MenuBuilder ( win , 'ReacType' ) ;
@@ -145,7 +146,7 @@ async function createWindow() {
145
146
callback ( true ) ; // Approve permission request
146
147
} else {
147
148
console . error (
148
- `The application tried to request permission for '${ permission } '. This permission was not whitelisted and has been blocked.` ,
149
+ `The application tried to request permission for '${ permission } '. This permission was not whitelisted and has been blocked.`
149
150
) ;
150
151
151
152
callback ( false ) ; // Deny
@@ -157,10 +158,10 @@ async function createWindow() {
157
158
// we could use this over _all_ urls
158
159
ses
159
160
. fromPartition ( partition )
160
- . webRequest . onBeforeRequest ( { urls : [ 'http://localhost./*' ] } , ( listener ) => {
161
+ . webRequest . onBeforeRequest ( { urls : [ 'http://localhost./*' ] } , listener => {
161
162
if ( listener . url . indexOf ( 'http://' ) >= 0 ) {
162
163
listener . callback ( {
163
- cancel : true ,
164
+ cancel : true
164
165
} ) ;
165
166
}
166
167
} ) ;
@@ -177,9 +178,9 @@ protocol.registerSchemesAsPrivileged([
177
178
standard : true ,
178
179
secure : true ,
179
180
allowServiceWorkers : true ,
180
- supportFetchAPI : true ,
181
- } ,
182
- } ,
181
+ supportFetchAPI : true
182
+ }
183
+ }
183
184
] ) ;
184
185
185
186
// This method will be called when Electron has finished
@@ -219,12 +220,12 @@ app.on('web-contents-created', (event, contents) => {
219
220
'https://www.facebook.com' ,
220
221
'https://developer.mozilla.org' ,
221
222
'https://www.smashingmagazine.com' ,
222
- 'https://www.html5rocks.com' ,
223
+ 'https://www.html5rocks.com'
223
224
] ;
224
225
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
225
226
if ( ! validOrigins . includes ( parsedUrl . origin ) ) {
226
227
console . error (
227
- `The application tried to navigate to the following address: '${ parsedUrl } '. This origin is not whitelisted attempt to navigate was blocked.` ,
228
+ `The application tried to navigate to the following address: '${ parsedUrl } '. This origin is not whitelisted attempt to navigate was blocked.`
228
229
) ;
229
230
// if the requested URL is not in the whitelisted array, then don't navigate there
230
231
event . preventDefault ( ) ;
@@ -248,11 +249,11 @@ app.on('web-contents-created', (event, contents) => {
248
249
] ;
249
250
// Log and prevent the app from redirecting to a new page
250
251
if (
251
- ! validOrigins . includes ( parsedUrl . origin )
252
- && ! validOrigins . includes ( parsedUrl . href )
252
+ ! validOrigins . includes ( parsedUrl . origin ) &&
253
+ ! validOrigins . includes ( parsedUrl . href )
253
254
) {
254
255
console . error (
255
- `The application tried to redirect to the following address: '${ navigationUrl } '. This attempt was blocked.` ,
256
+ `The application tried to redirect to the following address: '${ navigationUrl } '. This attempt was blocked.`
256
257
) ;
257
258
258
259
event . preventDefault ( ) ;
@@ -286,12 +287,12 @@ app.on('web-contents-created', (event, contents) => {
286
287
'https://github.com' ,
287
288
'https://www.facebook.com' ,
288
289
'https://www.smashingmagazine.com' ,
289
- 'https://www.html5rocks.com' ,
290
+ 'https://www.html5rocks.com'
290
291
] ;
291
292
// Log and prevent the app from navigating to a new page if that page's origin is not whitelisted
292
293
if ( ! validOrigins . includes ( parsedUrl . origin ) ) {
293
294
console . error (
294
- `The application tried to open a new window at the following address: '${ navigationUrl } '. This attempt was blocked.` ,
295
+ `The application tried to open a new window at the following address: '${ navigationUrl } '. This attempt was blocked.`
295
296
) ;
296
297
// if the requested URL is not in the whitelisted array, then don't navigate there
297
298
event . preventDefault ( ) ;
@@ -326,15 +327,15 @@ app.on('remote-get-current-web-contents', (event, webContents) => {
326
327
// When a user selects "Export project", a function (chooseAppDir loaded via preload.js)
327
328
// is triggered that sends a "choose_app_dir" message to the main process
328
329
// when the "choose_app_dir" message is received it triggers this event listener
329
- ipcMain . on ( 'choose_app_dir' , ( event ) => {
330
+ ipcMain . on ( 'choose_app_dir' , event => {
330
331
// dialog displays the native system's dialogue for selecting files
331
332
// once a directory is chosen send a message back to the renderer with the path of the directory
332
333
dialog
333
334
. showOpenDialog ( win , {
334
335
properties : [ 'openDirectory' ] ,
335
- buttonLabel : 'Export' ,
336
+ buttonLabel : 'Export'
336
337
} )
337
- . then ( ( directory ) => {
338
+ . then ( directory => {
338
339
if ( ! directory ) return ;
339
340
event . sender . send ( 'app_dir_selected' , directory . filePaths [ 0 ] ) ;
340
341
} )
@@ -374,8 +375,8 @@ ipcMain.on('delete_cookie', event => {
374
375
375
376
// opens new window for github oauth when button on sign in page is clicked
376
377
ipcMain . on ( 'github' , event => {
377
- // your applications credentials
378
- const githubUrl = 'https ://github.com/login/oauth/authorize? ' ;
378
+ console . log ( 'inside main.js in electron' ) ;
379
+ const githubURL = 'http ://localhost:5000/auth/github ' ;
379
380
const options = {
380
381
client_id : process . env . GITHUB_ID ,
381
382
client_secret : process . env . GITHUB_SECRET ,
@@ -395,8 +396,8 @@ ipcMain.on('github', event => {
395
396
zoomFactor : 1.0
396
397
}
397
398
} ) ;
398
- const authUrl = ` ${ githubUrl } client_id= ${ process . env . GITHUB_ID } ` ;
399
- github . loadURL ( authUrl ) ;
399
+
400
+ github . loadURL ( githubURL ) ;
400
401
github . show ( ) ;
401
402
const handleCallback = url => {
402
403
const raw_code = / c o d e = ( [ ^ & ] \* ) / . exec ( url ) || null ;
@@ -441,6 +442,9 @@ ipcMain.on('github', event => {
441
442
if ( isDev ) {
442
443
redirectUrl = 'http://localhost:8080/' ;
443
444
}
445
+ console . log ( callbackUrl === redirectUrl ) ;
446
+ console . log ( 'callbackUrl' , callbackUrl ) ;
447
+ console . log ( 'redirectUrl' , redirectUrl ) ;
444
448
if ( callbackUrl === redirectUrl ) {
445
449
dialog . showMessageBox ( {
446
450
type : 'info' ,
0 commit comments