-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add nlsConfig to webWorker #192808 #199258
base: main
Are you sure you want to change the base?
Changes from 4 commits
1f40cff
25de25f
01f5819
8faf47c
0167ea5
ee0f46f
58dabe3
a88dc1a
7b5f677
c91d6fa
415cbe0
5b99eba
ad14cc9
28b02c2
e7c58a3
0048b55
4f221a3
ab58c3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -83,9 +83,10 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost | |||||||||||||||
} | ||||||||||||||||
COI.addSearchParam(suffixSearchParams, true, true); | ||||||||||||||||
|
||||||||||||||||
const suffix = `?${suffixSearchParams.toString()}`; | ||||||||||||||||
let suffix = `?${suffixSearchParams.toString()}`; | ||||||||||||||||
|
||||||||||||||||
const iframeModulePath = 'vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html'; | ||||||||||||||||
const locale = localStorage.getItem('vscode.nls.locale') || navigator.language.toLowerCase(); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is running on the main side, I think you can just use vscode/src/vs/base/common/platform.ts Lines 182 to 188 in 7a104d4
the implementation of this will grab the local storage value or navigator value. |
||||||||||||||||
if (platform.isWeb) { | ||||||||||||||||
const webEndpointUrlTemplate = this._productService.webEndpointUrlTemplate; | ||||||||||||||||
const commit = this._productService.commit; | ||||||||||||||||
|
@@ -109,12 +110,19 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost | |||||||||||||||
const res = new URL(`${baseUrl}/out/${iframeModulePath}${suffix}`); | ||||||||||||||||
res.searchParams.set('parentOrigin', mainWindow.origin); | ||||||||||||||||
res.searchParams.set('salt', stableOriginUUID); | ||||||||||||||||
if (locale !== 'en') { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, also in platform there is a LANGUAGE_DEFAULT which you can use instead of hardcoding 'en' |
||||||||||||||||
res.searchParams.set('locale', locale); | ||||||||||||||||
} | ||||||||||||||||
return res.toString(); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
console.warn(`The web worker extension host is started in a same-origin iframe!`); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (locale !== 'en') { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too |
||||||||||||||||
suffixSearchParams.set('locale', locale); | ||||||||||||||||
suffix = `?${suffixSearchParams.toString()}`; | ||||||||||||||||
} | ||||||||||||||||
const relativeExtensionHostIframeSrc = FileAccess.asBrowserUri(iframeModulePath); | ||||||||||||||||
return `${relativeExtensionHostIframeSrc.toString(true)}${suffix}`; | ||||||||||||||||
} | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
const name = searchParams.get('debugged') ? 'DebugWorkerExtensionHost' : 'WorkerExtensionHost'; | ||
const parentOrigin = searchParams.get('parentOrigin') || window.origin; | ||
const salt = searchParams.get('salt'); | ||
const locale = searchParams.get('locale'); | ||
|
||
(async function () { | ||
const hostnameValidationMarker = 'v--'; | ||
|
@@ -73,6 +74,10 @@ | |
} | ||
|
||
const worker = new Worker(workerUrl, { name }); | ||
if (locale) { | ||
// send before `vs/workbench/api/worker/extensionHostWorker`load event. | ||
worker.postMessage(`worker:init-locale:${locale}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the worker cannot read the localstorge directly and the iframe may not be in the same domain name as the main application, the method used is to obtain the language in the host, pass it to the iframe, and then pass it to the worker. I don't know if this will be strange |
||
} | ||
worker.postMessage('vs/workbench/api/worker/extensionHostWorker'); | ||
const nestedWorkers = new Map(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you could just do this:
and get rid of the other changes in this file.