Files
moeka-project/apps/stage-tamagotchi/ai.moeru.airi.flatpak.yml
T

104 lines
4.6 KiB
YAML

app-id: ai.moeru.airi
runtime: org.freedesktop.Platform
runtime-version: '24.08'
sdk: org.freedesktop.Sdk
base: org.electronjs.Electron2.BaseApp
base-version: '24.08'
command: airi.sh
finish-args:
# GUI environment
- --share=network
- --socket=x11
- --socket=fallback-x11
- --socket=wayland
- --device=dri
- --device=all
- --socket=pulseaudio
- --socket=system-bus
- --socket=session-bus
- --share=ipc
# DBus
- --talk-name=org.freedesktop.Notifications
- --talk-name=org.freedesktop.portal.Desktop
- --system-talk-name=org.freedesktop.login1
- --system-talk-name=org.freedesktop.UPower
# Filesystem permissions
- --filesystem=xdg-download:rw
- --filesystem=xdg-config/airi:create
# Electron uses ~/.config/airi when XDG_CONFIG_HOME is not set.
- --filesystem=~/.config/airi:create
modules:
- name: AIRI-App
buildsystem: simple
build-commands:
- mkdir -p /app/bin
- mkdir -p /app/lib/airi
- cp -r payload/. /app/lib/airi/
- install airi.sh /app/bin/airi.sh
- chmod +x /app/lib/airi/airi
# Desktop-file launches run Exec=airi directly inside the sandbox; the manifest
# `command` does not apply to them, so /app/bin/airi must be a real entry point
# that resolves to the zypak wrapper script.
- ln -s /app/bin/airi.sh /app/bin/airi
- install -Dm644 ai.moeru.airi.desktop /app/share/applications/ai.moeru.airi.desktop
- install -Dm644 ai.moeru.airi.metainfo.xml /app/share/metainfo/ai.moeru.airi.metainfo.xml
# build-export rejects icons larger than the hicolor size directory they land in,
# so Flatpak installs the 512x512 derivative while Electron keeps the 1024x1024 source.
- install -Dm644 build/icon-512.png /app/share/icons/hicolor/512x512/apps/ai.moeru.airi.png
sources:
- type: dir
only-arches: [x86_64]
path: dist/linux-unpacked
dest: payload
- type: dir
only-arches: [aarch64]
path: dist/linux-arm64-unpacked
dest: payload
- type: file
path: ai.moeru.airi.desktop
- type: file
path: ai.moeru.airi.metainfo.xml
- type: file
path: build/icon-512.png
dest: build
# First discovered by [@gg582](https://github.com/gg582) in https://github.com/moeru-ai/airi/pull/647
#
# Without the correct zypak-wrapper, application launch will result in this error:
# content/browser/zygote_host/zygote_host_impl_linux.cc:132] No usable sandbox! ... If you want to live
# dangerously and need an immediate workaround, you can try using --no-sandbox.
#
# Though https://github.com/refi64/chromium-tar/blob/82ebd6a0473341fa75dd3bbb2f584da99f5ac92c/content/browser/zygote_host/zygote_host_impl_linux.cc#L104-L131
# suggests that the error is related to missing switch of service_manager::switches::kDisableNamespaceSandbox and
# service_manager::switches::kDisableSetuidSandbox, even if we add --no-sandbox to the command, the application basically
# exits immediately without any error message and traces.
#
# When searching for solutions, I spotted the session-desktop issue below looks exactly the same and
# they managed to resolve it by renaming the executable command with -app suffix, however the wrapper
# called zypak-wrapper is the key to resolve this issue:
# https://github.com/session-foundation/session-desktop/issues/795
# https://github.com/flathub/network.loki.Session/pull/32
#
# Similar keywords appears in the official docs of Flatpak as well:
# https://docs.flatpak.org/en/latest/electron.html#launching-the-app
#
# With the correct way to research, I found several examples of Electron apps using zypak-wrapper:
# https://github.com/chaiNNer-org/chaiNNer/issues/1597#issuecomment-3272020725
# https://github.com/vendillah/app.Chainner.chainner/blob/main/app.chainner.Chainner.yaml
#
# and bitwarden, as the most popular password manager app, it's architecture and bundle workflow looked
# almost the same as ours, most of the structure of this manifest is based on bitwarden's:
# https://github.com/bitwarden/clients/blob/b8d55c4db178de67f1778bc307f7c22aad01f4a9/apps/desktop/resources/com.bitwarden.desktop.devel.yaml
- type: script
dest-filename: airi.sh
commands:
- ulimit -c 0
- export TMPDIR="$XDG_RUNTIME_DIR/app/$FLATPAK_ID"
- |
if [ -n "$WAYLAND_DISPLAY" ]; then
export ELECTRON_OZONE_PLATFORM_HINT=auto
fi
- exec zypak-wrapper /app/lib/airi/airi "$@"