import { AllPublishOptions } from "builder-util-runtime" import { AppAdapter } from "./AppAdapter" import { DownloadUpdateOptions } from "./AppUpdater" import { BaseUpdater, InstallOptions } from "./BaseUpdater" import { findFile } from "./providers/Provider" import { DOWNLOAD_PROGRESS } from "./types" export class DebUpdater extends BaseUpdater { constructor(options?: AllPublishOptions | null, app?: AppAdapter) { super(options, app) } /*** @private */ protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise> { const provider = downloadUpdateOptions.updateInfoAndProvider.provider const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "deb", ["AppImage", "rpm", "pacman"])! return this.executeDownload({ fileExtension: "deb", fileInfo, downloadUpdateOptions, task: async (updateFile, downloadOptions) => { if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) { downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it) } await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions) }, }) } protected get installerPath(): string | null { return super.installerPath?.replace(/ /g, "\\ ") ?? null } protected doInstall(options: InstallOptions): boolean { const sudo = this.wrapSudo() // pkexec doesn't want the command to be wrapped in " quotes const wrapper = /pkexec/i.test(sudo) ? "" : `"` const installerPath = this.installerPath if (installerPath == null) { this.dispatchError(new Error("No valid update available, can't quit and install")) return false } const cmd = ["dpkg", "-i", installerPath, "||", "apt-get", "install", "-f", "-y"] this.spawnSyncLog(sudo, [`${wrapper}/bin/bash`, "-c", `'${cmd.join(" ")}'${wrapper}`]) if (options.isForceRunAfter) { this.app.relaunch() } return true } }