chore: add desktop integration tests for Linux

Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
TheOneWithTheBraid 2023-01-06 18:38:00 +01:00
parent 710b793c0f
commit e7a4ab6060
8 changed files with 392 additions and 70 deletions

View File

@ -85,14 +85,12 @@ integration_test:
# integration tests for Linux builds
### disabled because of Linux headless issues
.integration_test_linux:
image: cirrusci/flutter:${FLUTTER_VERSION}
integration_test_linux:
extends: integration_test
script:
- apt-get update
- apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libsecret-1-dev libjsoncpp-dev
- flutter pub get
- flutter test integration_test -d linux --dart-define=HOMESERVER=$HOMESERVER --dart-define=USER1_NAME=$USER1_NAME --dart-define=USER2_NAME=$USER2_NAME --dart-define=USER1_PW=$USER1_PW --dart-define=USER2_PW=$USER2_PW || ( sleep 10 && exit 1 )
- apk update && apk add sway
- chown -R 3434:3434 .
- ./scripts/integration-test-swayvnc-headless.sh
after_script: [ ]
artifacts:

View File

@ -0,0 +1,79 @@
# this work is based on https://github.com/bbusse/swayvnc
FROM ubuntu:latest
ARG flutter_version
WORKDIR /usr
ENV FLUTTER_HOME=/usr/flutter/bin
ENV PATH=${FLUTTER_HOME}:${PATH}
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
LABEL maintainer="The one with the braid <the-one@with-the-braid.cf>"
ENV USER="vnc-user" \
VNC_LISTEN_ADDRESS="0.0.0.0" \
VNC_AUTH_ENABLE="false" \
VNC_KEYFILE="key.pem" \
VNC_CERT="cert.pem" \
VNC_PASS="$(pwgen -yns 8 1)"
COPY selections.conf selections.conf
RUN apt update && apt install debconf-utils && dpkg-reconfigure debconf -f noninteractive -p critical \
&& debconf-set-selections < selections.conf
RUN apt upgrade -y
RUN apt install -y openssl socat sway keyboard-configuration wayvnc libneatvnc0 \
clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev git unzip foot curl
# Add application user
RUN groupadd --gid 3434 $USER \
&& useradd --uid 3434 --gid $USER --groups sudo,video,audio --shell /bin/bash --create-home $USER \
&& (echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers)
# Make sure we have UTF-8
RUN echo "LC_ALL=en_US.UTF-8" > /etc/environment \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "LANG=en_US.UTF-8" > /etc/locale.conf
# && locale-gen en_US.UTF-8
# Copy sway config
COPY config /etc/sway/config
# Add wayvnc to compositor startup and put IPC on the network
RUN mkdir -p /etc/sway/config.d \
&& echo "exec wayvnc 0.0.0.0 5900" >> /etc/sway/config.d/exec \
&& echo "exec \"socat TCP-LISTEN:7023,fork UNIX-CONNECT:/tmp/sway-ipc.sock\"" >> /etc/sway/config.d/exec \
&& mkdir -p /home/$USER/.config/wayvnc/ \
&& printf "\
address=$VNC_LISTEN_ADDRESS\n\
enable_auth=$VNC_AUTH_ENABLE\n\
username=$USER\n\
password=$VNC_PASS\n\
private_key_file=/home/$USER/$VNC_KEYFILE\n\
certificate_file=/home/$USER/$VNC_CERT" > /home/$USER/.config/wayvnc/config
# Generate certificates for VNC
RUN openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout key.pem -out cert.pem -subj /CN=localhost \
-addext subjectAltName=DNS:localhost,DNS:localhost,IP:127.0.0.1
RUN mkdir -p /usr/flutter && chown -R $USER /usr/flutter
RUN mkdir -p /home/$USER/.config && chown -R $USER /home/$USER/
USER $USER
ENV HOME /home/$USER
ENV PATH /home/$USER/.local/bin:/home/$USER/bin:${PATH}
RUN git clone --depth 1 https://github.com/flutter/flutter.git -b $flutter_version /usr/flutter
RUN flutter config --no-analytics && flutter precache --linux && flutter doctor
# Add entrypoint
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
WORKDIR /opt

View File

