@@ -486,10 +486,10 @@ index eab8591492..26668701f7 100644
486486 options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
487487diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
488488new file mode 100644
489- index 0000000000..3f53907de0
489+ index 0000000000..4042e32f74
490490--- /dev/null
491491+++ b/src/vs/server/browser/client.ts
492- @@ -0,0 +1,227 @@
492+ @@ -0,0 +1,263 @@
493493+ import { Emitter } from 'vs/base/common/event';
494494+ import { URI } from 'vs/base/common/uri';
495495+ import { localize } from 'vs/nls';
@@ -507,6 +507,7 @@ index 0000000000..3f53907de0
507507+ import 'vs/workbench/contrib/localizations/browser/localizations.contribution';
508508+ import { LocalizationsService } from 'vs/workbench/services/localizations/electron-browser/localizationsService';
509509+ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
510+ + import { Options } from 'vs/server/ipc.d';
510511+
511512+ class TelemetryService extends TelemetryChannelClient {
512513+ public constructor(
@@ -516,11 +517,46 @@ index 0000000000..3f53907de0
516517+ }
517518+ }
518519+
519- + const TELEMETRY_SECTION_ID = 'telemetry';
520+ + /**
521+ + * Remove extra slashes in a URL.
522+ + */
523+ + export const normalize = (url: string, keepTrailing = false): string => {
524+ + return url.replace(/\/\/+/g, "/").replace(/\/+$/, keepTrailing ? "/" : "");
525+ + };
526+ +
527+ + /**
528+ + * Get options embedded in the HTML from the server.
529+ + */
530+ + export const getOptions = <T extends Options>(): T => {
531+ + if (typeof document === "undefined") {
532+ + return {} as T;
533+ + }
534+ + const el = document.getElementById("coder-options");
535+ + try {
536+ + if (!el) {
537+ + throw new Error("no options element");
538+ + }
539+ + const value = el.getAttribute("data-settings");
540+ + if (!value) {
541+ + throw new Error("no options value");
542+ + }
543+ + const options = JSON.parse(value);
544+ + const parts = window.location.pathname.replace(/^\//g, "").split("/");
545+ + parts[parts.length - 1] = options.base;
546+ + const url = new URL(window.location.origin + "/" + parts.join("/"));
547+ + return {
548+ + ...options,
549+ + base: normalize(url.pathname, true),
550+ + };
551+ + } catch (error) {
552+ + console.warn(error);
553+ + return {} as T;
554+ + }
555+ + };
520556+
521- + const el = document.getElementById("vscode-disable-telemetry");
522- + const disableTelemetry = el && el.getAttribute("data-value") === "true" || false;
557+ + const options = getOptions();
523558+
559+ + const TELEMETRY_SECTION_ID = 'telemetry';
524560+ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
525561+ 'id': TELEMETRY_SECTION_ID,
526562+ 'order': 110,
@@ -530,7 +566,7 @@ index 0000000000..3f53907de0
530566+ 'telemetry.enableTelemetry': {
531567+ 'type': 'boolean',
532568+ 'description': localize('telemetry.enableTelemetry', 'Enable usage data and errors to be sent to a Microsoft online service.'),
533- + 'default': !disableTelemetry,
569+ + 'default': !options. disableTelemetry,
534570+ 'tags': ['usesOnlineServices']
535571+ }
536572+ }
@@ -625,7 +661,7 @@ index 0000000000..3f53907de0
625661+ const applyUpdate = async (): Promise<void> => {
626662+ (services.get(ILogService) as ILogService).debug("Applying update...");
627663+
628- + const response = await fetch(". /update/apply" , {
664+ + const response = await fetch(normalize(`${options.base} /update/apply`) , {
629665+ headers: { "content-type": "application/json" },
630666+ });
631667+ if (response.status !== 200) {
@@ -643,7 +679,7 @@ index 0000000000..3f53907de0
643679+ const getUpdate = async (): Promise<void> => {
644680+ (services.get(ILogService) as ILogService).debug("Checking for update...");
645681+
646- + const response = await fetch(". /update" , {
682+ + const response = await fetch(normalize(`${options.base} /update`) , {
647683+ headers: { "content-type": "application/json" },
648684+ });
649685+ if (response.status !== 200) {
@@ -1076,14 +1112,20 @@ index 0000000000..56331ff1fc
10761112+ require('../../bootstrap-amd').load('vs/server/entry');
10771113diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
10781114new file mode 100644
1079- index 0000000000..a0d1d0df54
1115+ index 0000000000..15d2ba55d1
10801116--- /dev/null
10811117+++ b/src/vs/server/ipc.d.ts
1082- @@ -0,0 +1,108 @@
1118+ @@ -0,0 +1,114 @@
10831119+ /**
10841120+ * External interfaces for integration into code-server over IPC. No vs imports
10851121+ * should be made in this file.
10861122+ */
1123+ + export interface Options {
1124+ + base: string
1125+ + commit: string
1126+ + disableTelemetry: boolean
1127+ + nlsConfiguration: NLSConfiguration
1128+ + }
10871129+
10881130+ export interface InitMessage {
10891131+ type: 'init';
0 commit comments