build(electron): flatpak support for linux (#8439)

some issues
- app icon not showing correctly
- missing wayland support
- runtime is outdated

related to
- https://github.com/toeverything/AFFiNE/issues/3272
- https://github.com/toeverything/AFFiNE/issues/5985
- https://github.com/toeverything/AFFiNE/issues/6642
This commit is contained in:
pengx17
2024-10-10 09:51:32 +00:00
parent 46321b72ba
commit 06e059db88
5 changed files with 92 additions and 8 deletions

View File

@@ -567,7 +567,7 @@ jobs:
if: ${{ matrix.spec.test && matrix.spec.os != 'ubuntu-latest' }}
run: yarn workspace @affine-test/affine-desktop e2e
- name: Make bundle
- name: Make bundle (macOS)
if: ${{ matrix.spec.target == 'aarch64-apple-darwin' }}
env:
SKIP_BUNDLE: true
@@ -575,8 +575,15 @@ jobs:
HOIST_NODE_MODULES: 1
run: yarn workspace @affine/electron package --platform=darwin --arch=arm64
- name: Make AppImage
run: yarn workspace @affine/electron make --platform=linux --arch=x64
- name: Make Bundle (Linux)
run: |
sudo add-apt-repository universe
sudo apt install -y libfuse2 elfutils flatpak flatpak-builder
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak update
# some flatpak deps need git protocol.file.allow
git config --global protocol.file.allow always
yarn workspace @affine/electron make --platform=linux --arch=x64
if: ${{ matrix.spec.target == 'x86_64-unknown-linux-gnu' }}
env:
SKIP_WEB_BUILD: 1

View File

@@ -131,17 +131,22 @@ jobs:
p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: Install fuse on Linux (for patching AppImage)
- name: Install additional dependencies on Linux
if: ${{ matrix.spec.platform == 'linux' }}
run: |
sudo add-apt-repository universe
sudo apt install libfuse2 -y
sudo apt install -y libfuse2 elfutils flatpak flatpak-builder
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak update
# some flatpak deps need git protocol.file.allow
git config --global protocol.file.allow always
- name: make
run: yarn workspace @affine/electron make --platform=${{ matrix.spec.platform }} --arch=${{ matrix.spec.arch }}
env:
SKIP_WEB_BUILD: 1
HOIST_NODE_MODULES: 1
DEBUG: '*'
- name: signing DMG
if: ${{ matrix.spec.platform == 'darwin' }}
@@ -161,6 +166,8 @@ jobs:
mv packages/frontend/apps/electron/out/*/make/zip/linux/x64/*.zip ./builds/affine-${{ needs.before-make.outputs.RELEASE_VERSION }}-${{ env.BUILD_TYPE }}-linux-x64.zip
mv packages/frontend/apps/electron/out/*/make/*.AppImage ./builds/affine-${{ needs.before-make.outputs.RELEASE_VERSION }}-${{ env.BUILD_TYPE }}-linux-x64.appimage
mv packages/frontend/apps/electron/out/*/make/deb/x64/*.deb ./builds/affine-${{ needs.before-make.outputs.RELEASE_VERSION }}-${{ env.BUILD_TYPE }}-linux-x64.deb
mv packages/frontend/apps/electron/out/*/make/flatpak/*/*.flatpak ./builds/affine-${{ needs.before-make.outputs.RELEASE_VERSION }}-${{ env.BUILD_TYPE }}-linux-x64.flatpak
- uses: actions/attest-build-provenance@v1
if: ${{ matrix.spec.platform == 'darwin' }}
with:
@@ -412,6 +419,7 @@ jobs:
./*.exe
./*.appimage
./*.deb
./*.flatpak
./*.apk
./*.yml
- name: Create Nightly Release Draft
@@ -436,4 +444,5 @@ jobs:
./*.appimage
./*.deb
./*.apk
./*.flatpak
./*.yml

View File

@@ -10,6 +10,7 @@ import {
arch,
buildType,
icnsPath,
iconPngPath,
iconUrl,
iconX64PngPath,
icoPath,
@@ -19,6 +20,8 @@ import {
const fromBuildIdentifier = utils.fromBuildIdentifier;
const linuxMimeTypes = [`x-scheme-handler/${productName.toLowerCase()}`];
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const makers = [
!process.env.SKIP_BUNDLE &&
@@ -96,7 +99,39 @@ const makers = [
name: productName,
productName,
icon: iconX64PngPath,
mimeType: ['x-scheme-handler/affine'],
mimeType: linuxMimeTypes,
},
},
},
!process.env.SKIP_BUNDLE && {
name: '@electron-forge/maker-flatpak',
platforms: ['linux'],
/** @type {import('@electron-forge/maker-flatpak').MakerFlatpakConfig} */
config: {
options: {
mimeType: linuxMimeTypes,
productName,
bin: productName,
id: fromBuildIdentifier(appIdMap),
icon: iconPngPath, // not working yet
branch: buildType,
runtimeVersion: '20.08',
finishArgs: [
// Wayland/X11 Rendering
'--socket=wayland',
'--socket=x11',
'--share=ipc',
// Open GL
'--device=dri',
// Audio output
'--socket=pulseaudio',
// Read/write home directory access
'--filesystem=home',
// Allow communication with network
'--share=network',
// System notifications with libnotify
'--talk-name=org.freedesktop.Notifications',
],
},
},
},

