From 307b58f24fceb9fd35aea6325ce028b16a77b6f3 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 7 Oct 2016 12:19:12 +0200 Subject: [PATCH] extract method --- src/vs/code/electron-main/main.ts | 47 ++++++++++++++++++------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index da2755debb6..fd59d598624 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -106,11 +106,13 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo // Setup Windows mutex let windowsMutex: Mutex = null; - try { - const Mutex = (require.__$__nodeRequire('windows-mutex')).Mutex; - windowsMutex = new Mutex(product.win32MutexName); - } catch (e) { - // noop + if (platform.isWindows) { + try { + const Mutex = (require.__$__nodeRequire('windows-mutex')).Mutex; + windowsMutex = new Mutex(product.win32MutexName); + } catch (e) { + // noop + } } // Register Main IPC services @@ -265,6 +267,25 @@ function setupIPC(accessor: ServicesAccessor): TPromise { const logService = accessor.get(ILogService); const environmentService = accessor.get(IEnvironmentService); + function allowSetForegroundWindow(service: LaunchChannelClient): TPromise { + let promise = TPromise.as(null); + if (platform.isWindows) { + promise = service.getMainProcessId() + .then(processId => { + logService.log('Sending some foreground love to the running instance:', processId); + + try { + const { allowSetForegroundWindow } = require.__$__nodeRequire('windows-foreground-love'); + allowSetForegroundWindow(processId); + } catch (e) { + // noop + } + }); + } + + return promise; + } + function setup(retry: boolean): TPromise { return serve(environmentService.mainIPCHandle).then(server => { if (platform.isMacintosh) { @@ -299,21 +320,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise { const channel = client.getChannel('launch'); const service = new LaunchChannelClient(channel); - let promise = TPromise.as(null); - if (platform.isWindows) { - promise = service.getMainProcessId() - .then(processId => { - logService.log('Sending some foreground love to the running instance:', processId); - try { - const { allowSetForegroundWindow } = require.__$__nodeRequire('windows-foreground-love'); - allowSetForegroundWindow(processId); - } catch (e) { - // noop - } - }); - } - - return promise + return allowSetForegroundWindow(service) .then(() => service.start(environmentService.args, process.env)) .then(() => client.dispose()) .then(() => TPromise.wrapError('Sent env to running instance. Terminating...')); -- GitLab