From eef12f873450165825f3bcb2fa931f82daaf51de Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 17 Oct 2018 12:01:34 +0200 Subject: [PATCH] Support using webpack's process: 'mock' (Microsoft/monaco-editor-webpack-plugin#17) --- src/vs/base/common/platform.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/vs/base/common/platform.ts b/src/vs/base/common/platform.ts index 4b703fc900a..864c6bdc620 100644 --- a/src/vs/base/common/platform.ts +++ b/src/vs/base/common/platform.ts @@ -27,6 +27,10 @@ interface INodeProcess { env: IProcessEnvironment; getuid(): number; nextTick: Function; + versions?: { + electron?: string; + }; + type?: string; } declare let process: INodeProcess; declare let global: any; @@ -40,8 +44,18 @@ declare let self: any; export const LANGUAGE_DEFAULT = 'en'; +const isElectronRenderer = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'renderer'); + // OS detection -if (typeof process === 'object' && typeof process.nextTick === 'function' && typeof process.platform === 'string') { +if (typeof navigator === 'object' && !isElectronRenderer) { + const userAgent = navigator.userAgent; + _isWindows = userAgent.indexOf('Windows') >= 0; + _isMacintosh = userAgent.indexOf('Macintosh') >= 0; + _isLinux = userAgent.indexOf('Linux') >= 0; + _isWeb = true; + _locale = navigator.language; + _language = _locale; +} else if (typeof process === 'object') { _isWindows = (process.platform === 'win32'); _isMacintosh = (process.platform === 'darwin'); _isLinux = (process.platform === 'linux'); @@ -60,14 +74,6 @@ if (typeof process === 'object' && typeof process.nextTick === 'function' && typ } } _isNative = true; -} else if (typeof navigator === 'object') { - const userAgent = navigator.userAgent; - _isWindows = userAgent.indexOf('Windows') >= 0; - _isMacintosh = userAgent.indexOf('Macintosh') >= 0; - _isLinux = userAgent.indexOf('Linux') >= 0; - _isWeb = true; - _locale = navigator.language; - _language = _locale; } export const enum Platform {