@ -0,0 +1,200 @@
# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.
### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4
# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l
# Your preferred terminal emulator
set $term alacritty
# Your preferred application launcher
# Note: pass the final command to swaymsg so that the resulting window can be opened
# on the original workspace that the command was run on.
set $menu dmenu_path | dmenu | xargs swaymsg exec --
### Output configuration
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
#
# Example configuration:
#
# output HDMI-A-1 resolution 1920x1080 position 1920,0
#
# You can get the names of your outputs by running: swaymsg -t get_outputs
### Idle configuration
#
# Example configuration:
#
# exec swayidle -w \
# timeout 300 'swaylock -f -c 000000' \
# timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
# before-sleep 'swaylock -f -c 000000'
#
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
### Input configuration
#
# Example configuration:
#
# input "2:14:SynPS/2_Synaptics_TouchPad" {
# dwt enabled
# tap enabled
# natural_scroll enabled
# middle_emulation enabled
# }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
### Key bindings
#
# Basics:
#
# Start a terminal
bindsym $mod+Return exec $term
# Kill focused window
bindsym $mod+Shift+q kill
# Start your launcher
bindsym $mod+d exec $menu
# Drag floating windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Despite the name, also works for non-floating windows.
# Change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal
# Reload the configuration file
bindsym $mod+Shift+c reload
# Exit sway (logs you out of your Wayland session)
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'
#
# Moving around:
#
# Move your focus around
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right
# Or use $mod+[up|down|left|right]
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# Move the focused window with the same, but add Shift
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right
# Ditto, with arrow keys
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
#
# Workspaces:
#
# Switch to workspace
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+0 workspace number 10
# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
bindsym $mod+Shift+0 move container to workspace number 10
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv
# Switch the current container between different layout styles
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# Make the current focus fullscreen
bindsym $mod+f fullscreen
# Toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle
# Swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle
# Move focus to the parent container
bindsym $mod+a focus parent
#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.
# Move the currently focused window to the scratchpad
bindsym $mod+Shift+minus move scratchpad
# Show the next scratchpad window or hide the focused scratchpad window.
# If there are multiple scratchpad windows, this command cycles through them.
bindsym $mod+minus scratchpad show
#
# Resizing containers:
#
mode "resize" {
# left will shrink the containers width
# right will grow the containers width
# up will shrink the containers height
# down will grow the containers height
bindsym $left resize shrink width 10px
bindsym $down resize grow height 10px
bindsym $up resize shrink height 10px
bindsym $right resize grow width 10px
# Ditto, with arrow keys
bindsym Left resize shrink width 10px
bindsym Down resize grow height 10px
bindsym Up resize shrink height 10px
bindsym Right resize grow width 10px
# Return to default mode
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
include /etc/sway/config.d/*
exec wayvnc 0.0.0.0 5910

View File

@ -0,0 +1,13 @@
#!/bin/sh
set -o errexit
case "$1" in
sh|bash)
set -- "$@"
;;
*)
set -- sway
;;
esac
exec "$@"

View File

@ -0,0 +1,22 @@
debconf debconf/frontend select Noninteractive
keyboard-configuration keyboard-configuration/store_defaults_in_debconf_db boolean true
keyboard-configuration keyboard-configuration/switch select No temporary switch
keyboard-configuration keyboard-configuration/altgr select The default for the keyboard layout
keyboard-configuration keyboard-configuration/ctrl_alt_bksp boolean false
keyboard-configuration keyboard-configuration/xkb-keymap select
keyboard-configuration keyboard-configuration/optionscode string
keyboard-configuration keyboard-configuration/unsupported_config_layout boolean true
keyboard-configuration console-setup/detect detect-keyboard
keyboard-configuration console-setup/ask_detect boolean false
keyboard-configuration keyboard-configuration/toggle select No toggling
keyboard-configuration keyboard-configuration/variantcode string
keyboard-configuration keyboard-configuration/modelcode string pc105
keyboard-configuration keyboard-configuration/layoutcode string us
keyboard-configuration keyboard-configuration/unsupported_config_options boolean true
keyboard-configuration keyboard-configuration/variant select English (US)
keyboard-configuration console-setup/detected note
keyboard-configuration keyboard-configuration/model select Generic 105-key PC
keyboard-configuration keyboard-configuration/unsupported_options boolean true
keyboard-configuration keyboard-configuration/layout select English (US)
keyboard-configuration keyboard-configuration/compose select No compose key
keyboard-configuration keyboard-configuration/unsupported_layout boolean true

View File

@ -1,57 +0,0 @@
//
// Generated file. Do not edit.
//
// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars
// ignore_for_file: depend_on_referenced_packages
import 'package:audio_session/audio_session_web.dart';
import 'package:connectivity_plus_web/connectivity_plus_web.dart';
import 'package:desktop_drop/desktop_drop_web.dart';
import 'package:device_info_plus_web/device_info_plus_web.dart';
import 'package:file_picker/_internal/file_picker_web.dart';
import 'package:file_selector_web/file_selector_web.dart';
import 'package:flutter_keyboard_visibility_web/flutter_keyboard_visibility_web.dart';
import 'package:flutter_native_splash/flutter_native_splash_web.dart';
import 'package:flutter_secure_storage_web/flutter_secure_storage_web.dart';
import 'package:flutter_web_auth/src/flutter_web_auth_web.dart';
import 'package:geolocator_web/geolocator_web.dart';
import 'package:image_picker_for_web/image_picker_for_web.dart';
import 'package:just_audio_web/just_audio_web.dart';
import 'package:package_info_plus_web/package_info_plus_web.dart';
import 'package:record_web/record_web.dart';
import 'package:share_plus_web/share_plus_web.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:uni_links_web/uni_links_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart';
import 'package:wakelock_web/wakelock_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
AudioSessionWeb.registerWith(registrar);
ConnectivityPlusPlugin.registerWith(registrar);
DesktopDropWeb.registerWith(registrar);
DeviceInfoPlusPlugin.registerWith(registrar);
FilePickerWeb.registerWith(registrar);
FileSelectorWeb.registerWith(registrar);
FlutterKeyboardVisibilityPlugin.registerWith(registrar);
FlutterNativeSplashWeb.registerWith(registrar);
FlutterSecureStorageWeb.registerWith(registrar);
FlutterWebAuthPlugin.registerWith(registrar);
GeolocatorPlugin.registerWith(registrar);
ImagePickerPlugin.registerWith(registrar);
JustAudioPlugin.registerWith(registrar);
PackageInfoPlugin.registerWith(registrar);
RecordPluginWeb.registerWith(registrar);
SharePlusPlugin.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar);
UniLinksPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar);
VideoPlayerPlugin.registerWith(registrar);
WakelockWeb.registerWith(registrar);
registrar.registerMessageHandler();
}

View File

@ -240,13 +240,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
bool webHasFocus = true;
String? get activeRoomId {
try {
return VRouter.of(navigatorContext).pathParameters['roomid'];
} catch (_) {
return null;
}
}
String? get activeRoomId =>
VRouter.of(navigatorContext).pathParameters['roomid'];
final linuxNotifications =
PlatformInfos.isLinux ? NotificationsClient() : null;

View File

@ -0,0 +1,72 @@
#!/usr/bin/env bash
if [ -z "$HOMESERVER" ]; then
echo "Please ensure HOMESERVER environment variable is set to the IP or hostname of the homeserver."
exit 1
fi
if [ -z "$USER1_NAME" ]; then
echo "Please ensure USER1_NAME environment variable is set to first user name."
exit 1
fi
if [ -z "$USER1_PW" ]; then
echo "Please ensure USER1_PW environment variable is set to first user password."
exit 1
fi
if [ -z "$USER2_NAME" ]; then
echo "Please ensure USER2_NAME environment variable is set to second user name."
exit 1
fi
if [ -z "$USER2_PW" ]; then
echo "Please ensure USER2_PW environment variable is set to second user password."
exit 1
fi
if ( docker images swayvnc-flutter:latest | grep swayvnc-flutter ) ; then
echo "Found swayvnc-flutter:latest, skipping image build..."
else
if [ -n "$FLUTTER_VERSION" ]; then
FLUTTER_VERSION="$(flutter --no-version-check --version | grep channel | awk '{ print $2 }')"
fi
docker build integration_test/desktop -t swayvnc-flutter:latest --build-arg flutter_version="$FLUTTER_VERSION"
fi
docker rm -f swayvnc-flutter || true
echo "Starting swayvnc-flutter container..."
docker run -i --rm --name swayvnc-flutter -e XDG_RUNTIME_DIR=/tmp -v "$(pwd)":/project \
-e WLR_BACKENDS=headless \
-e WLR_LIBINPUT_NO_DEVICES=1 \
-e SWAYSOCK=/tmp/sway-ipc.sock \
-p :5910:5910 \
-p :7023:7023 \
swayvnc-flutter:latest &
killall soccat || true
if [ -f /tmp/swayip ]; then
rm /tmp/swayip
fi
echo "Opening Sway socket communication..."
sleep 10
socat UNIX-LISTEN:/tmp/swayipc,fork TCP:127.0.0.1:7023 &
echo "Starting integration test..."
SWAYSOCK=/tmp/swayipc swaymsg exec "foot sh -c \"cd /project && flutter --no-version-check pub get && flutter --no-version-check test integration_test -d linux --dart-define=HOMESERVER=$HOMESERVER --dart-define=USER1_NAME=$USER1_NAME --dart-define=USER2_NAME=$USER2_NAME --dart-define=USER1_PW=$USER1_PW --dart-define=USER2_PW=$USER2_PW || ( sleep 10 && exit 1 )\""
while [ -z "$(SWAYSOCK=/tmp/swayipc swaymsg exec \"pgrep foot\")" ]; do
sleep 10
done
if [ ! -d output ]; then
mkdir output
fi
docker run -t -e VR_VNC_HOST="$LISTEN_ADDRESS" -e VR_VNC_PORT=5910 -e VR_OUTFILE=/output/linux-integration-test.mp4 \
-v "$(pwd)/output":/output widerin/vnc-recorder &
docker stop swayvnc-flutter