@codingame/monaco-vscode-update-service-override 37.2.0 → 37.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. package/package.json +2 -2
  2. package/vscode/src/vs/platform/update/common/update.config.contribution.js +18 -18
  3. package/vscode/src/vs/workbench/contrib/update/browser/postUpdateWidget.js +5 -5
  4. package/vscode/src/vs/workbench/contrib/update/browser/update.contribution.js +19 -19
  5. package/vscode/src/vs/workbench/browser/media/code-icon.svg +0 -1
  6. package/vscode/src/vs/workbench/contrib/markdown/browser/markdownSettingRenderer.d.ts +0 -43
  7. package/vscode/src/vs/workbench/contrib/markdown/browser/markdownSettingRenderer.js +0 -330
  8. package/vscode/src/vs/workbench/contrib/update/browser/media/updateTitleBarEntry.css +0 -91
  9. package/vscode/src/vs/workbench/contrib/update/browser/media/updateTooltip.css +0 -165
  10. package/vscode/src/vs/workbench/contrib/update/browser/releaseNotesEditor.d.ts +0 -67
  11. package/vscode/src/vs/workbench/contrib/update/browser/releaseNotesEditor.js +0 -646
  12. package/vscode/src/vs/workbench/contrib/update/browser/update.d.ts +0 -65
  13. package/vscode/src/vs/workbench/contrib/update/browser/update.js +0 -498
  14. package/vscode/src/vs/workbench/contrib/update/browser/updateTitleBarEntry.d.ts +0 -64
  15. package/vscode/src/vs/workbench/contrib/update/browser/updateTitleBarEntry.js +0 -364
  16. package/vscode/src/vs/workbench/contrib/update/browser/updateTooltip.d.ts +0 -61
  17. package/vscode/src/vs/workbench/contrib/update/browser/updateTooltip.js +0 -395
  18. package/vscode/src/vs/workbench/contrib/update/common/updateUtils.d.ts +0 -61
  19. package/vscode/src/vs/workbench/contrib/update/common/updateUtils.js +0 -129
