-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: platform detection after Node.js 21 (#3956)
- Loading branch information
Showing
2 changed files
with
23 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,42 +33,36 @@ interface INodeProcess { | |
nextTick: any; | ||
versions?: { | ||
electron?: string; | ||
node?: string; | ||
chrome?: string; | ||
}; | ||
type?: string; | ||
} | ||
declare const process: INodeProcess; | ||
declare const global: any; | ||
|
||
let nodeProcess: INodeProcess | undefined; | ||
if (typeof process !== 'undefined' && typeof process?.versions?.node === 'string') { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
erha19
Member
|
||
nodeProcess = process; | ||
} | ||
|
||
interface INavigator { | ||
userAgent: string; | ||
language: string; | ||
} | ||
declare const navigator: INavigator; | ||
declare const self: any; | ||
|
||
const isElectronRenderer = | ||
typeof process !== 'undefined' && | ||
typeof process.versions !== 'undefined' && | ||
typeof process.versions.electron !== 'undefined' && | ||
process.type === 'renderer'; | ||
const isElectronRenderer = typeof nodeProcess?.versions?.electron === 'string' && nodeProcess.type === 'renderer'; | ||
|
||
// OS detection | ||
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; | ||
_isWebKit = userAgent.indexOf('AppleWebKit') >= 0; | ||
} else if (typeof process === 'object') { | ||
_isWindows = process.platform === 'win32'; | ||
_isMacintosh = process.platform === 'darwin'; | ||
_isLinux = process.platform === 'linux'; | ||
if (typeof nodeProcess === 'object') { | ||
_isWindows = nodeProcess.platform === 'win32'; | ||
_isMacintosh = nodeProcess.platform === 'darwin'; | ||
_isLinux = nodeProcess.platform === 'linux'; | ||
_locale = LANGUAGE_DEFAULT; | ||
_language = LANGUAGE_DEFAULT; | ||
const rawNlsConfig = process.env['VSCODE_NLS_CONFIG']; | ||
const rawNlsConfig = nodeProcess.env['VSCODE_NLS_CONFIG']; | ||
if (rawNlsConfig) { | ||
try { | ||
const nlsConfig: NLSConfig = JSON.parse(rawNlsConfig); | ||
|
@@ -80,6 +74,15 @@ if (typeof navigator === 'object' && !isElectronRenderer) { | |
} catch (e) {} | ||
} | ||
_isNative = true; | ||
} else 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; | ||
_isWebKit = userAgent.indexOf('AppleWebKit') >= 0; | ||
} | ||
|
||
export const enum Platform { | ||
|
遇到一个问题,这里的修改可能会导致纯前端构建出错,最终导致快捷键绑定异常