Skip to content

Commit

Permalink
feat: implement autoupdates for pacman (#8394)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyloflake authored Oct 6, 2024
1 parent 2f0b621 commit ae9221d
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/yellow-snakes-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": minor
"electron-updater": minor
---

feat: Implement autoupdates for pacman
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/FpmTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export default class FpmTarget extends Target {
}

private supportsAutoUpdate(target: string) {
return ["deb", "rpm"].includes(target)
return ["deb", "rpm", "pacman"].includes(target)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AppImageUpdater extends BaseUpdater {
/*** @private */
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
const provider = downloadUpdateOptions.updateInfoAndProvider.provider
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "AppImage", ["rpm", "deb"])!
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "AppImage", ["rpm", "deb", "pacman"])!
return this.executeDownload({
fileExtension: "AppImage",
fileInfo,
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/src/DebUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DebUpdater extends BaseUpdater {
/*** @private */
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
const provider = downloadUpdateOptions.updateInfoAndProvider.provider
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "deb", ["AppImage", "rpm"])!
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "deb", ["AppImage", "rpm", "pacman"])!
return this.executeDownload({
fileExtension: "deb",
fileInfo,
Expand Down
41 changes: 41 additions & 0 deletions packages/electron-updater/src/PacmanUpdater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { AllPublishOptions } from "builder-util-runtime"
import { AppAdapter } from "./AppAdapter"
import { DownloadUpdateOptions } from "./AppUpdater"
import { BaseUpdater, InstallOptions } from "./BaseUpdater"
import { DOWNLOAD_PROGRESS } from "./main"
import { findFile } from "./providers/Provider"

export class PacmanUpdater extends BaseUpdater {
constructor(options?: AllPublishOptions | null, app?: AppAdapter) {
super(options, app)
}

/*** @private */
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
const provider = downloadUpdateOptions.updateInfoAndProvider.provider
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "pacman", ["AppImage", "deb", "rpm"])!
return this.executeDownload({
fileExtension: "pacman",
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 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 cmd = ["pacman", "-U", "--noconfirm", options.installerPath]
this.spawnSyncLog(sudo, [`${wrapper}/bin/bash`, "-c", `'${cmd.join(" ")}'${wrapper}`])
if (options.isForceRunAfter) {
this.app.relaunch()
}
return true
}
}
2 changes: 1 addition & 1 deletion packages/electron-updater/src/RpmUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class RpmUpdater extends BaseUpdater {
/*** @private */
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
const provider = downloadUpdateOptions.updateInfoAndProvider.provider
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "rpm", ["AppImage", "deb"])!
const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), "rpm", ["AppImage", "deb", "pacman"])!
return this.executeDownload({
fileExtension: "rpm",
fileInfo,
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-updater/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { CancellationToken, PackageFileInfo, ProgressInfo, UpdateFileInfo, Updat
export { Provider } from "./providers/Provider"
export { AppImageUpdater } from "./AppImageUpdater"
export { DebUpdater } from "./DebUpdater"
export { PacmanUpdater } from "./PacmanUpdater"
export { RpmUpdater } from "./RpmUpdater"
export { MacUpdater } from "./MacUpdater"
export { NsisUpdater } from "./NsisUpdater"
Expand Down Expand Up @@ -45,6 +46,9 @@ function doLoadAutoUpdater(): AppUpdater {
case "rpm":
_autoUpdater = new (require("./RpmUpdater").RpmUpdater)()
break
case "pacman":
_autoUpdater = new (require("./PacmanUpdater").PacmanUpdater)()
break
default:
break
}
Expand Down
4 changes: 2 additions & 2 deletions pages/auto-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Read the remainder of this guide to configure everything.
## Auto-updatable Targets

* macOS: DMG.
* Linux: AppImage, DEB and RPM.
* Linux: AppImage, DEB, Pacman (beta) and RPM.
* Windows: NSIS.

All these targets are default, custom configuration is not required. (Though it is possible to [pass in additional configuration, e.g. request headers](#custom-options-instantiating-updater-directly).)
Expand Down Expand Up @@ -213,4 +213,4 @@ Emitted on progress.
## UpdateInfo
{!./electron-updater.Interface.UpdateInfo.md!}
{!./electron-updater.Interface.UpdateInfo.md!}
2 changes: 1 addition & 1 deletion pages/programmatic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const options = {
Encoding: "UTF-8",
MimeType: "x-scheme-handler/deeplink"
},
target: ["AppImage", "rpm", "deb"]
target: ["AppImage", "rpm", "deb", "pacman"]
},
deb: {
priority: "optional",
Expand Down
43 changes: 43 additions & 0 deletions test/snapshots/updater/linuxUpdaterTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,49 @@ Array [
]
`;

exports[`test pacman download 1`] = `
Object {
"files": Array [
Object {
"blockMapSize": 82581,
"sha512": "u6MIxgkAyGQJNoQh/xZaVN2quQ7+So3t5RXnA2RspDuF0PiMk4q3xE5DhjnTdYCUpFANykEyt/QfmSriGoRamw==",
"size": 79016577,
"url": "electron-quick-start-typescript-1.0.4-x86_64.AppImage",
},
Object {
"sha512": "TUEgrKUlS8RGFW86GlN8YZpuAK5TL0pbVDERmAvv5dPOHXI9VbvrlDEEwCzn0NYrvajVQW03jz64Ik5mhRSCvg==",
"size": 56079686,
"url": "electron-quick-start-typescript-1.0.4-amd64.deb",
},
Object {
"sha512": "RRTErNJKHJX+tfxSzE0EItjPgd+Oh7t4okaaRS4EveokyQp1fZgheLmPuxOft4ptKqjZCvFW+m200rvJRuYcWg==",
"size": 56055361,
"url": "electron-quick-start-typescript-1.0.4-x86_64.rpm",
},
Object {
"sha512": "2mUqhYKCSlAw1aWUNz2707tsqcp2/xSAsVrUVZtKZyfZEzGus63L/A5sW963i1jfuzrWk0HfdyUqYNFNS2HSWA==",
"size": 56075488,
"url": "electron-quick-start-typescript-1.0.4-x64.pacman",
},
],
"path": "electron-quick-start-typescript-1.0.4-x86_64.AppImage",
"releaseDate": "2024-09-08T16:57:10.775Z",
"releaseName": "1.0.4",
"releaseNotes": "<p>pacman autoupdate release added</p>",
"sha512": "u6MIxgkAyGQJNoQh/xZaVN2quQ7+So3t5RXnA2RspDuF0PiMk4q3xE5DhjnTdYCUpFANykEyt/QfmSriGoRamw==",
"tag": "v1.0.4",
"version": "1.0.4",
}
`;

exports[`test pacman download 2`] = `
Array [
"checking-for-update",
"update-available",
"update-downloaded",
]
`;

exports[`test rpm download 1`] = `
Object {
"files": Array [
Expand Down
2 changes: 1 addition & 1 deletion test/src/ExtraBuildResourcesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test.ifAll.ifNotWindows(
publish: null,
// https://github.com/electron-userland/electron-builder/issues/1355
linux: {
target: ["AppImage", "deb", "rpm"],
target: ["AppImage", "deb", "rpm", "pacman"],
},
compression: "store",
},
Expand Down
8 changes: 6 additions & 2 deletions test/src/updater/linuxUpdaterTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GithubOptions } from "builder-util-runtime"
import { DebUpdater, RpmUpdater } from "electron-updater"
import { DebUpdater, RpmUpdater, PacmanUpdater } from "electron-updater"
import { assertThat } from "../helpers/fileAssert"
import { createTestAppAdapter, tuneTestUpdater, validateDownload, writeUpdateConfig } from "../helpers/updaterTestUtil"

const runTest = async (updaterClass: any, expectedExtension: "deb" | "rpm" | "AppImage") => {
const runTest = async (updaterClass: any, expectedExtension: "deb" | "rpm" | "AppImage" | "pacman") => {
const testAppAdapter = await createTestAppAdapter("1.0.1")
const updater = new updaterClass(null, testAppAdapter)
tuneTestUpdater(updater, { platform: "linux" })
Expand All @@ -29,6 +29,10 @@ test("test rpm download", async () => {
await runTest(RpmUpdater, "rpm")
})

test("test pacman download", async () => {
await runTest(PacmanUpdater, "pacman")
})

test("test deb download", async () => {
await runTest(DebUpdater, "deb")
})
Expand Down

0 comments on commit ae9221d

Please sign in to comment.