@@ -1,395 +0,0 @@
1
-
2
- import { registerCss } from '@codingame/monaco-vscode-api/css';
3
- import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
4
- import { $, append, addDisposableListener, clearNode, createTextNode } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/dom';
5
- import { Codicon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/codicons';
6
- import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
7
- import { ThemeIcon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/themables';
8
- import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
9
- import { IClipboardService } from '@codingame/monaco-vscode-api/vscode/vs/platform/clipboard/common/clipboardService.service';
10
- import { ICommandService } from '@codingame/monaco-vscode-api/vscode/vs/platform/commands/common/commands.service';
11
- import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
12
- import { IHoverService } from '@codingame/monaco-vscode-api/vscode/vs/platform/hover/browser/hover.service';
13
- import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
14
- import { StateType, DisablementReason } from '@codingame/monaco-vscode-api/vscode/vs/platform/update/common/update';
15
- import { ShowCurrentReleaseNotesActionId } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/update/common/update';
16
- import { computeProgressPercent, formatBytes, computeDownloadSpeed, computeDownloadTimeRemaining, formatTimeRemaining, tryParseDate, formatDate } from '../common/updateUtils.js';
17
- import * as updateTooltip from './media/updateTooltip.css';
18
-
19
- registerCss(updateTooltip);
20
- let UpdateTooltip = class UpdateTooltip extends Disposable {
21
- constructor(
22
- clipboardService,
23
- commandService,
24
- configurationService,
25
- hoverService,
26
- productService
27
- ) {
28
- super();
29
- this.clipboardService = clipboardService;
30
- this.commandService = commandService;
31
- this.configurationService = configurationService;
32
- this.hoverService = hoverService;
33
- this.productService = productService;
34
- this.domNode = $(".update-tooltip");
35
- const header = append(this.domNode, $(".header"));
36
- this.titleNode = append(header, $(".title"));
37
- this.productInfoNode = append(this.domNode, $(".product-info"));
38
- const logoContainer = append(this.productInfoNode, $(".product-logo"));
39
- logoContainer.setAttribute("role", "img");
40
- logoContainer.setAttribute("aria-label", this.productService.nameLong);
41
- const details = append(this.productInfoNode, $(".product-details"));
42
- this.productNameNode = append(details, $(".product-name"));
43
- this.productNameNode.textContent = this.productService.nameLong;
44
- const currentVersionRow = this.createVersionRow(details);
45
- this.currentVersionNode = currentVersionRow.label;
46
- this.currentVersionCopyValue = currentVersionRow.copyValue;
47
- this.currentVersionCopyButton = currentVersionRow.copyButton;
48
- const latestVersionRow = this.createVersionRow(details);
49
- this.latestVersionNode = latestVersionRow.label;
50
- this.latestVersionCopyValue = latestVersionRow.copyValue;
51
- this.latestVersionCopyButton = latestVersionRow.copyButton;
52
- this.releaseDateNode = append(details, $(".product-release-date"));
53
- this.progressContainer = append(this.domNode, $(".progress-container"));
54
- const progressBar = append(this.progressContainer, $(".progress-bar"));
55
- this.progressFill = append(progressBar, $(".progress-fill"));
56
- const progressText = append(this.progressContainer, $(".progress-text"));
57
- this.progressPercentNode = append(progressText, $("span"));
58
- this.progressSizeNode = append(progressText, $("span"));
59
- this.downloadStatsContainer = append(this.progressContainer, $(".download-stats"));
60
- this.timeRemainingNode = append(this.downloadStatsContainer, $(".time-remaining"));
61
- this.speedInfoNode = append(this.downloadStatsContainer, $(".speed-info"));
62
- this.messageNode = append(this.domNode, $(".state-message"));
63
- this.buttonBar = append(this.domNode, $(".button-bar"));
64
- this.releaseNotesButton = append(this.buttonBar, $("button.release-notes-button"));
65
- this.releaseNotesButton.textContent = ( localize(18411, "Release Notes"));
66
- this._register(addDisposableListener(this.releaseNotesButton, "click", () => {
67
- if (this.releaseNotesVersion) {
68
- this.runCommandAndClose(ShowCurrentReleaseNotesActionId, this.releaseNotesVersion);
69
- }
70
- }));
71
- this.actionButton = append(this.buttonBar, $("button.action-button"));
72
- this._register(addDisposableListener(this.actionButton, "click", () => {
73
- const commandId = this.actionButton.dataset.commandId;
74
- if (commandId) {
75
- this.runCommandAndClose(commandId);
76
- }
77
- }));
78
- this.updateCurrentVersion();
79
- }
80
- updateCurrentVersion() {
81
- const productVersion = this.productService.version;
82
- if (productVersion) {
83
- const currentCommitId = this.productService.commit?.substring(0, 7);
84
- this.currentVersionNode.textContent = currentCommitId ? ( localize(18412, "Current Version: {0} ({1})", productVersion, currentCommitId)) : ( localize(18413, "Current Version: {0}", productVersion));
85
- this.currentVersionCopyValue.value = currentCommitId ? `${productVersion} (${this.productService.commit})` : productVersion;
86
- this.currentVersionNode.parentElement.style.display = "";
87
- this.currentVersionCopyButton.tabIndex = 0;
88
- } else {
89
- this.currentVersionNode.parentElement.style.display = "none";
90
- this.currentVersionCopyButton.tabIndex = -1;
91
- }
92
- }
93
- hideAll() {
94
- this.productInfoNode.style.display = "";
95
- this.progressContainer.style.display = "none";
96
- this.speedInfoNode.textContent = "";
97
- this.timeRemainingNode.textContent = "";
98
- this.messageNode.style.display = "none";
99
- this.actionButton.style.display = "none";
100
- this.actionButton.tabIndex = -1;
101
- this.actionButton.dataset.commandId = "";
102
- this.releaseNotesButton.style.marginRight = "";
103
- }
104
- renderState(state) {
105
- this.hideAll();
106
- switch (state.type) {
107
- case StateType.Uninitialized:
108
- this.renderUninitialized();
109
- break;
110
- case StateType.Disabled:
111
- this.renderDisabled(state);
112
- break;
113
- case StateType.Idle:
114
- this.renderIdle(state);
115
- break;
116
- case StateType.CheckingForUpdates:
117
- this.renderCheckingForUpdates();
118
- break;
119
- case StateType.AvailableForDownload:
120
- this.renderAvailableForDownload(state);
121
- break;
122
- case StateType.Downloading:
123
- this.renderDownloading(state);
124
- break;
125
- case StateType.Downloaded:
126
- this.renderDownloaded(state);
127
- break;
128
- case StateType.Updating:
129
- this.renderUpdating(state);
130
- break;
131
- case StateType.Ready:
132
- this.renderReady(state);
133
- break;
134
- case StateType.Overwriting:
135
- this.renderOverwriting(state);
136
- break;
137
- case StateType.Cancelling:
138
- this.renderCancelling();
139
- break;
140
- case StateType.Restarting:
141
- this.renderRestarting(state);
142
- break;
143
- }
144
- }
145
- renderUninitialized() {
146
- this.renderTitleAndInfo(( localize(18414, "Initializing")));
147
- this.renderMessage(( localize(18415, "Initializing update service...")));
148
- }
149
- renderDisabled(
150
- {
151
- reason
152
- }
153
- ) {
154
- this.renderTitleAndInfo(( localize(18416, "Updates Disabled")));
155
- switch (reason) {
156
- case DisablementReason.NotBuilt:
157
- this.renderMessage(( localize(18417, "Updates are not available for this build.")), Codicon.info);
158
- break;
159
- case DisablementReason.DisabledByEnvironment:
160
- this.renderMessage(( localize(18418, "Updates are disabled by the --disable-updates command line flag.")), Codicon.warning);
161
- break;
162
- case DisablementReason.ManuallyDisabled:
163
- this.renderMessage(( localize(
164
- 18419,
165
- "Updates are manually disabled. Change the \"update.mode\" setting to enable."
166
- )), Codicon.warning);
167
- break;
168
- case DisablementReason.Policy:
169
- this.renderMessage(( localize(18420, "Updates are disabled by organization policy.")), Codicon.info);
170
- break;
171
- case DisablementReason.MissingConfiguration:
172
- this.renderMessage(( localize(18421, "Updates are disabled because no update URL is configured.")), Codicon.info);
173
- break;
174
- case DisablementReason.InvalidConfiguration:
175
- this.renderMessage(( localize(18422, "Updates are disabled because the update URL is invalid.")), Codicon.error);
176
- break;
177
- case DisablementReason.RunningAsAdmin:
178
- this.renderMessage(( localize(
179
- 18423,
180
- "Updates are not available when running a user install of {0} as administrator.",
181
- this.productService.nameShort
182
- )), Codicon.warning);
183
- break;
184
- default:
185
- this.renderMessage(( localize(18424, "Updates are disabled.")), Codicon.warning);
186
- break;
187
- }
188
- }
189
- renderIdle(
190
- {
191
- error,
192
- notAvailable
193
- }
194
- ) {
195
- if (error) {
196
- this.renderTitleAndInfo(( localize(18425, "Update Error")));
197
- this.renderMessage(error, Codicon.error);
198
- return;
199
- }
200
- if (notAvailable) {
201
- this.renderTitleAndInfo(( localize(18426, "No Update Available")));
202
- this.renderMessage(( localize(18427, "There are no updates currently available.")), Codicon.info);
203
- return;
204
- }
205
- const updateMode = this.configurationService.getValue("update.mode");
206
- this.renderTitleAndInfo(( localize(18428, "Up to Date")));
207
- switch (updateMode) {
208
- case "none":
209
- this.renderMessage(( localize(18429, "Automatic updates are disabled.")), Codicon.warning);
210
- break;
211
- case "manual":
212
- this.renderMessage(( localize(
213
- 18430,
214
- "Automatic updates will be checked but not installed automatically."
215
- )));
216
- break;
217
- case "start":
218
- this.renderMessage(( localize(18431, "Updates will be applied on restart.")));
219
- break;
220
- case "default":
221
- this.renderMessage(( localize(18432, "Automatic updates are enabled. Happy Coding!")), Codicon.smiley);
222
- break;
223
- }
224
- }
225
- renderCheckingForUpdates() {
226
- this.renderTitleAndInfo(( localize(18433, "Checking for Updates")));
227
- this.renderMessage(( localize(18434, "Checking for updates, please wait...")));
228
- }
229
- renderAvailableForDownload(
230
- {
231
- update
232
- }
233
- ) {
234
- this.renderTitleAndInfo(( localize(18435, "Update Available")), update);
235
- this.renderActionButton(( localize(18436, "Download")), "update.downloadNow");
236
- }
237
- renderDownloading(state) {
238
- this.renderTitleAndInfo(( localize(18437, "Downloading Update")), state.update);
239
- const {
240
- downloadedBytes,
241
- totalBytes
242
- } = state;
243
- if (downloadedBytes !== undefined && totalBytes !== undefined && totalBytes > 0) {
244
- const percentage = computeProgressPercent(downloadedBytes, totalBytes) ?? 0;
245
- this.progressFill.style.width = `${percentage}%`;
246
- this.progressPercentNode.textContent = `${percentage}%`;
247
- this.progressSizeNode.textContent = `${formatBytes(downloadedBytes)} / ${formatBytes(totalBytes)}`;
248
- this.progressContainer.style.display = "";
249
- const speed = computeDownloadSpeed(state);
250
- if (speed !== undefined && speed > 0) {
251
- this.speedInfoNode.textContent = ( localize(18438, "{0}/s", formatBytes(speed)));
252
- }
253
- const timeRemaining = computeDownloadTimeRemaining(state);
254
- if (timeRemaining !== undefined && timeRemaining > 0) {
255
- this.timeRemainingNode.textContent = `~${formatTimeRemaining(timeRemaining)} ${( localize(18439, "remaining"))}`;
256
- }
257
- this.downloadStatsContainer.style.display = "";
258
- } else {
259
- this.renderMessage(( localize(18440, "Downloading update, please wait...")));
260
- }
261
- }
262
- renderDownloaded(
263
- {
264
- update
265
- }
266
- ) {
267
- this.renderTitleAndInfo(( localize(18441, "Update is Ready to Install")), update);
268
- this.renderActionButton(( localize(18442, "Install")), "update.install");
269
- }
270
- renderUpdating(
271
- {
272
- update,
273
- currentProgress,
274
- maxProgress
275
- }
276
- ) {
277
- this.renderTitleAndInfo(( localize(18443, "Installing Update")), update);
278
- const percentage = computeProgressPercent(currentProgress, maxProgress);
279
- if (percentage !== undefined) {
280
- this.progressFill.style.width = `${percentage}%`;
281
- this.progressPercentNode.textContent = `${percentage}%`;
282
- this.progressSizeNode.textContent = "";
283
- this.progressContainer.style.display = "";
284
- } else {
285
- this.renderMessage(( localize(18444, "Installing update, please wait...")));
286
- }
287
- }
288
- renderReady(
289
- {
290
- update
291
- }
292
- ) {
293
- if (this.configurationService.getValue("update.mode") === "manual") {
294
- this.renderTitleAndInfo(( localize(18445, "Update Installed")), update);
295
- this.renderActionButton(( localize(18446, "Restart")), "update.restart");
296
- } else {
297
- this.renderTitleAndInfo(( localize(18447, "Restart to Update")), update);
298
- }
299
- }
300
- renderOverwriting(
301
- {
302
- update
303
- }
304
- ) {
305
- this.renderTitleAndInfo(( localize(18448, "Downloading Newer Update")), update);
306
- this.renderMessage(( localize(18449, "A newer update was released. Downloading, please wait...")));
307
- }
308
- renderRestarting(
309
- {
310
- update
311
- }
312
- ) {
313
- this.renderTitleAndInfo(( localize(18450, "Restarting {0}", this.productService.nameShort)), update);
314
- this.renderMessage(( localize(18451, "Restarting to update, please wait...")));
315
- }
316
- renderCancelling() {
317
- this.renderTitleAndInfo(( localize(18452, "Cancelling Update")));
318
- this.renderMessage(( localize(18453, "Cancelling update, please wait...")));
319
- }
320
- renderTitleAndInfo(title, update) {
321
- this.titleNode.textContent = title;
322
- const version = update?.productVersion;
323
- if (version) {
324
- const updateCommitId = update.version?.substring(0, 7);
325
- this.latestVersionNode.textContent = updateCommitId ? ( localize(18454, "Latest Version: {0} ({1})", version, updateCommitId)) : ( localize(18455, "Latest Version: {0}", version));
326
- this.latestVersionCopyValue.value = updateCommitId ? `${version} (${update.version})` : version;
327
- this.latestVersionNode.parentElement.style.display = "";
328
- this.latestVersionCopyButton.tabIndex = 0;
329
- } else {
330
- this.latestVersionNode.parentElement.style.display = "none";
331
- this.latestVersionCopyButton.tabIndex = -1;
332
- }
333
- const releaseDate = update?.timestamp ?? tryParseDate(this.productService.date);
334
- if (typeof releaseDate === "number" && releaseDate > 0) {
335
- this.releaseDateNode.textContent = ( localize(18456, "Released {0}", formatDate(releaseDate)));
336
- this.releaseDateNode.style.display = "";
337
- } else {
338
- this.releaseDateNode.style.display = "none";
339
- }
340
- this.releaseNotesVersion = version ?? this.productService.version;
341
- this.releaseNotesButton.style.display = this.releaseNotesVersion ? "" : "none";
342
- this.releaseNotesButton.tabIndex = this.releaseNotesVersion ? 0 : -1;
343
- this.releaseNotesButton.style.marginRight = this.releaseNotesVersion ? "auto" : "";
344
- this.buttonBar.style.display = this.releaseNotesVersion ? "" : "none";
345
- }
346
- renderActionButton(label, commandId) {
347
- this.actionButton.textContent = label;
348
- this.actionButton.dataset.commandId = commandId;
349
- this.actionButton.style.display = "";
350
- this.actionButton.tabIndex = 0;
351
- }
352
- renderMessage(message, icon) {
353
- clearNode(this.messageNode);
354
- if (icon) {
355
- const iconNode = append(this.messageNode, $(".state-message-icon"));
356
- iconNode.classList.add(...ThemeIcon.asClassNameArray(icon));
357
- }
358
- append(this.messageNode, createTextNode(message));
359
- this.messageNode.style.display = "";
360
- }
361
- createVersionRow(parent) {
362
- const row = append(parent, $(".product-version"));
363
- const label = append(row, $("span"));
364
- const copyValue = {
365
- value: ""
366
- };
367
- const copyButton = append(row, $("a.copy-version-button"));
368
- copyButton.setAttribute("role", "button");
369
- copyButton.setAttribute("tabindex", "0");
370
- const title = ( localize(18457, "Copy"));
371
- copyButton.title = title;
372
- copyButton.setAttribute("aria-label", title);
373
- const copyIcon = append(copyButton, $(".copy-icon"));
374
- copyIcon.classList.add(...ThemeIcon.asClassNameArray(Codicon.copy));
375
- this._register(addDisposableListener(copyButton, "click", e => {
376
- e.preventDefault();
377
- e.stopPropagation();
378
- if (copyValue.value) {
379
- this.clipboardService.writeText(copyValue.value);
380
- }
381
- }));
382
- return {
383
- label,
384
- copyValue,
385
- copyButton
386
- };
387
- }
388
- runCommandAndClose(command, ...args) {
389
- this.commandService.executeCommand(command, ...args);
390
- this.hoverService.hideHover(true);
391
- }
392
- };
393
- UpdateTooltip = ( __decorate([( __param(0, IClipboardService)), ( __param(1, ICommandService)), ( __param(2, IConfigurationService)), ( __param(3, IHoverService)), ( __param(4, IProductService))], UpdateTooltip));
394
-
395
- export { UpdateTooltip };
@@ -1,61 +0,0 @@
1
- import { Downloading } from "@codingame/monaco-vscode-api/vscode/vs/platform/update/common/update";
2
- /**
3
- * Returns the progress percentage based on the current and maximum progress values.
4
- */
5
- export declare function computeProgressPercent(current: number | undefined, max: number | undefined): number | undefined;
6
- /**
7
- * Computes an estimate of remaining download time in seconds.
8
- */
9
- export declare function computeDownloadTimeRemaining(state: Downloading): number | undefined;
10
- /**
11
- * Computes the current download speed in bytes per second.
12
- */
13
- export declare function computeDownloadSpeed(state: Downloading): number | undefined;
14
- /**
15
- * Computes the version to use for fetching update info.
16
- * - If the minor version differs: returns `{major}.{minor}` (e.g., 1.108.2 -> 1.109.5 => 1.109)
17
- * - If the same minor: returns the target version as-is (e.g., 1.109.2 -> 1.109.5 => 1.109.5)
18
- */
19
- export declare function computeUpdateInfoVersion(currentVersion: string, targetVersion: string): string | undefined;
20
- /**
21
- * Computes the URL to fetch update info from.
22
- * Follows the release notes URL pattern but with `_update` suffix.
23
- */
24
- export declare function getUpdateInfoUrl(version: string): string;
25
- /**
26
- * Formats the time remaining as a human-readable string.
27
- */
28
- export declare function formatTimeRemaining(seconds: number): string;
29
- /**
30
- * Formats a byte count as a human-readable string.
31
- */
32
- export declare function formatBytes(bytes: number): string;
33
- /**
34
- * Tries to parse a date string and returns the timestamp or undefined if parsing fails.
35
- */
36
- export declare function tryParseDate(date: string | undefined): number | undefined;
37
- /**
38
- * Formats a timestamp as a localized date string.
39
- */
40
- export declare function formatDate(timestamp: number): string;
41
- /**
42
- * Formats a number to 1 decimal place, omitting ".0" for whole numbers.
43
- */
44
- export declare function formatDecimal(value: number): string;
45
- export interface IVersion {
46
- major: number;
47
- minor: number;
48
- patch: number;
49
- }
50
- /**
51
- * Parses a version string in the format "major.minor.patch" and returns an object with the components.
52
- */
53
- export declare function tryParseVersion(version: string | undefined): IVersion | undefined;
54
- /**
55
- * Processes an error message and returns a user-friendly version of it, or undefined if the error should be ignored.
56
- */
57
- export declare function preprocessError(error?: string): string | undefined;
58
- /**
59
- * Determines whether there is a major or minor version change between two versions.
60
- */
61
- export declare function isMajorMinorVersionChange(previousVersion?: string, newVersion?: string): boolean;
@@ -1,129 +0,0 @@
1
-
2
- import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
3
-
4
- function computeProgressPercent(current, max) {
5
- if (current === undefined || max === undefined || max <= 0) {
6
- return undefined;
7
- }
8
- return Math.max(Math.min(Math.round((current / max) * 100), 100), 0);
9
- }
10
- function computeDownloadTimeRemaining(state) {
11
- const {
12
- downloadedBytes,
13
- totalBytes,
14
- startTime
15
- } = state;
16
- if (downloadedBytes === undefined || totalBytes === undefined || startTime === undefined) {
17
- return undefined;
18
- }
19
- const elapsedMs = Date.now() - startTime;
20
- if (downloadedBytes <= 0 || totalBytes <= 0 || elapsedMs <= 0) {
21
- return undefined;
22
- }
23
- const remainingBytes = totalBytes - downloadedBytes;
24
- if (remainingBytes <= 0) {
25
- return 0;
26
- }
27
- const bytesPerMs = downloadedBytes / elapsedMs;
28
- if (bytesPerMs <= 0) {
29
- return undefined;
30
- }
31
- const remainingMs = remainingBytes / bytesPerMs;
32
- return Math.ceil(remainingMs / 1000);
33
- }
34
- function computeDownloadSpeed(state) {
35
- const {
36
- downloadedBytes,
37
- startTime
38
- } = state;
39
- if (downloadedBytes === undefined || startTime === undefined) {
40
- return undefined;
41
- }
42
- const elapsedMs = Date.now() - startTime;
43
- if (elapsedMs <= 0 || downloadedBytes <= 0) {
44
- return undefined;
45
- }
46
- return (downloadedBytes / elapsedMs) * 1000;
47
- }
48
- function getUpdateInfoUrl(version) {
49
- const versionLabel = version.replace(/\./g, "_").replace(/_0$/, "");
50
- return `https://code.visualstudio.com/raw/v${versionLabel}_update.md`;
51
- }
52
- function formatTimeRemaining(seconds) {
53
- const hours = seconds / 3600;
54
- if (hours >= 1) {
55
- const formattedHours = formatDecimal(hours);
56
- if (formattedHours === "1") {
57
- return localize(18458, "{0} hour", formattedHours);
58
- } else {
59
- return localize(18459, "{0} hours", formattedHours);
60
- }
61
- }
62
- const minutes = Math.floor(seconds / 60);
63
- if (minutes >= 1) {
64
- return localize(18460, "{0} min", minutes);
65
- }
66
- return localize(18461, "{0}s", seconds);
67
- }
68
- function formatBytes(bytes) {
69
- if (bytes < 1024) {
70
- return localize(18462, "{0} B", bytes);
71
- }
72
- const kb = bytes / 1024;
73
- if (kb < 1024) {
74
- return localize(18463, "{0} KB", formatDecimal(kb));
75
- }
76
- const mb = kb / 1024;
77
- if (mb < 1024) {
78
- return localize(18464, "{0} MB", formatDecimal(mb));
79
- }
80
- const gb = mb / 1024;
81
- return localize(18465, "{0} GB", formatDecimal(gb));
82
- }
83
- function tryParseDate(date) {
84
- if (date === undefined) {
85
- return undefined;
86
- }
87
- try {
88
- const parsed = Date.parse(date);
89
- return isNaN(parsed) ? undefined : parsed;
90
- } catch {
91
- return undefined;
92
- }
93
- }
94
- function formatDate(timestamp) {
95
- return ( new Date(timestamp)).toLocaleDateString(undefined, {
96
- year: "numeric",
97
- month: "short",
98
- day: "numeric"
99
- });
100
- }
101
- function formatDecimal(value) {
102
- const rounded = Math.round(value * 10) / 10;
103
- return rounded % 1 === 0 ? ( rounded.toString()) : rounded.toFixed(1);
104
- }
105
- function tryParseVersion(version) {
106
- if (version === undefined) {
107
- return undefined;
108
- }
109
- const match = /^(\d{1,10})\.(\d{1,10})\.(\d{1,10})/.exec(version);
110
- if (!match) {
111
- return undefined;
112
- }
113
- try {
114
- return {
115
- major: parseInt(match[1]),
116
- minor: parseInt(match[2]),
117
- patch: parseInt(match[3])
118
- };
119
- } catch {
120
- return undefined;
121
- }
122
- }
123
- function isMajorMinorVersionChange(previousVersion, newVersion) {
124
- const previous = tryParseVersion(previousVersion);
125
- const current = tryParseVersion(newVersion);
126
- return !!previous && !!current && (previous.major !== current.major || previous.minor !== current.minor);
127
- }
128
-
129
- export { computeDownloadSpeed, computeDownloadTimeRemaining, computeProgressPercent, formatBytes, formatDate, formatDecimal, formatTimeRemaining, getUpdateInfoUrl, isMajorMinorVersionChange, tryParseDate, tryParseVersion };