Skip to content

Commit

Permalink
winupdate: autocheck - manual download
Browse files Browse the repository at this point in the history
  • Loading branch information
Himanshu-Singh-Chauhan committed Feb 25, 2025
1 parent f978a8a commit 69778c0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 43 deletions.
89 changes: 47 additions & 42 deletions src/vs/platform/update/electron-main/updateService.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,47 +130,11 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
return Promise.resolve(null);
}

if (updateType === UpdateType.Archive) {
this.setState(State.AvailableForDownload(update));
return Promise.resolve(null);
}

this.setState(State.Downloading);

return this.cleanup(update.version).then(() => {
return this.getUpdatePackagePath(update.version).then(updatePackagePath => {
return pfs.Promises.exists(updatePackagePath).then(exists => {
if (exists) {
return Promise.resolve(updatePackagePath);
}

const downloadPath = `${updatePackagePath}.tmp`;

return this.requestService.request({ url: update.url }, CancellationToken.None)
.then(context => this.fileService.writeFile(URI.file(downloadPath), context.stream))
.then(update.sha256hash ? () => checksum(downloadPath, update.sha256hash) : () => undefined)
.then(() => pfs.Promises.rename(downloadPath, updatePackagePath, false /* no retry */))
.then(() => updatePackagePath);
});
}).then(packagePath => {
this.availableUpdate = { packagePath };
this.setState(State.Downloaded(update));
// NOTE: pear does not support fast updates. so we are setting the state to ready.
this.setState(State.Ready(update));

// const fastUpdatesEnabled = this.configurationService.getValue('update.enableWindowsBackgroundUpdates');
// if (fastUpdatesEnabled) {
// if (this.productService.target === 'user') {
// this.doApplyUpdate();
// }
// } else {
// this.setState(State.Ready(update));
// }
});
});
this.setState(State.AvailableForDownload(update));
return Promise.resolve(null);
})
.then(undefined, err => {
this.telemetryService.publicLog2<{ messageHash: string }, UpdateErrorClassification>('update:error', { messageHash: String(hash(String(err))) });
this.telemetryService.publicLog2<{ messageHash: string }, UpdateErrorClassification>('updateCheck:error', { messageHash: String(hash(String(err))) });
this.logService.error(err);

// only show message when explicitly checking for updates
Expand All @@ -180,10 +144,51 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
}

protected override async doDownloadUpdate(state: AvailableForDownload): Promise<void> {
if (state.update.url) {
this.nativeHostMainService.openExternal(undefined, state.update.url);
if (getUpdateType() === UpdateType.Archive) {
if (state.update.url) {
this.nativeHostMainService.openExternal(undefined, state.update.url);
}
this.setState(State.Idle(getUpdateType()));
}
this.setState(State.Idle(getUpdateType()));

if (this.state.type !== StateType.AvailableForDownload)
return;

const update = this.state.update;

this.setState(State.Downloading);

return this.cleanup(update.version).then(() => {
return this.getUpdatePackagePath(update.version).then(updatePackagePath => {
return pfs.Promises.exists(updatePackagePath).then(exists => {
if (exists) {
return Promise.resolve(updatePackagePath);
}

const downloadPath = `${updatePackagePath}.tmp`;

return this.requestService.request({ url: update.url }, CancellationToken.None)
.then(context => this.fileService.writeFile(URI.file(downloadPath), context.stream))
.then(update.sha256hash ? () => checksum(downloadPath, update.sha256hash) : () => undefined)
.then(() => pfs.Promises.rename(downloadPath, updatePackagePath, false /* no retry */))
.then(() => updatePackagePath);
});
}).then(packagePath => {
this.availableUpdate = { packagePath };
this.setState(State.Downloaded(update));
// NOTE: pear does not support fast updates. so we are setting the state to ready.
this.setState(State.Ready(update));

// const fastUpdatesEnabled = this.configurationService.getValue('update.enableWindowsBackgroundUpdates');
// if (fastUpdatesEnabled) {
// if (this.productService.target === 'user') {
// this.doApplyUpdate();
// }
// } else {
// this.setState(State.Ready(update));
// }
});
});
}

private async getUpdatePackagePath(version: string): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
align-items: center;
justify-content: center;
cursor: pointer;
border-radius: 16px;
border-radius: 8px;
padding: 6px 8px;
margin: 5px 6px;
color: var(--vscode-button-foreground);
Expand Down

0 comments on commit 69778c0

Please sign in to comment.