@@ -486,10 +486,10 @@ index eab8591492..26668701f7 100644
486
486
options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
487
487
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
488
488
new file mode 100644
489
- index 0000000000..3f53907de0
489
+ index 0000000000..4042e32f74
490
490
--- /dev/null
491
491
+++ b/src/vs/server/browser/client.ts
492
- @@ -0,0 +1,227 @@
492
+ @@ -0,0 +1,263 @@
493
493
+ import { Emitter } from 'vs/base/common/event';
494
494
+ import { URI } from 'vs/base/common/uri';
495
495
+ import { localize } from 'vs/nls';
@@ -507,6 +507,7 @@ index 0000000000..3f53907de0
507
507
+ import 'vs/workbench/contrib/localizations/browser/localizations.contribution';
508
508
+ import { LocalizationsService } from 'vs/workbench/services/localizations/electron-browser/localizationsService';
509
509
+ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
510
+ + import { Options } from 'vs/server/ipc.d';
510
511
+
511
512
+ class TelemetryService extends TelemetryChannelClient {
512
513
+ public constructor(
@@ -516,11 +517,46 @@ index 0000000000..3f53907de0
516
517
+ }
517
518
+ }
518
519
+
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
+ + };
520
556
+
521
- + const el = document.getElementById("vscode-disable-telemetry");
522
- + const disableTelemetry = el && el.getAttribute("data-value") === "true" || false;
557
+ + const options = getOptions();
523
558
+
559
+ + const TELEMETRY_SECTION_ID = 'telemetry';
524
560
+ Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
525
561
+ 'id': TELEMETRY_SECTION_ID,
526
562
+ 'order': 110,
@@ -530,7 +566,7 @@ index 0000000000..3f53907de0
530
566
+ 'telemetry.enableTelemetry': {
531
567
+ 'type': 'boolean',
532
568
+ 'description': localize('telemetry.enableTelemetry', 'Enable usage data and errors to be sent to a Microsoft online service.'),
533
- + 'default': !disableTelemetry,
569
+ + 'default': !options. disableTelemetry,
534
570
+ 'tags': ['usesOnlineServices']
535
571
+ }
536
572
+ }
@@ -625,7 +661,7 @@ index 0000000000..3f53907de0
625
661
+ const applyUpdate = async (): Promise<void> => {
626
662
+ (services.get(ILogService) as ILogService).debug("Applying update...");
627
663
+
628
- + const response = await fetch(". /update/apply" , {
664
+ + const response = await fetch(normalize(`${options.base} /update/apply`) , {
629
665
+ headers: { "content-type": "application/json" },
630
666
+ });
631
667
+ if (response.status !== 200) {
@@ -643,7 +679,7 @@ index 0000000000..3f53907de0
643
679
+ const getUpdate = async (): Promise<void> => {
644
680
+ (services.get(ILogService) as ILogService).debug("Checking for update...");
645
681
+
646
- + const response = await fetch(". /update" , {
682
+ + const response = await fetch(normalize(`${options.base} /update`) , {
647
683
+ headers: { "content-type": "application/json" },
648
684
+ });
649
685
+ if (response.status !== 200) {
@@ -1076,14 +1112,20 @@ index 0000000000..56331ff1fc
1076
1112
+ require('../../bootstrap-amd').load('vs/server/entry');
1077
1113
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
1078
1114
new file mode 100644
1079
- index 0000000000..a0d1d0df54
1115
+ index 0000000000..15d2ba55d1
1080
1116
--- /dev/null
1081
1117
+++ b/src/vs/server/ipc.d.ts
1082
- @@ -0,0 +1,108 @@
1118
+ @@ -0,0 +1,114 @@
1083
1119
+ /**
1084
1120
+ * External interfaces for integration into code-server over IPC. No vs imports
1085
1121
+ * should be made in this file.
1086
1122
+ */
1123
+ + export interface Options {
1124
+ + base: string
1125
+ + commit: string
1126
+ + disableTelemetry: boolean
1127
+ + nlsConfiguration: NLSConfiguration
1128
+ + }
1087
1129
+
1088
1130
+ export interface InitMessage {
1089
1131
+ type: 'init';
0 commit comments