@@ -20,74 +20,10 @@ const port = 3000;
2020const path_1 = require ( "path" ) ;
2121const url_1 = require ( "url" ) ;
2222const { app, BrowserWindow, Tray, Menu, dialog, autoUpdater, desktopCapturer, shell } = require ( 'electron' ) ;
23- const handleSquirrelEvent = ( ) => {
24- if ( process . argv . length === 1 || process . platform !== 'win32' ) {
25- return false ;
26- }
27- const ChildProcess = require ( 'child_process' ) ;
28- const path = require ( 'path' ) ;
29- const appFolder = path . resolve ( process . execPath , '..' ) ;
30- const rootAtomFolder = path . resolve ( appFolder , '..' ) ;
31- const updateDotExe = path . resolve ( path . join ( rootAtomFolder , 'Update.exe' ) ) ;
32- const exeName = path . basename ( process . execPath ) ;
33- const spawn = function ( command , args ) {
34- let spawnedProcess , error ;
35- try {
36- spawnedProcess = ChildProcess . spawn ( command , args , { detached : true } ) ;
37- }
38- catch ( error ) { }
39- return spawnedProcess ;
40- } ;
41- const spawnUpdate = function ( args ) {
42- return spawn ( updateDotExe , args ) ;
43- } ;
44- const squirrelEvent = process . argv [ 1 ] ;
45- switch ( squirrelEvent ) {
46- case '--squirrel-install' :
47- case '--squirrel-updated' :
48- // Optionally do things such as:
49- // - Add your .exe to the PATH
50- // - Write to the registry for things like file associations and
51- // explorer context menus
52- // Install desktop and start menu shortcuts
53- spawnUpdate ( [ '--createShortcut' , exeName ] ) ;
54- setTimeout ( app . quit , 1000 ) ;
55- return true ;
56- case '--squirrel-uninstall' :
57- // Undo anything you did in the --squirrel-install and
58- // --squirrel-updated handlers
59- // Remove desktop and start menu shortcuts
60- spawnUpdate ( [ '--removeShortcut' , exeName ] ) ;
61- setTimeout ( app . quit , 1000 ) ;
62- return true ;
63- case '--squirrel-obsolete' :
64- // This is called on the outgoing version of your app before
65- // we update to the new version - it's the opposite of
66- // --squirrel-updated
67- app . quit ( ) ;
68- return true ;
69- }
70- } ;
71- if ( handleSquirrelEvent ( ) ) {
72- // squirrel event handled and app will exit in 1000ms, so don't do anything else
73- }
74- const makeSingleInstance = ( ) => {
75- // For Mac App Store build
76- if ( process . platform === 'darwin' ) {
77- return false ;
78- }
79- return app . makeSingleInstance ( ( ) => {
80- createWindow ( ) ;
81- } ) ;
82- } ;
83- if ( makeSingleInstance ( ) ) {
84- app . quit ( ) ;
85- }
8623// squirrel event handled and app will exit in 1000ms, so don't do anything else
8724const version = app . getVersion ( ) ;
8825let localServer1 = null ;
8926let tray = null ;
90- let mainWindow = null ;
9127let doReady = false ;
9228const _doUpdate = ( tag_name , _port ) => {
9329 let url = null ;
@@ -197,7 +133,12 @@ const appReady = () => {
197133 //const menu = Menu.buildFromTemplate( template )
198134 //Menu.setApplicationMenu ( menu)
199135 if ( ! localServer1 ) {
200- localServer1 = new BrowserWindow ( { show : DEBUG } ) ;
136+ localServer1 = new BrowserWindow ( {
137+ show : DEBUG ,
138+ webPreferences : {
139+ nodeIntegration : true
140+ }
141+ } ) ;
201142 localServer1 . _doUpdate = _doUpdate ;
202143 DEBUG ? localServer1 . webContents . openDevTools ( ) : null ;
203144 //localServer1.maximize ()
@@ -207,7 +148,7 @@ const appReady = () => {
207148 slashes : true
208149 } ) ) ;
209150 setTimeout ( ( ) => {
210- shell . openExternal ( `http://127.0.0.1: ${ port } ` ) ;
151+ createWindow ( ) ;
211152 } , 2000 ) ;
212153 /*
213154 setTimeout (() => {
@@ -235,23 +176,21 @@ const appReady = () => {
235176 }
236177} ;
237178const initialize = ( ) => {
179+ const gotTheLock = app . requestSingleInstanceLock ( ) ;
180+ if ( ! gotTheLock ) {
181+ return app . quit ( ) ;
182+ }
183+ app . on ( 'second-instance' , ( event , commandLine , workingDirectory ) => {
184+ createWindow ( ) ;
185+ } ) ;
238186 app . once ( 'ready' , ( ) => {
239187 if ( doReady ) {
240188 return ;
241189 }
242190 doReady = true ;
243191 return appReady ( ) ;
244192 } ) ;
245- app . once ( 'will-finish-launching' , ( ) => {
246- /*
247- if ( doReady )
248- return
249- doReady = true
250-
251- return appReady ()
252- */
253- } ) ;
254- app . on ( 'window-all-closed' , ( ) => {
193+ app . once ( 'window-all-closed' , ( ) => {
255194 app . quit ( ) ;
256195 } ) ;
257196} ;
0 commit comments