src/vs/workbench/contrib/update/common/updateUtils.ts
227 LOC · 208 covered · 19 uncovered · 63 ranges · 46 concepts · 42 introducers · 36 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
updateUtils.ts ×13
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from '../../../../nls.js';
import { Downloading } from '../../../../platform/update/common/update.js';
/**
* Returns the progress percentage based on the current and maximum progress values.
*/
export function computeProgressPercent(current: number | undefined, max: number | undefined): number | undefined {
}
return Math.max(Math.min(Math.round((current / max) * 100), 100), 0);
}
/**
* Computes an estimate of remaining download time in seconds.
*/
export function computeDownloadTimeRemaining(state: Downloading): number | undefined {
if (downloadedBytes === undefined || totalBytes === undefined || startTime === undefined) {
}
const elapsedMs = Date.now() - startTime;
if (downloadedBytes <= 0 || totalBytes <= 0 || elapsedMs <= 0) {
}
const remainingBytes = totalBytes - downloadedBytes;
if (remainingBytes <= 0) {
}
const bytesPerMs = downloadedBytes / elapsedMs;
if (bytesPerMs <= 0) {
return undefined;
}
const remainingMs = remainingBytes / bytesPerMs;
return Math.ceil(remainingMs / 1000);
}
/**
* Computes the current download speed in bytes per second.
*/
export function computeDownloadSpeed(state: Downloading): number | undefined {
if (downloadedBytes === undefined || startTime === undefined) {
}
const elapsedMs = Date.now() - startTime;
}
return (downloadedBytes / elapsedMs) * 1000;
}
/**
* Computes the version to use for fetching update info.
* - If the minor version differs: returns `{major}.{minor}` (e.g., 1.108.2 -> 1.109.5 => 1.109)
* - If the same minor: returns the target version as-is (e.g., 1.109.2 -> 1.109.5 => 1.109.5)
*/
export function computeUpdateInfoVersion(currentVersion: string, targetVersion: string): string | undefined {
const target = tryParseVersion(targetVersion);
if (!current || !target) {
}
}
return `${target.major}.${target.minor}.${target.patch}`;
}
/**
* Computes the URL to fetch update info from.
* Follows the release notes URL pattern but with `_update` suffix.
*/
export function getUpdateInfoUrl(version: string): string {
return `https://code.visualstudio.com/raw/v${versionLabel}_update.md`;
}
/**
* Formats the time remaining as a human-readable string.
*/
export function formatTimeRemaining(seconds: number): string {
if (hours >= 1) {
if (formattedHours === '1') {
return localize('update.timeRemainingHour', "{0} hour", formattedHours);
} else {
return localize('update.timeRemainingHours', "{0} hours", formattedHours);
}
}
const minutes = Math.floor(seconds / 60);
if (minutes >= 1) {
}
return localize('update.timeRemainingSeconds', "{0}s", seconds);
}
/**
* Formats a byte count as a human-readable string.
*/
export function formatBytes(bytes: number): string {
}
const kb = bytes / 1024;
if (kb < 1024) {
}
const mb = kb / 1024;
if (mb < 1024) {
}
const gb = mb / 1024;
return localize('update.gigabytes', "{0} GB", formatDecimal(gb));
}
/**
* Tries to parse a date string and returns the timestamp or undefined if parsing fails.
*/
export function tryParseDate(date: string | undefined): number | undefined {
}
try {
const parsed = Date.parse(date);
} catch {
return undefined;
}
/**
* Formats a timestamp as a localized date string.
*/
export function formatDate(timestamp: number): string {
year: 'numeric',
month: 'short',
day: 'numeric'
});
}
/**
* Formats a number to 1 decimal place, omitting ".0" for whole numbers.
*/
export function formatDecimal(value: number): string {
return rounded % 1 === 0 ? rounded.toString() : rounded.toFixed(1);
}
export interface IVersion {
major: number;
minor: number;
patch: number;
}
/**
* Parses a version string in the format "major.minor.patch" and returns an object with the components.
*/
export function tryParseVersion(version: string | undefined): IVersion | undefined {
}
const match = /^(\d{1,10})\.(\d{1,10})\.(\d{1,10})/.exec(version);
if (!match) {
}
try {
return {
major: parseInt(match[1]),
minor: parseInt(match[2]),
patch: parseInt(match[3])
};
} catch {
return undefined;
}
/**
* Processes an error message and returns a user-friendly version of it, or undefined if the error should be ignored.
*/
export function preprocessError(error?: string): string | undefined {
if (!error) {
return undefined;
}
if (/The request timed out|The network connection was lost/i.test(error)) {
return undefined;
}
return error.replace(
/See https:\/\/github\.com\/Squirrel\/Squirrel\.Mac\/issues\/182 for more information/,
'This might mean the application was put on quarantine by macOS. See [this link](https://github.com/microsoft/vscode/issues/7426#issuecomment-425093469) for more information'
);
}
/**
* Determines whether there is a major or minor version change between two versions.
*/
export function isMajorMinorVersionChange(previousVersion?: string, newVersion?: string): boolean {
const current = tryParseVersion(newVersion);
return !!previous && !!current && (previous.major !== current.major || previous.minor !== current.minor);
}