From 5d9853d679a3f3437ce3f345baed71234a90a9e9 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 30 Nov 2015 18:09:00 +0100 Subject: [PATCH] call CreateMutex whenever Code is running --- src/typings/windows-mutex.ts | 12 ++++++++++++ src/vs/workbench/electron-main/main.ts | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/typings/windows-mutex.ts diff --git a/src/typings/windows-mutex.ts b/src/typings/windows-mutex.ts new file mode 100644 index 00000000000..039dffcc2ad --- /dev/null +++ b/src/typings/windows-mutex.ts @@ -0,0 +1,12 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'windows-mutex' { + export class Mutex { + constructor(name: string); + isActive(): boolean; + release(): void; + } +} \ No newline at end of file diff --git a/src/vs/workbench/electron-main/main.ts b/src/vs/workbench/electron-main/main.ts index 1a26f9a059a..2970c2fee28 100644 --- a/src/vs/workbench/electron-main/main.ts +++ b/src/vs/workbench/electron-main/main.ts @@ -9,7 +9,6 @@ import app = require('app'); import fs = require('fs'); import dialog = require('dialog'); import shell = require('shell'); - import nls = require('vs/nls'); import {assign} from 'vs/base/common/objects'; import platform = require('vs/base/common/platform'); @@ -233,6 +232,15 @@ function setupIPC(): TPromise { return setup(true); } +function setupMutex() { + try { + var Mutex = ( require.__$__nodeRequire('windows-mutex')).Mutex; + new Mutex('vscode'); + } catch (e) { + // noop + } +} + // On some platforms we need to manually read from the global environment variables // and assign them to the process environment (e.g. when doubleclick app on Mac) getUserEnvironment() @@ -241,6 +249,7 @@ getUserEnvironment() return timebomb() .then(setupIPC) + .then(ipcServer => { setupMutex(); return ipcServer; }) .then(ipcServer => main(ipcServer, userEnv)); }) .done(null, quit); -- GitLab