mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-28 16:58:41 +01:00
Package Linux as .deb and AppImage, built in CI
- binary bikecontrol, application id app.bikecontrol.BikeControl - .deb: /opt/bikecontrol, launcher, icon, bikecontrol:// handler and the udev rule for /dev/uinput; AppImage for other distros - single instance, so a bikecontrol:// link reaches the running app - CI builds on Ubuntu 22.04 (x64 via Shorebird, arm64) and publishes to the version's release and the rolling linux-latest release - keypress_simulator_linux: no std::clamp (plugins build as C++14) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
154
.github/workflows/build.yml
vendored
154
.github/workflows/build.yml
vendored
@@ -28,6 +28,11 @@ on:
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
build_linux:
|
||||
description: 'Build for Linux (.deb + AppImage)'
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
SHOREBIRD_TOKEN: ${{ secrets.SHOREBIRD_TOKEN }}
|
||||
@@ -362,3 +367,152 @@ jobs:
|
||||
replacesArtifacts: false
|
||||
tag: v${{ env.VERSION }}
|
||||
token: ${{ secrets.TOKEN }}
|
||||
|
||||
linux:
|
||||
if: inputs.build_linux
|
||||
name: Build on Linux (${{ matrix.arch }})
|
||||
# 22.04 (glibc 2.35): what the bundle is built against is the oldest system
|
||||
# it runs on — Ubuntu 22.04+, Debian 12+, Mint 21+ and current rolling
|
||||
# distros. A 24.04 build needs glibc 2.38 and fails to start on Debian 12.
|
||||
runs-on: ${{ matrix.runner }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- arch: x64
|
||||
runner: ubuntu-22.04
|
||||
deb_arch: amd64
|
||||
appimage_arch: x86_64
|
||||
shorebird: true
|
||||
# Plain Flutter build: no Shorebird patches on arm64.
|
||||
- arch: arm64
|
||||
runner: ubuntu-22.04-arm
|
||||
deb_arch: arm64
|
||||
appimage_arch: aarch64
|
||||
shorebird: false
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
token: ${{ secrets.PAT_TOKEN }}
|
||||
|
||||
- name: Rename pubspec_overrides_ci.yaml to pubspec_overrides.yaml
|
||||
uses: ./.github/actions/rename-pubspec-overrides
|
||||
|
||||
- name: Install Linux build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends clang cmake ninja-build pkg-config \
|
||||
libgtk-3-dev liblzma-dev libstdc++-12-dev libasound2-dev libpulse-dev libsecret-1-dev \
|
||||
libayatana-appindicator3-dev libnotify-dev libkeybinder-3.0-dev libgstreamer1.0-dev \
|
||||
libgstreamer-plugins-base1.0-dev libsqlite3-dev libudev-dev libevdev-dev
|
||||
|
||||
- name: Extract version from pubspec.yaml
|
||||
run: |
|
||||
version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
|
||||
echo "VERSION=$version" >> "$GITHUB_ENV"
|
||||
|
||||
- name: 🐦 Setup Shorebird
|
||||
if: matrix.shorebird
|
||||
uses: shorebirdtech/setup-shorebird@v1
|
||||
with:
|
||||
cache: true
|
||||
|
||||
- name: Set Up Flutter
|
||||
uses: ./.github/actions/setup-flutter
|
||||
|
||||
- name: 🚀 Shorebird Release Linux
|
||||
if: matrix.shorebird
|
||||
uses: shorebirdtech/shorebird-release@v1
|
||||
with:
|
||||
flutter-version: latest
|
||||
platform: linux
|
||||
args: "--obfuscate --split-debug-info=symbols-linux -- --dart-define=SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }}"
|
||||
|
||||
- name: Flutter build Linux
|
||||
if: ${{ !matrix.shorebird }}
|
||||
run: flutter build linux --release --obfuscate --split-debug-info=symbols-linux --dart-define=SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }}
|
||||
|
||||
- name: Package .deb and AppImage
|
||||
run: |
|
||||
bundle=build/linux/${{ matrix.arch }}/release/bundle
|
||||
linux/packaging/build_deb.sh "$bundle" "$VERSION" ${{ matrix.deb_arch }} dist
|
||||
linux/packaging/build_appimage.sh "$bundle" "$VERSION" ${{ matrix.appimage_arch }} dist
|
||||
|
||||
- name: Upload Linux packages
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
overwrite: true
|
||||
name: Linux ${{ matrix.arch }}
|
||||
path: dist/*
|
||||
|
||||
- name: Zip Linux Symbols
|
||||
run: zip -P "${{ secrets.ZIP_PASSWORD }}" -r symbols-linux-${{ matrix.arch }}.zip symbols-linux/
|
||||
|
||||
- name: Upload Linux Symbols
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
overwrite: true
|
||||
name: Linux Symbols ${{ matrix.arch }}
|
||||
path: symbols-linux-${{ matrix.arch }}.zip
|
||||
|
||||
linux_publish:
|
||||
if: inputs.build_linux && inputs.build_github
|
||||
name: Publish Linux packages
|
||||
needs: linux
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Extract version from pubspec.yaml
|
||||
run: |
|
||||
version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
|
||||
echo "VERSION=$version" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Download Linux packages
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: Linux *64
|
||||
merge-multiple: true
|
||||
path: dist
|
||||
|
||||
# What the app's update check compares against (without the build number:
|
||||
# patches within a version come through Shorebird).
|
||||
- name: Write VERSION.txt
|
||||
run: echo "${VERSION%%+*}" > dist/VERSION.txt
|
||||
|
||||
- name: Add to the version's release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: "dist/*.deb,dist/*.AppImage"
|
||||
allowUpdates: true
|
||||
prerelease: true
|
||||
omitBodyDuringUpdate: true
|
||||
replacesArtifacts: false
|
||||
tag: v${{ env.VERSION }}
|
||||
token: ${{ secrets.TOKEN }}
|
||||
|
||||
# Fixed file names under a fixed tag, so the download links on the
|
||||
# website and the app's update check never change.
|
||||
- name: Update the rolling linux-latest release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: "dist/*.deb,dist/*.AppImage,dist/VERSION.txt"
|
||||
allowUpdates: true
|
||||
replacesArtifacts: true
|
||||
removeArtifacts: true
|
||||
makeLatest: false
|
||||
name: BikeControl for Linux
|
||||
body: |
|
||||
BikeControl ${{ env.VERSION }} for Linux.
|
||||
|
||||
- **Ubuntu, Debian, Mint, Pop!_OS:** the `.deb` (`amd64` for most PCs, `arm64` for ARM). Install with `sudo apt install ./BikeControl-linux-amd64.deb`.
|
||||
- **Everything else:** the AppImage. Make it executable and run it.
|
||||
|
||||
The Local connection method needs write access to `/dev/uinput`. The `.deb` sets that up; with the AppImage, BikeControl shows the one-line udev rule to add.
|
||||
commit: ${{ github.sha }}
|
||||
tag: linux-latest
|
||||
token: ${{ secrets.TOKEN }}
|
||||
|
||||
@@ -244,7 +244,8 @@ static FlMethodResponse* simulate_mouse_click(FlKeypressSimulatorLinuxPlugin* se
|
||||
|
||||
// x/y are relative to the primary monitor.
|
||||
auto scale = [](double value, int origin, int size) {
|
||||
return std::clamp(static_cast<int>(std::lround((value - origin) * kAbsMax / size)), 0, kAbsMax);
|
||||
// std::clamp is C++17; plugins build as C++14 (apply_standard_settings).
|
||||
return std::max(0, std::min(static_cast<int>(std::lround((value - origin) * kAbsMax / size)), kAbsMax));
|
||||
};
|
||||
const int abs_x = scale(primary.x + x, bounds.x, bounds.width);
|
||||
const int abs_y = scale(primary.y + y, bounds.y, bounds.height);
|
||||
|
||||
@@ -4,10 +4,10 @@ project(runner LANGUAGES CXX)
|
||||
|
||||
# The name of the executable created for the application. Change this to change
|
||||
# the on-disk name of your application.
|
||||
set(BINARY_NAME "swift_play")
|
||||
set(BINARY_NAME "bikecontrol")
|
||||
# The unique GTK application identifier for this application. See:
|
||||
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
|
||||
set(APPLICATION_ID "de.jonasbark.swift_play")
|
||||
set(APPLICATION_ID "app.bikecontrol.BikeControl")
|
||||
|
||||
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
||||
# versions of CMake.
|
||||
|
||||
4
linux/packaging/60-bikecontrol-uinput.rules
Normal file
4
linux/packaging/60-bikecontrol-uinput.rules
Normal file
@@ -0,0 +1,4 @@
|
||||
# BikeControl's Local connection method presses keys and clicks in the trainer
|
||||
# app through virtual input devices on /dev/uinput. Let the user at the seat
|
||||
# create them, as Steam does for Steam Input.
|
||||
KERNEL=="uinput", SUBSYSTEM=="misc", TAG+="uaccess", OPTIONS+="static_node=uinput"
|
||||
12
linux/packaging/app.bikecontrol.BikeControl.desktop
Normal file
12
linux/packaging/app.bikecontrol.BikeControl.desktop
Normal file
@@ -0,0 +1,12 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=BikeControl
|
||||
GenericName=Smart bike controller bridge
|
||||
Comment=Use your bike's controllers and smart trainer with any training app
|
||||
Exec=bikecontrol %u
|
||||
Icon=app.bikecontrol.BikeControl
|
||||
Terminal=false
|
||||
Categories=Utility;Sports;
|
||||
Keywords=Zwift;MyWhoosh;Rouvy;trainer;shifting;controller;
|
||||
StartupWMClass=app.bikecontrol.BikeControl
|
||||
MimeType=x-scheme-handler/bikecontrol;
|
||||
BIN
linux/packaging/app.bikecontrol.BikeControl.png
Normal file
BIN
linux/packaging/app.bikecontrol.BikeControl.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 323 KiB |
46
linux/packaging/build_appimage.sh
Executable file
46
linux/packaging/build_appimage.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
# Packages a `flutter build linux` / `shorebird release linux` bundle as an
|
||||
# AppImage.
|
||||
#
|
||||
# linux/packaging/build_appimage.sh <bundle dir> <version> <x86_64|aarch64> <output dir>
|
||||
#
|
||||
# An AppImage cannot install the udev rule for /dev/uinput; the app explains
|
||||
# the rule when the Local connection method needs it. Machines with Steam
|
||||
# installed already have an equivalent rule.
|
||||
set -euo pipefail
|
||||
|
||||
BUNDLE=$1
|
||||
VERSION=$2
|
||||
ARCH=$3
|
||||
OUT=$4
|
||||
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
APP_ID=app.bikecontrol.BikeControl
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
APPDIR=$WORK/BikeControl.AppDir
|
||||
|
||||
install -d "$APPDIR/usr/lib/bikecontrol" "$APPDIR/usr/share/applications" \
|
||||
"$APPDIR/usr/share/icons/hicolor/512x512/apps"
|
||||
cp -a "$BUNDLE"/. "$APPDIR/usr/lib/bikecontrol/"
|
||||
install -m 644 "$HERE/$APP_ID.desktop" "$APPDIR/$APP_ID.desktop"
|
||||
install -m 644 "$HERE/$APP_ID.desktop" "$APPDIR/usr/share/applications/$APP_ID.desktop"
|
||||
install -m 644 "$HERE/$APP_ID.png" "$APPDIR/$APP_ID.png"
|
||||
install -m 644 "$HERE/$APP_ID.png" "$APPDIR/usr/share/icons/hicolor/512x512/apps/$APP_ID.png"
|
||||
ln -s "$APP_ID.png" "$APPDIR/.DirIcon"
|
||||
|
||||
cat > "$APPDIR/AppRun" <<'EOF'
|
||||
#!/bin/sh
|
||||
HERE=$(dirname "$(readlink -f "$0")")
|
||||
exec "$HERE/usr/lib/bikecontrol/bikecontrol" "$@"
|
||||
EOF
|
||||
chmod 755 "$APPDIR/AppRun"
|
||||
|
||||
TOOL=$WORK/appimagetool
|
||||
curl -fsSL -o "$TOOL" "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$ARCH.AppImage"
|
||||
chmod 755 "$TOOL"
|
||||
|
||||
mkdir -p "$OUT"
|
||||
# Extract-and-run: CI runners and containers have no FUSE.
|
||||
ARCH=$ARCH VERSION=$VERSION "$TOOL" --appimage-extract-and-run --no-appstream \
|
||||
"$APPDIR" "$OUT/BikeControl-linux-$ARCH.AppImage"
|
||||
70
linux/packaging/build_deb.sh
Executable file
70
linux/packaging/build_deb.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
# Packages a `flutter build linux` / `shorebird release linux` bundle as a .deb.
|
||||
#
|
||||
# linux/packaging/build_deb.sh <bundle dir> <version> <amd64|arm64> <output dir>
|
||||
#
|
||||
# Installs the app under /opt/bikecontrol, a launcher, the icon, the
|
||||
# bikecontrol:// handler (sign-in and checkout come back through it) and the
|
||||
# udev rule that lets the logged-in user create virtual input devices for the
|
||||
# Local connection method.
|
||||
set -euo pipefail
|
||||
|
||||
BUNDLE=$1
|
||||
VERSION=$2
|
||||
ARCH=$3
|
||||
OUT=$4
|
||||
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
APP_ID=app.bikecontrol.BikeControl
|
||||
ROOT=$(mktemp -d)
|
||||
trap 'rm -rf "$ROOT"' EXIT
|
||||
|
||||
install -d "$ROOT/opt/bikecontrol" "$ROOT/usr/bin" "$ROOT/DEBIAN" \
|
||||
"$ROOT/usr/share/applications" "$ROOT/usr/share/icons/hicolor/512x512/apps" "$ROOT/usr/lib/udev/rules.d"
|
||||
cp -a "$BUNDLE"/. "$ROOT/opt/bikecontrol/"
|
||||
ln -s /opt/bikecontrol/bikecontrol "$ROOT/usr/bin/bikecontrol"
|
||||
install -m 644 "$HERE/$APP_ID.desktop" "$ROOT/usr/share/applications/$APP_ID.desktop"
|
||||
install -m 644 "$HERE/$APP_ID.png" "$ROOT/usr/share/icons/hicolor/512x512/apps/$APP_ID.png"
|
||||
install -m 644 "$HERE/60-bikecontrol-uinput.rules" "$ROOT/usr/lib/udev/rules.d/60-bikecontrol-uinput.rules"
|
||||
|
||||
# Flutter loads EGL/GLES with dlopen, so they do not show up in ldd.
|
||||
cat > "$ROOT/DEBIAN/control" <<EOF
|
||||
Package: bikecontrol
|
||||
Version: $VERSION
|
||||
Architecture: $ARCH
|
||||
Maintainer: BikeControl <support@bikecontrol.app>
|
||||
Homepage: https://bikecontrol.app
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Installed-Size: $(du -sk "$ROOT" | cut -f1)
|
||||
Depends: libgtk-3-0t64 | libgtk-3-0, libegl1, libgles2, libsecret-1-0, libasound2t64 | libasound2, libstdc++6, libc6 (>= 2.35)
|
||||
Recommends: bluez, avahi-daemon
|
||||
Description: Use your bike's controllers with any training app
|
||||
BikeControl connects Zwift Click, Ride and Play, Shimano Di2, SRAM AXS and
|
||||
other bike controllers and smart trainers to MyWhoosh, Zwift, Rouvy,
|
||||
TrainingPeaks Virtual and more, with virtual shifting for any smart trainer.
|
||||
EOF
|
||||
|
||||
cat > "$ROOT/DEBIAN/postinst" <<'EOF'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
if command -v udevadm >/dev/null 2>&1; then
|
||||
udevadm control --reload-rules || true
|
||||
udevadm trigger --name-match=uinput || true
|
||||
fi
|
||||
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database -q /usr/share/applications || true
|
||||
command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
cat > "$ROOT/DEBIAN/postrm" <<'EOF'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
command -v udevadm >/dev/null 2>&1 && udevadm control --reload-rules || true
|
||||
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database -q /usr/share/applications || true
|
||||
exit 0
|
||||
EOF
|
||||
chmod 755 "$ROOT/DEBIAN/postinst" "$ROOT/DEBIAN/postrm"
|
||||
|
||||
mkdir -p "$OUT"
|
||||
dpkg-deb --root-owner-group -Zxz --build "$ROOT" "$OUT/BikeControl-linux-$ARCH.deb"
|
||||
@@ -17,6 +17,16 @@ G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
|
||||
// Implements GApplication::activate.
|
||||
static void my_application_activate(GApplication* application) {
|
||||
MyApplication* self = MY_APPLICATION(application);
|
||||
|
||||
// Single instance: a second launch (e.g. the browser opening a
|
||||
// bikecontrol:// link after sign-in or checkout) brings the running window
|
||||
// forward; its command line reaches Dart through the gtk plugin.
|
||||
GList* windows = gtk_application_get_windows(GTK_APPLICATION(application));
|
||||
if (windows) {
|
||||
gtk_window_present(GTK_WINDOW(windows->data));
|
||||
return;
|
||||
}
|
||||
|
||||
GtkWindow* window =
|
||||
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
|
||||
|
||||
@@ -47,6 +57,9 @@ static void my_application_activate(GApplication* application) {
|
||||
gtk_window_set_title(window, "BikeControl");
|
||||
}
|
||||
|
||||
// Installed by the .deb and AppImage packages (linux/packaging) under the
|
||||
// application id, which is also the .desktop file name Wayland matches on.
|
||||
gtk_window_set_icon_name(window, APPLICATION_ID);
|
||||
gtk_window_set_default_size(window, 1280, 720);
|
||||
gtk_widget_show(GTK_WIDGET(window));
|
||||
|
||||
@@ -78,7 +91,9 @@ static gboolean my_application_local_command_line(GApplication* application, gch
|
||||
g_application_activate(application);
|
||||
*exit_status = 0;
|
||||
|
||||
return TRUE;
|
||||
// FALSE: let GApplication hand the command line to the primary instance,
|
||||
// where the gtk plugin passes it on (app_links reads deep links from it).
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Implements GApplication::startup.
|
||||
@@ -125,6 +140,6 @@ MyApplication* my_application_new() {
|
||||
|
||||
return MY_APPLICATION(g_object_new(my_application_get_type(),
|
||||
"application-id", APPLICATION_ID,
|
||||
"flags", G_APPLICATION_NON_UNIQUE,
|
||||
"flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN,
|
||||
nullptr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user