Skip to content

Commit f073778

Browse files
authored
Add isMobile context key (microsoft#160676)
1 parent 08b86c0 commit f073778

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/vs/base/common/platform.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let _isWeb = false;
1515
let _isElectron = false;
1616
let _isIOS = false;
1717
let _isCI = false;
18+
let _isMobile = false;
1819
let _locale: string | undefined = undefined;
1920
let _language: string = LANGUAGE_DEFAULT;
2021
let _translationsConfigFile: string | undefined = undefined;
@@ -79,6 +80,7 @@ if (typeof navigator === 'object' && !isElectronRenderer) {
7980
_isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
8081
_isIOS = (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0;
8182
_isLinux = _userAgent.indexOf('Linux') >= 0;
83+
_isMobile = _userAgent?.indexOf('Mobi') >= 0;
8284
_isWeb = true;
8385

8486
const configuredLocale = nls.getConfiguredDefaultLocale(
@@ -157,6 +159,7 @@ export const isElectron = _isElectron;
157159
export const isWeb = _isWeb;
158160
export const isWebWorker = (_isWeb && typeof globals.importScripts === 'function');
159161
export const isIOS = _isIOS;
162+
export const isMobile = _isMobile;
160163
/**
161164
* Whether we run inside a CI environment, such as
162165
* GH actions or Azure Pipelines.

src/vs/platform/contextkey/common/contextkeys.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { isIOS, isLinux, isMacintosh, isWeb, isWindows } from 'vs/base/common/platform';
6+
import { isIOS, isLinux, isMacintosh, isMobile, isWeb, isWindows } from 'vs/base/common/platform';
77
import { localize } from 'vs/nls';
88
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
99

@@ -14,6 +14,7 @@ export const IsWindowsContext = new RawContextKey<boolean>('isWindows', isWindow
1414
export const IsWebContext = new RawContextKey<boolean>('isWeb', isWeb, localize('isWeb', "Whether the platform is a web browser"));
1515
export const IsMacNativeContext = new RawContextKey<boolean>('isMacNative', isMacintosh && !isWeb, localize('isMacNative', "Whether the operating system is macOS on a non-browser platform"));
1616
export const IsIOSContext = new RawContextKey<boolean>('isIOS', isIOS, localize('isIOS', "Whether the operating system is iOS"));
17+
export const IsMobileContext = new RawContextKey<boolean>('isMobile', isMobile, localize('isMobile', "Whether the platform is a mobile web browser"));
1718

1819
export const IsDevelopmentContext = new RawContextKey<boolean>('isDevelopment', false, true);
1920
export const ProductQualityContext = new RawContextKey<string>('productQualityType', '', localize('productQualityType', "Quality type of VS Code"));

0 commit comments

Comments
 (0)