Skip to content

Commit

Permalink
Switch update logic to use Download Center based metadata links (#25677
Browse files Browse the repository at this point in the history
…) (#25682)

* switch to client side update

* lower version to 1.47 for testing

* cleanup

* move download center def/links to one file

* more sql carbon tags

* revert version change

* move urls to product.json

* fix isLatestVersion

* fix Mac meatdata urls
  • Loading branch information
caohai authored Jun 11, 2024
1 parent 4970733 commit 9c28bca
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 20 deletions.
4 changes: 4 additions & 0 deletions product.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"gettingStartedUrl": "https://go.microsoft.com/fwlink/?linkid=862039",
"releaseNotesUrl": "https://go.microsoft.com/fwlink/?linkid=875578",
"documentationUrl": "https://go.microsoft.com/fwlink/?linkid=862277",
"updateMetadataUrl": "https://go.microsoft.com/fwlink/?linkid=2274438",
"updateMetadataMacUrl": "https://go.microsoft.com/fwlink/?linkid=2274285",
"updateMetadataMacArmUrl": "https://go.microsoft.com/fwlink/?linkid=2274463",
"updateMetadataMacUniversalUrl": "https://go.microsoft.com/fwlink/?linkid=2274286",
"vscodeVersion": "1.82.0",
"commit": "9ca6200018fc206d67a47229f991901a8a453781",
"date": "2017-12-15T12:00:00.000Z",
Expand Down
4 changes: 4 additions & 0 deletions src/vs/base/common/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export interface IProductConfiguration {
readonly vscodeVersion: string; // {{SQL CARBON EDIT}} add vscode version
readonly gettingStartedUrl: string; // {{SQL CARBON EDIT}}
readonly disabledFeatures?: string[]; // {{SQL CARBON EDIT}}
readonly updateMetadataUrl: string; // {{SQL CARBON EDIT}}
readonly updateMetadataMacUrl: string; // {{SQL CARBON EDIT}} Mac update uses electron auto updater which has a format requirement for the update metadata feed.
readonly updateMetadataMacArmUrl: string; // {{SQL CARBON EDIT}}
readonly updateMetadataMacUniversalUrl: string; // {{SQL CARBON EDIT}}

readonly crashReporter?: {
readonly companyName: string;
Expand Down
16 changes: 10 additions & 6 deletions src/vs/platform/update/electron-main/abstractUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/e
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { ILogService } from 'vs/platform/log/common/log';
import { IProductService } from 'vs/platform/product/common/productService';
import { IRequestService } from 'vs/platform/request/common/request';
import { IRequestService, asJson } from 'vs/platform/request/common/request'; // {{SQL CARBON EDIT}}
import { AvailableForDownload, DisablementReason, IUpdateService, State, StateType, UpdateType } from 'vs/platform/update/common/update';
import { Build, getUpdateFromBuild } from 'vs/platform/update/electron-main/updateMetadataProvider'; // {{SQL CARBON EDIT}}

export function createUpdateURL(platform: string, quality: string, productService: IProductService): string {
return `${productService.updateUrl}/api/update/${platform}/${quality}/${productService.commit}`;
Expand All @@ -29,6 +30,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
declare readonly _serviceBrand: undefined;

protected url: string | undefined;
protected platform: string | undefined; // {{SQL CARBON EDIT}}

private _state: State = State.Uninitialized;

Expand Down Expand Up @@ -89,6 +91,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
return;
}

this.platform = this.buildPlatform(); // {{SQL CARBON EDIT}}
this.url = this.buildUpdateFeedUrl(quality);
if (!this.url) {
this.setState(State.Disabled(DisablementReason.InvalidConfiguration));
Expand Down Expand Up @@ -199,11 +202,11 @@ export abstract class AbstractUpdateService implements IUpdateService {
}

try {
const context = await this.requestService.request({ url: this.url }, CancellationToken.None);
// The update server replies with 204 (No Content) when no
// update is available - that's all we want to know.
return context.res.statusCode === 204;

// {{SQL CARBON EDIT}} - Use the metadata files from the Download Center as the update feed.
// If we don't have a update, then we are on the latest version.
const build = await asJson<Build | null>(await this.requestService.request({ url: this.productService.updateMetadataUrl }, CancellationToken.None));
const update = getUpdateFromBuild(build, this.productService, this.platform);
return update === undefined;
} catch (error) {
this.logService.error('update#isLatestVersion(): failed to check for updates');
this.logService.error(error);
Expand All @@ -223,6 +226,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
// noop
}

protected abstract buildPlatform(): string | undefined; // {{SQL CARBON EDIT}}
protected abstract buildUpdateFeedUrl(quality: string): string | undefined;
protected abstract doCheckForUpdates(context: any): void;
}
54 changes: 54 additions & 0 deletions src/vs/platform/update/electron-main/updateMetadataProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// {{SQL CARBON EDIT}} - This file contains interfaces, util functions and url definitions
// to support Download Center based update.
import { IProductService } from 'vs/platform/product/common/productService';
import { IUpdate } from 'vs/platform/update/common/update';

export interface Asset {
platform: string;
type: string;
url: string;
mooncakeUrl: string;
hash: string;
sha256hash?: string;
packageCatalog?: string;
repoDefinition?: string;
repoDataFiles?: string[];
}

export interface Build {
id: string;
version: string;
isFrozen?: boolean;
assets: Asset[];
updates: { [platform: string]: string; };
}

export function getUpdateFromBuild(build: Build | null, productService: IProductService, platform: string): IUpdate | undefined {
if (!build) {
return undefined;
}

if (build.id === productService.commit) {
return undefined;
}

const assetType = build.updates[platform];
const asset = build.assets.filter(a => a.platform === platform && a.type === assetType)[0];

if (!asset) {
return undefined;
}

const url = asset.url;
return {
url: url,
version: build.id,
productVersion: build.version,
hash: asset.hash,
};
}
21 changes: 16 additions & 5 deletions src/vs/platform/update/electron-main/updateService.darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { IRequestService } from 'vs/platform/request/common/request';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IUpdate, State, StateType, UpdateType } from 'vs/platform/update/common/update';
import { AbstractUpdateService, createUpdateURL, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
import { AbstractUpdateService, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService'; // {{SQL CARBON EDIT}}

export class DarwinUpdateService extends AbstractUpdateService implements IRelaunchHandler {

Expand Down Expand Up @@ -71,14 +71,25 @@ export class DarwinUpdateService extends AbstractUpdateService implements IRelau
this.setState(State.Idle(UpdateType.Archive, message));
}

// {{SQL CARBON EDIT}}
protected buildPlatform(): string {
if (!this.productService.darwinUniversalAssetId) {
return process.arch === 'x64' ? 'darwin' : 'darwin-arm64';
} else {
return 'darwin-universal';
}
}

protected buildUpdateFeedUrl(quality: string): string | undefined {
let assetID: string;
let url: string;

// {{SQL CARBON EDIT}} - Use the metadata files from the Download Center as the update feed.
if (!this.productService.darwinUniversalAssetId) {
assetID = process.arch === 'x64' ? 'darwin' : 'darwin-arm64';
url = process.arch === 'x64' ? this.productService.updateMetadataMacUrl : this.productService.updateMetadataMacArmUrl;
} else {
assetID = this.productService.darwinUniversalAssetId;
url = this.productService.updateMetadataMacUniversalUrl;
}
const url = createUpdateURL(assetID, quality, this.productService);

try {
electron.autoUpdater.setFeedURL({ url });
} catch (e) {
Expand Down
17 changes: 13 additions & 4 deletions src/vs/platform/update/electron-main/updateService.linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeH
import { IProductService } from 'vs/platform/product/common/productService';
import { asJson, IRequestService } from 'vs/platform/request/common/request';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { AvailableForDownload, IUpdate, State, UpdateType } from 'vs/platform/update/common/update';
import { AvailableForDownload, State, UpdateType } from 'vs/platform/update/common/update'; // {{SQL CARBON EDIT}}
import { AbstractUpdateService, createUpdateURL, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
import { Build, getUpdateFromBuild } from 'vs/platform/update/electron-main/updateMetadataProvider'; // {{SQL CARBON EDIT}}

export class LinuxUpdateService extends AbstractUpdateService {

Expand All @@ -30,6 +31,11 @@ export class LinuxUpdateService extends AbstractUpdateService {
super(lifecycleMainService, configurationService, environmentMainService, requestService, logService, productService);
}

// {{SQL CARBON EDIT}}
protected buildPlatform(): string {
return `linux-${process.arch}`;
}

protected buildUpdateFeedUrl(quality: string): string {
return createUpdateURL(`linux-${process.arch}`, quality, this.productService);
}
Expand All @@ -40,9 +46,12 @@ export class LinuxUpdateService extends AbstractUpdateService {
}

this.setState(State.CheckingForUpdates(context));
this.requestService.request({ url: this.url }, CancellationToken.None)
.then<IUpdate | null>(asJson)
.then(update => {

// {{SQL CARBON EDIT}} - Use the metadata files from the Download Center as the update feed.
this.requestService.request({ url: this.productService.updateMetadataUrl }, CancellationToken.None)
.then<Build | null>(asJson)
.then(build => {
const update = getUpdateFromBuild(build, this.productService, `linux-${process.arch}`);
if (!update || !update.url || !update.version || !update.productVersion) {
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });

Expand Down
17 changes: 12 additions & 5 deletions src/vs/platform/update/electron-main/updateService.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { asJson, IRequestService } from 'vs/platform/request/common/request';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { AvailableForDownload, DisablementReason, IUpdate, State, StateType, UpdateType } from 'vs/platform/update/common/update';
import { AbstractUpdateService, createUpdateURL, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
import { Build, getUpdateFromBuild } from 'vs/platform/update/electron-main/updateMetadataProvider'; // {{SQL CARBON EDIT}}

async function pollUntil(fn: () => boolean, millis = 1000): Promise<void> {
while (!fn()) {
Expand Down Expand Up @@ -98,7 +99,8 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
await super.initialize();
}

protected buildUpdateFeedUrl(quality: string): string | undefined {
// {{SQL CARBON EDIT}}
protected buildPlatform(): string {
let platform = 'win32';

if (process.arch !== 'ia32') {
Expand All @@ -110,8 +112,11 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
} else if (this.productService.target === 'user') {
platform += '-user';
}
return platform;
}

return createUpdateURL(platform, quality, this.productService);
protected buildUpdateFeedUrl(quality: string): string | undefined {
return createUpdateURL(this.platform, quality, this.productService); // {{SQL CARBON EDIT}}
}

protected doCheckForUpdates(context: any): void {
Expand All @@ -121,9 +126,11 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun

this.setState(State.CheckingForUpdates(context));

this.requestService.request({ url: this.url }, CancellationToken.None)
.then<IUpdate | null>(asJson)
.then(update => {
// {{SQL CARBON EDIT}} - Use the metadata files from the Download Center as the update feed.
this.requestService.request({ url: this.productService.updateMetadataUrl }, CancellationToken.None)
.then<Build | null>(asJson)
.then(build => {
const update = getUpdateFromBuild(build, this.productService, this.platform);
const updateType = getUpdateType();

if (!update || !update.url || !update.version || !update.productVersion) {
Expand Down

0 comments on commit 9c28bca

Please sign in to comment.