@@ -4,35 +4,35 @@ const {
4
4
dialog,
5
5
BrowserWindow,
6
6
session,
7
- ipcMain,
8
- Menu
7
+ ipcMain
9
8
} = require ( 'electron' ) ;
9
+
10
10
// The splash screen is what appears while the app is loading
11
11
const { initSplashScreen, OfficeTemplate } = require ( 'electron-splashscreen' ) ;
12
12
const { resolve } = require ( 'app-root-path' ) ;
13
+ const Protocol = require ( './protocol' ) ;
14
+ const MenuBuilder = require ( './menu' ) ;
15
+ const path = require ( 'path' ) ;
16
+
13
17
const {
14
18
default : installExtension ,
15
19
REACT_DEVELOPER_TOOLS
16
20
} = require ( 'electron-devtools-installer' ) ;
17
21
const debug = require ( 'electron-debug' ) ;
18
22
19
- const Protocol = require ( './protocol' ) ;
20
- // menu from another file to modularize the code
21
- const MenuBuilder = require ( './menu' ) ;
22
-
23
- const path = require ( 'path' ) ;
24
- // const fs = require('fs');
25
-
26
- console . log ( 'NODE ENV is ' , process . env . NODE_ENV ) ;
27
23
const isDev = process . env . NODE_ENV === 'development' ;
28
24
const port = 8080 ;
29
25
const selfHost = `http://localhost:${ port } ` ;
30
26
27
+ // main.js is what controls the lifecycle of the electron applicaton
28
+
31
29
// Keep a global reference of the window object, if you don't, the window will
32
30
// be closed automatically when the JavaScript object is garbage collected.
33
31
let win ;
34
32
let menuBuilder ;
35
33
34
+ // function to create a new broswer window
35
+ // this function will be called when Electron has initialized itself
36
36
async function createWindow ( ) {
37
37
if ( isDev ) {
38
38
await installExtension ( [ REACT_DEVELOPER_TOOLS ] )
@@ -52,12 +52,10 @@ async function createWindow() {
52
52
height : 1080 ,
53
53
// window title
54
54
title : `ReacType` ,
55
+ // the browser window will not display intiially as it's loading
56
+ // once the browser window renders, a function is called below that hides the splash screen and displays the browser window
55
57
show : false ,
56
- icon : path . join ( __dirname , '../src/public/icons/png/256x256.png' ) ,
57
- win : {
58
- icon : path . join ( __dirname , '../src/public/icons/win/icon.ico' ) ,
59
- target : [ 'portable' ]
60
- } ,
58
+ // icon: path.join(__dirname, '../src/public/icons/png/256x256.png'),
61
59
webPreferences : {
62
60
zoomFactor : 0.7 ,
63
61
// enable devtools
@@ -79,10 +77,7 @@ async function createWindow() {
79
77
}
80
78
} ) ;
81
79
82
- console . log ( 'PATH is ' , resolve ( '/' ) ) ;
83
-
84
- //splash screen deets
85
- // TODO: splash screen logo/icon aren't loading in dev mode
80
+ // Splash screen that appears while loading
86
81
const hideSplashscreen = initSplashScreen ( {
87
82
mainWindow : win ,
88
83
icon : resolve ( 'app/src/public/icons/png/64x64.png' ) ,
@@ -112,9 +107,9 @@ async function createWindow() {
112
107
hideSplashscreen ( ) ;
113
108
} ) ;
114
109
115
- // Only do these things when in development
110
+ // automatically open DevTools when opening the app
111
+ // Note: devtools is creating many errors in the logs at the moment but can't figure out how to resolve the issue
116
112
if ( isDev ) {
117
- // automatically open DevTools when opening the app
118
113
win . webContents . once ( 'dom-ready' , ( ) => {
119
114
debug ( ) ;
120
115
win . webContents . openDevTools ( ) ;
@@ -129,6 +124,10 @@ async function createWindow() {
129
124
win = null ;
130
125
} ) ;
131
126
127
+ menuBuilder = MenuBuilder ( win , 'ReacType' ) ;
128
+ menuBuilder . buildMenu ( ) ;
129
+
130
+ // Removed this security feature for now since it's not being used
132
131
// https://electronjs.org/docs/tutorial/security#4-handle-session-permission-requests-from-remote-content
133
132
// TODO: is this the same type of sessions that have in react type
134
133
// Could potentially remove this session capability - it appears to be more focused on approving requests from 3rd party notifications
@@ -163,12 +162,8 @@ async function createWindow() {
163
162
} ) ;
164
163
}
165
164
} ) ;
166
-
167
- menuBuilder = MenuBuilder ( win , 'ReacType' ) ;
168
- menuBuilder . buildMenu ( ) ;
169
165
}
170
166
171
- // TODO: unclear of whether this is necsssary or not. Looks like a security best practice but will likely introduce complications
172
167
// Needs to be called before app is ready;
173
168
// gives our scheme access to load relative files,
174
169
// as well as local storage, cookies, etc.
@@ -197,8 +192,6 @@ app.on('window-all-closed', () => {
197
192
if ( process . platform !== 'darwin' ) {
198
193
app . quit ( ) ;
199
194
} else {
200
- // TODO: remove i18nextbackend
201
- // i18nextBackend.clearMainBindings(ipcMain);
202
195
ContextMenu . clearMainBindings ( ipcMain ) ;
203
196
}
204
197
} ) ;
@@ -214,7 +207,6 @@ app.on('activate', () => {
214
207
// https://electronjs.org/docs/tutorial/security#12-disable-or-limit-navigation
215
208
// limits navigation within the app to a whitelisted array
216
209
// redirects are a common attack vector
217
- // TODO: add github to the validOrigins whitelist array
218
210
219
211
// after the contents of the webpage are rendered, set up event listeners on the webContents
220
212
app . on ( 'web-contents-created' , ( event , contents ) => {
0 commit comments