From ebb77a7dfd1095cb7162ea9c7ef2c0fbbba6678a Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Mon, 21 Nov 2022 11:28:55 -0800 Subject: [PATCH] Add more checks, fixes #166771 (#166884) --- src/main.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index 53299affc83..eec37545ad2 100644 --- a/src/main.js +++ b/src/main.js @@ -567,17 +567,21 @@ async function resolveNlsConfiguration() { // valid after we have received the app ready event. This is why the // code is here. - // The ternary and ts-ignore can both be removed once Electron - // officially adopts the getPreferredSystemLanguages API. - // Ref https://github.com/microsoft/vscode/issues/159813 - // and https://github.com/electron/electron/pull/36035 /** * @type string */ - // @ts-ignore API not yet available in the official Electron - let appLocale = ((product.quality === 'insider' || product.quality === 'exploration') && app?.getPreferredSystemLanguages()?.length) ? - // @ts-ignore API not yet available in the official Electron - app.getPreferredSystemLanguages()[0] : app.getLocale(); + let appLocale = app.getLocale(); + + // This if statement can be simplified once + // VS Code moves to Electron 22. + // Ref https://github.com/microsoft/vscode/issues/159813 + // and https://github.com/electron/electron/pull/36035 + if ((product.quality === 'insider' || product.quality === 'exploration') + && 'getPreferredSystemLanguages' in app + && typeof app.getPreferredSystemLanguages === 'function' + && app.getPreferredSystemLanguages().length) { + appLocale = app.getPreferredSystemLanguages()[0]; + } if (!appLocale) { nlsConfiguration = { locale: 'en', availableLanguages: {} }; } else {