| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  | // Modules to control application life and create native browser window
 | 
					
						
							| 
									
										
										
										
											2021-10-03 20:12:55 -05:00
										 |  |  | const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron') | 
					
						
							| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  | const path = require('path') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-08 11:42:28 -07:00
										 |  |  | let mainWindow; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (process.defaultApp) { | 
					
						
							|  |  |  |   if (process.argv.length >= 2) { | 
					
						
							|  |  |  |     app.setAsDefaultProtocolClient('electron-fiddle', process.execPath, [path.resolve(process.argv[1])]) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |     app.setAsDefaultProtocolClient('electron-fiddle') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const gotTheLock = app.requestSingleInstanceLock() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!gotTheLock) { | 
					
						
							|  |  |  |   app.quit() | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |   app.on('second-instance', (event, commandLine, workingDirectory) => { | 
					
						
							|  |  |  |     // Someone tried to run a second instance, we should focus our window.
 | 
					
						
							|  |  |  |     if (mainWindow) { | 
					
						
							|  |  |  |       if (mainWindow.isMinimized()) mainWindow.restore() | 
					
						
							|  |  |  |       mainWindow.focus() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Create mainWindow, load the rest of the app, etc...
 | 
					
						
							|  |  |  |   app.whenReady().then(() => { | 
					
						
							|  |  |  |     createWindow() | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   app.on('open-url', (event, url) => { | 
					
						
							|  |  |  |     dialog.showErrorBox('Welcome Back', `You arrived from: ${url}`) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | function createWindow () { | 
					
						
							|  |  |  |   // Create the browser window.
 | 
					
						
							|  |  |  |   mainWindow = new BrowserWindow({ | 
					
						
							|  |  |  |     width: 800, | 
					
						
							|  |  |  |     height: 600, | 
					
						
							|  |  |  |     webPreferences: { | 
					
						
							| 
									
										
										
										
											2021-07-08 11:42:28 -07:00
										 |  |  |       preload: path.join(__dirname, 'preload.js'), | 
					
						
							| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mainWindow.loadFile('index.html') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-08 11:42:28 -07:00
										 |  |  | // Quit when all windows are closed, except on macOS. There, it's common
 | 
					
						
							|  |  |  | // for applications and their menu bar to stay active until the user quits
 | 
					
						
							|  |  |  | // explicitly with Cmd + Q.
 | 
					
						
							| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  | app.on('window-all-closed', function () { | 
					
						
							| 
									
										
										
										
											2021-07-08 11:42:28 -07:00
										 |  |  |   if (process.platform !== 'darwin') app.quit() | 
					
						
							| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-08 11:42:28 -07:00
										 |  |  | // Handle window controls via IPC
 | 
					
						
							|  |  |  | ipcMain.on('shell:open', () => { | 
					
						
							|  |  |  |   const pageDirectory = __dirname.replace('app.asar', 'app.asar.unpacked') | 
					
						
							|  |  |  |   const pagePath = path.join('file://', pageDirectory, 'index.html') | 
					
						
							|  |  |  |   shell.openExternal(pagePath) | 
					
						
							| 
									
										
										
										
											2019-11-13 05:46:54 +00:00
										 |  |  | }) |