From 9898a953f00a893a013371a61bcd21ccd8099fdd Mon Sep 17 00:00:00 2001 From: Mikhail Novosyolov Date: Mon, 25 Apr 2022 20:24:12 +0300 Subject: [PATCH] Add GUI to trigger connection Reading width and height is not implemented yet --- .gear/doskast.spec | 3 ++ Makefile | 2 ++ server-watcher/doskast-server-watcher.sh | 3 ++ .../doskast-student-connect.desktop | 11 ++++++ student-connect/doskast-student-connect.sh | 36 +++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100755 student-connect/doskast-student-connect.desktop diff --git a/.gear/doskast.spec b/.gear/doskast.spec index 9a18f9b..916bebd 100644 --- a/.gear/doskast.spec +++ b/.gear/doskast.spec @@ -40,6 +40,7 @@ Requires(pre): apache2-base Summary: Doskast for client (student) Group: Graphical desktop/Other Requires: curl +Requires: xdpyinfo Requires: xpra Requires: zenity Requires: %{_bindir}/pkexec @@ -49,11 +50,13 @@ Requires: %{_bindir}/pkexec %files student %{_bindir}/doskast-student-config +%{_bindir}/doskast-student-connect %{_bindir}/doskast-xpra-shadow %{_sbindir}/doskast-student-config %{_unitdir}/doskast-xpra-shadow.service %{_unitdir}/doskast-xpra-shadow.socket %{_datadir}/applications/doskast-student-config.desktop +%{_datadir}/applications/doskast-student-connect.desktop %{_datadir}/polkit-1/actions/ru.mos.doskast-student-config.policy %{_sysconfdir}/xdg/autostart/doskast-xpra-shadow.desktop %config(noreplace) %{_sysconfdir}/systemd/system/doskast-xpra-shadow.service.d/xpra-shadow-firewall.conf diff --git a/Makefile b/Makefile index af2f24f..45ee4b3 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ install: echo -e '#!/bin/sh\npkexec $(SBINDIR)/doskast-student-config "$$@"' > $(DESTDIR)$(BINDIR)/doskast-student-config chmod 0755 $(DESTDIR)$(BINDIR)/doskast-student-config install -m0755 xpra-shadow/doskast-xpra-shadow.sh $(DESTDIR)$(BINDIR)/doskast-xpra-shadow + install -m0755 student-connect/doskast-student-connect.sh $(DESTDIR)$(BINDIR)/doskast-student-connect mkdir -p --mode=0755 $(DESTDIR)$(SYSCONFDIR)/xdg/autostart install -m0644 server-watcher/doskast-server-watcher.desktop $(DESTDIR)$(SYSCONFDIR)/xdg/autostart @@ -37,3 +38,4 @@ install: mkdir -p --mode=0755 $(DESTDIR)$(DATADIR)/applications install -m0644 student-config/doskast-student-config.desktop $(DESTDIR)$(DATADIR)/applications + install -m0644 student-connect/doskast-student-connect.desktop $(DESTDIR)$(DATADIR)/applications diff --git a/server-watcher/doskast-server-watcher.sh b/server-watcher/doskast-server-watcher.sh index 45350ff..f77924d 100755 --- a/server-watcher/doskast-server-watcher.sh +++ b/server-watcher/doskast-server-watcher.sh @@ -17,6 +17,9 @@ _main_server_watcher(){ local target target="$(head -n 1 "$dir/$line" | _safe_param_stdin)" test -n "$target" + # TODO: calculate scale factor for xpra based on width and height + # https://unix.stackexchange.com/a/400791 + #IFS=', =' read -a area < <(xprop -root '_NET_WORKAREA') # log how xpra is run into ~/.xsession-errors* ( set -x ; xpra attach tcp://"$target":4648 ) & # XXX TODO: this fails for now, fix permissions and try to avoid 777 diff --git a/student-connect/doskast-student-connect.desktop b/student-connect/doskast-student-connect.desktop new file mode 100755 index 0000000..b74a354 --- /dev/null +++ b/student-connect/doskast-student-connect.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=Doskast Connect +Name[ru]=Соединение Doskast +Comment=Make board cast screen of this computer +Comment[ru]=Запуск трансляции экрана этого компьютера на доске +Exec=doskast-student-connect +# TODO: a better icon +Icon=network-wireless-hotspot +Type=Application +Terminal=false +Categories=Education; diff --git a/student-connect/doskast-student-connect.sh b/student-connect/doskast-student-connect.sh index 05a7907..b21c8cd 100755 --- a/student-connect/doskast-student-connect.sh +++ b/student-connect/doskast-student-connect.sh @@ -1,2 +1,38 @@ #!/bin/bash +set -e +set -f +set -u +set -o pipefail + +_zenity(){ + zenity --width=250 --title="Doskast" "$@" +} + +readonly config="/etc/doskastrc" + +if ! . /etc/doskastrc ; then + # || : to stabilize return code if clicking "Cancel" in zenity + _zenity --error --text="Нет файла с настройками Doskast, запустите программу настройки!" || : + exit 1 +fi + +if [ -z "${board:-}" ]; then + _zenity --error --text="Неправильный файл настроек Doskast, запустите программу настройки!" || : + exit 1 +fi + +IFS='x' read -a area < <(xdpyinfo | grep -oP 'dimensions:\s+\K\S+') +width="${area[0]}" +height="${area[1]}" +if [ -z "$width" ] || [ -z "$height" ]; then + _zenity --error --text="Ошибка получения геометрии экрана." || : + exit 1 +fi + +if ! curl --fail "http://${board}/cgi-bin/doskast-trigger-connect.cgi?width=${width}&height=${height}"; then + _zenity --error --text="Ошибка отправки запроса на доску." || : + exit 1 +fi + +_zenity --info --text="На доску отправлен запрос на трансляцию экрана этого компьютера." || :