From b5c8a1e709e7a8ac79e287095a6571efff6d72fd Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Wed, 10 Mar 2021 00:09:43 +0800 Subject: [PATCH] refactor: move service init after gotTheLock --- src/main.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main.ts b/src/main.ts index 624919ad..e09480a2 100755 --- a/src/main.ts +++ b/src/main.ts @@ -31,31 +31,31 @@ import { IWorkspaceViewService } from './services/workspacesView/interface'; const gotTheLock = app.requestSingleInstanceLock(); -bindServiceAndProxy(); -const menuService = container.get(serviceIdentifier.MenuService); -const nativeService = container.get(serviceIdentifier.NativeService); -const preferenceService = container.get(serviceIdentifier.Preference); -const wikiService = container.get(serviceIdentifier.Wiki); -const windowService = container.get(serviceIdentifier.Window); -const workspaceService = container.get(serviceIdentifier.Workspace); -const workspaceViewService = container.get(serviceIdentifier.WorkspaceView); - logger.info('App booting'); -app.on('second-instance', () => { - // Someone tried to run a second instance, we should focus our window. - const mainWindow = windowService.get(WindowNames.main); - if (mainWindow !== undefined) { - if (mainWindow.isMinimized()) { - mainWindow.restore(); - } - mainWindow.focus(); - } -}); + if (!gotTheLock) { logger.info('Quitting dut to we only allow one instance to run.'); console.info('Quitting dut to we only allow one instance to run.'); app.quit(); } else { + bindServiceAndProxy(); + const menuService = container.get(serviceIdentifier.MenuService); + const nativeService = container.get(serviceIdentifier.NativeService); + const preferenceService = container.get(serviceIdentifier.Preference); + const wikiService = container.get(serviceIdentifier.Wiki); + const windowService = container.get(serviceIdentifier.Window); + const workspaceService = container.get(serviceIdentifier.Workspace); + const workspaceViewService = container.get(serviceIdentifier.WorkspaceView); + app.on('second-instance', () => { + // Someone tried to run a second instance, we should focus our window. + const mainWindow = windowService.get(WindowNames.main); + if (mainWindow !== undefined) { + if (mainWindow.isMinimized()) { + mainWindow.restore(); + } + mainWindow.focus(); + } + }); // make sure "Settings" file exists // if not, ignore this chunk of code // as using electron-settings before app.on('ready') and "Settings" is created