app-id: io.github.alyraffauf.Switchyard.Devel
runtime: org.gnome.Platform
runtime-version: "50"
sdk: org.gnome.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.golang
command: switchyard

finish-args:
  # Display
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --device=dri

  # Access to Flatpak service
  # Needed to launch other Flatpak browsers and run xdg-settings on the host
  # to check/set the default browser
  - --talk-name=org.freedesktop.Flatpak

  # Read-only access to discover all installed browsers
  # Covers native apps, Flatpak exports, and Snap installations
  - --filesystem=/var/lib/flatpak:ro
  - --filesystem=/var/lib/snapd:ro
  - --filesystem=host:ro
  - --filesystem=xdg-data/applications:ro
  - --filesystem=xdg-data/flatpak:ro
modules:
  - name: glib
    buildsystem: meson
    config-opts:
      - -Dtests=false
    sources:
      - type: archive
        url: https://download.gnome.org/sources/glib/2.88/glib-2.88.0.tar.xz
        sha256: 3546251ccbb3744d4bc4eb48354540e1f6200846572bab68e3a2b7b2b64dfd07
      - type: patch
        path: patches/glib-appinfo.patch

  - name: switchyard
    buildsystem: simple
    build-options:
      env:
        GOROOT: /usr/lib/sdk/golang
        # Use flatpak-builder's cache directory for Go cache
        GOPATH: /run/build/switchyard/go
        GOCACHE: /run/ccache/go-build-cache
        CGO_ENABLED: "1"
    build-commands:
      - |
        . /usr/lib/sdk/golang/enable.sh
        mkdir -p "$GOCACHE"
        go build -mod=vendor -trimpath -o switchyard-bin ./src
      - install -Dm755 switchyard-bin /app/bin/switchyard-bin
      - install -Dm755 flatpak/switchyard-wrapper.sh /app/bin/switchyard
      # Install desktop file and update app-id to .Devel
      - install -Dm644 data/io.github.alyraffauf.Switchyard.desktop /app/share/applications/io.github.alyraffauf.Switchyard.Devel.desktop
      - sed -i 's/io.github.alyraffauf.Switchyard/io.github.alyraffauf.Switchyard.Devel/g' /app/share/applications/io.github.alyraffauf.Switchyard.Devel.desktop
      # Install metainfo and update app-id and launchable to .Devel
      - install -Dm644 data/io.github.alyraffauf.Switchyard.metainfo.xml /app/share/metainfo/io.github.alyraffauf.Switchyard.Devel.metainfo.xml
      - sed -i 's/io.github.alyraffauf.Switchyard/io.github.alyraffauf.Switchyard.Devel/g' /app/share/metainfo/io.github.alyraffauf.Switchyard.Devel.metainfo.xml
      - install -Dm644 data/icons/hicolor/scalable/apps/io.github.alyraffauf.Switchyard.svg /app/share/icons/hicolor/scalable/apps/io.github.alyraffauf.Switchyard.Devel.svg
    sources:
      - type: dir
        path: ..
