| 
									
										
										
										
											2021-10-14 18:32:32 -07:00
										 |  |  | const { app } = require('electron'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-10 08:54:46 -08:00
										 |  |  | // Send data from the second instance to the first instance.
 | 
					
						
							|  |  |  | const sendAdditionalData = app.commandLine.hasSwitch('send-data'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 22:20:54 -07:00
										 |  |  | app.whenReady().then(() => { | 
					
						
							|  |  |  |   console.log('started'); // ping parent
 | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-01-10 08:54:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 01:14:09 -07:00
										 |  |  | let obj = { | 
					
						
							| 
									
										
										
										
											2021-10-14 18:32:32 -07:00
										 |  |  |   level: 1, | 
					
						
							|  |  |  |   testkey: 'testvalue1', | 
					
						
							|  |  |  |   inner: { | 
					
						
							|  |  |  |     level: 2, | 
					
						
							|  |  |  |     testkey: 'testvalue2' | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-11-04 01:14:09 -07:00
										 |  |  | if (app.commandLine.hasSwitch('data-content')) { | 
					
						
							|  |  |  |   obj = JSON.parse(app.commandLine.getSwitchValue('data-content')); | 
					
						
							|  |  |  |   if (obj === 'undefined') { | 
					
						
							|  |  |  |     obj = undefined; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const gotTheLock = sendAdditionalData | 
					
						
							|  |  |  |   ? app.requestSingleInstanceLock(obj) : app.requestSingleInstanceLock(); | 
					
						
							| 
									
										
										
										
											2021-10-14 18:32:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 22:20:54 -07:00
										 |  |  | app.on('second-instance', (event, args, workingDirectory, data) => { | 
					
						
							| 
									
										
										
										
											2021-10-14 18:32:32 -07:00
										 |  |  |   setImmediate(() => { | 
					
						
							|  |  |  |     console.log([JSON.stringify(args), JSON.stringify(data)].join('||')); | 
					
						
							| 
									
										
										
										
											2022-05-22 22:20:54 -07:00
										 |  |  |     app.exit(0); | 
					
						
							| 
									
										
										
										
											2021-10-14 18:32:32 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!gotTheLock) { | 
					
						
							|  |  |  |   app.exit(1); | 
					
						
							|  |  |  | } |