View File

@@ -34,6 +34,7 @@
"@electron-forge/core-utils": "^7.3.0",
"@electron-forge/maker-deb": "^7.5.0",
"@electron-forge/maker-dmg": "^7.3.0",
"@electron-forge/maker-flatpak": "^7.5.0",
"@electron-forge/maker-squirrel": "^7.3.0",
"@electron-forge/maker-zip": "^7.3.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.3.0",

View File

@@ -476,6 +476,7 @@ __metadata:
"@electron-forge/core-utils": "npm:^7.3.0"
"@electron-forge/maker-deb": "npm:^7.5.0"
"@electron-forge/maker-dmg": "npm:^7.3.0"
"@electron-forge/maker-flatpak": "npm:^7.5.0"
"@electron-forge/maker-squirrel": "npm:^7.3.0"
"@electron-forge/maker-zip": "npm:^7.3.0"
"@electron-forge/plugin-auto-unpack-natives": "npm:^7.3.0"
@@ -3382,6 +3383,21 @@ __metadata:
languageName: node
linkType: hard
"@electron-forge/maker-flatpak@npm:^7.5.0":
version: 7.5.0
resolution: "@electron-forge/maker-flatpak@npm:7.5.0"
dependencies:
"@electron-forge/maker-base": "npm:7.5.0"
"@electron-forge/shared-types": "npm:7.5.0"
"@malept/electron-installer-flatpak": "npm:^0.11.4"
fs-extra: "npm:^10.0.0"
dependenciesMeta:
"@malept/electron-installer-flatpak":
optional: true
checksum: 10/4e795f737fff75b03bdc5f08907302f240a422ef79f65b5bb7c65d152e2fb22cd39eaf07c0957c7b02d882e6d2455ff7ceeffcb044ca0bdca08f6967acd4bad8
languageName: node
linkType: hard
"@electron-forge/maker-squirrel@npm:^7.3.0":
version: 7.5.0
resolution: "@electron-forge/maker-squirrel@npm:7.5.0"
@@ -6139,6 +6155,22 @@ __metadata:
languageName: node
linkType: hard
"@malept/electron-installer-flatpak@npm:^0.11.4":
version: 0.11.4
resolution: "@malept/electron-installer-flatpak@npm:0.11.4"
dependencies:
"@malept/flatpak-bundler": "npm:^0.4.0"
debug: "npm:^4.1.1"
electron-installer-common: "npm:^0.10.0"
lodash: "npm:^4.17.15"
semver: "npm:^7.1.1"
yargs: "npm:^16.0.0"
bin:
electron-installer-flatpak: bin/electron-installer-flatpak.js
conditions: (os=darwin | os=linux)
languageName: node
linkType: hard
"@malept/flatpak-bundler@npm:^0.4.0":
version: 0.4.0
resolution: "@malept/flatpak-bundler@npm:0.4.0"
@@ -18590,7 +18622,7 @@ __metadata:
languageName: node
linkType: hard
"electron-installer-common@npm:^0.10.2":
"electron-installer-common@npm:^0.10.0, electron-installer-common@npm:^0.10.2":
version: 0.10.3
resolution: "electron-installer-common@npm:0.10.3"
dependencies:
@@ -33559,7 +33591,7 @@ __metadata:
languageName: node
linkType: hard
"yargs@npm:^16.0.2":
"yargs@npm:^16.0.0, yargs@npm:^16.0.2":
version: 16.2.0
resolution: "yargs@npm:16.2.0"
dependencies: