Skip to content

Commit ebb77a7

Browse files
authored
Add more checks, fixes microsoft#166771 (microsoft#166884)
1 parent ad9e069 commit ebb77a7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/main.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,17 +567,21 @@ async function resolveNlsConfiguration() {
567567
// valid after we have received the app ready event. This is why the
568568
// code is here.
569569

570-
// The ternary and ts-ignore can both be removed once Electron
571-
// officially adopts the getPreferredSystemLanguages API.
572-
// Ref https://github.com/microsoft/vscode/issues/159813
573-
// and https://github.com/electron/electron/pull/36035
574570
/**
575571
* @type string
576572
*/
577-
// @ts-ignore API not yet available in the official Electron
578-
let appLocale = ((product.quality === 'insider' || product.quality === 'exploration') && app?.getPreferredSystemLanguages()?.length) ?
579-
// @ts-ignore API not yet available in the official Electron
580-
app.getPreferredSystemLanguages()[0] : app.getLocale();
573+
let appLocale = app.getLocale();
574+
575+
// This if statement can be simplified once
576+
// VS Code moves to Electron 22.
577+
// Ref https://github.com/microsoft/vscode/issues/159813
578+
// and https://github.com/electron/electron/pull/36035
579+
if ((product.quality === 'insider' || product.quality === 'exploration')
580+
&& 'getPreferredSystemLanguages' in app
581+
&& typeof app.getPreferredSystemLanguages === 'function'
582+
&& app.getPreferredSystemLanguages().length) {
583+
appLocale = app.getPreferredSystemLanguages()[0];
584+
}
581585
if (!appLocale) {
582586
nlsConfiguration = { locale: 'en', availableLanguages: {} };
583587
} else {

0 commit comments

Comments
 (0)