UNPKG

sussudio

Version:

An unofficial VS Code Internal API

125 lines (124 loc) 6.44 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; import * as electron from 'electron'; import { memoize } from "../../../base/common/decorators.mjs"; import { Event } from "../../../base/common/event.mjs"; import { DisposableStore } from "../../../base/common/lifecycle.mjs"; import { IConfigurationService } from "../../configuration/common/configuration.mjs"; import { IEnvironmentMainService } from "../../environment/electron-main/environmentMainService.mjs"; import { ILifecycleMainService } from "../../lifecycle/electron-main/lifecycleMainService.mjs"; import { ILogService } from "../../log/common/log.mjs"; import { IProductService } from "../../product/common/productService.mjs"; import { IRequestService } from "../../request/common/request.mjs"; import { ITelemetryService } from "../../telemetry/common/telemetry.mjs"; import { State } from "../common/update.mjs"; import { AbstractUpdateService, createUpdateURL } from "./abstractUpdateService.mjs"; let DarwinUpdateService = class DarwinUpdateService extends AbstractUpdateService { telemetryService; disposables = new DisposableStore(); get onRawError() { return Event.fromNodeEventEmitter(electron.autoUpdater, 'error', (_, message) => message); } get onRawUpdateNotAvailable() { return Event.fromNodeEventEmitter(electron.autoUpdater, 'update-not-available'); } get onRawUpdateAvailable() { return Event.fromNodeEventEmitter(electron.autoUpdater, 'update-available', (_, url, version) => ({ url, version, productVersion: version })); } get onRawUpdateDownloaded() { return Event.fromNodeEventEmitter(electron.autoUpdater, 'update-downloaded', (_, releaseNotes, version, date) => ({ releaseNotes, version, productVersion: version, date })); } constructor(lifecycleMainService, configurationService, telemetryService, environmentMainService, requestService, logService, productService) { super(lifecycleMainService, configurationService, environmentMainService, requestService, logService, productService); this.telemetryService = telemetryService; } async initialize() { await super.initialize(); this.onRawError(this.onError, this, this.disposables); this.onRawUpdateAvailable(this.onUpdateAvailable, this, this.disposables); this.onRawUpdateDownloaded(this.onUpdateDownloaded, this, this.disposables); this.onRawUpdateNotAvailable(this.onUpdateNotAvailable, this, this.disposables); } onError(err) { this.logService.error('UpdateService error:', err); // only show message when explicitly checking for updates const shouldShowMessage = this.state.type === "checking for updates" /* StateType.CheckingForUpdates */ ? this.state.explicit : true; const message = shouldShowMessage ? err : undefined; this.setState(State.Idle(1 /* UpdateType.Archive */, message)); } buildUpdateFeedUrl(quality) { let assetID; if (!this.productService.darwinUniversalAssetId) { assetID = process.arch === 'x64' ? 'darwin' : 'darwin-arm64'; } else { assetID = this.productService.darwinUniversalAssetId; } const url = createUpdateURL(assetID, quality, this.productService); try { electron.autoUpdater.setFeedURL({ url }); } catch (e) { // application is very likely not signed this.logService.error('Failed to set update feed URL', e); return undefined; } return url; } doCheckForUpdates(context) { this.setState(State.CheckingForUpdates(context)); electron.autoUpdater.checkForUpdates(); } onUpdateAvailable(update) { if (this.state.type !== "checking for updates" /* StateType.CheckingForUpdates */) { return; } this.setState(State.Downloading(update)); } onUpdateDownloaded(update) { if (this.state.type !== "downloading" /* StateType.Downloading */) { return; } this.telemetryService.publicLog2('update:downloaded', { version: update.version }); this.setState(State.Ready(update)); } onUpdateNotAvailable() { if (this.state.type !== "checking for updates" /* StateType.CheckingForUpdates */) { return; } this.telemetryService.publicLog2('update:notAvailable', { explicit: this.state.explicit }); this.setState(State.Idle(1 /* UpdateType.Archive */)); } doQuitAndInstall() { this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()'); electron.autoUpdater.quitAndInstall(); } dispose() { this.disposables.dispose(); } }; __decorate([ memoize ], DarwinUpdateService.prototype, "onRawError", null); __decorate([ memoize ], DarwinUpdateService.prototype, "onRawUpdateNotAvailable", null); __decorate([ memoize ], DarwinUpdateService.prototype, "onRawUpdateAvailable", null); __decorate([ memoize ], DarwinUpdateService.prototype, "onRawUpdateDownloaded", null); DarwinUpdateService = __decorate([ __param(0, ILifecycleMainService), __param(1, IConfigurationService), __param(2, ITelemetryService), __param(3, IEnvironmentMainService), __param(4, IRequestService), __param(5, ILogService), __param(6, IProductService) ], DarwinUpdateService); export { DarwinUpdateService };