diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index 319216f2..ab6702a8 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -7,6 +7,7 @@ include(I18n) ecm_find_qmlmodule(org.kde.kirigami REQUIRED) add_executable(wivrn-dashboard + avahi.cpp main.cpp wivrn_server.cpp wivrn_qdbus_types.cpp diff --git a/dashboard/avahi.cpp b/dashboard/avahi.cpp new file mode 100644 index 00000000..f9d6acbc --- /dev/null +++ b/dashboard/avahi.cpp @@ -0,0 +1,59 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "avahi.h" + +#include "dashboard_utils.h" +#include "escape_sandbox.h" + +#include + +bool avahi::installed() +{ + return not find_executable("avahi-daemon").isEmpty(); +} + +bool avahi::running() +{ + QDBusInterface dbus = QDBusInterface("org.freedesktop.Avahi", "/", "org.freedesktop.Avahi.Server", QDBusConnection::systemBus()); + return dbus.isValid(); +} + +bool avahi::canStart() +{ + return not(find_executable("systemctl").isEmpty() or find_executable("pkexec").isEmpty()); +} + +void avahi::start() +{ + auto pkexec = escape_sandbox("pkexec", + "systemctl", + "enable", + "--now", + "avahi-daemon.service"); + pkexec->setProcessChannelMode(QProcess::MergedChannels); + pkexec->start(); + auto ptr = pkexec.get(); + + QObject::connect(ptr, &QProcess::finished, this, [this, pkexec = std::move(pkexec)](int exit_code, QProcess::ExitStatus exit_status) mutable { + if (exit_status != QProcess::NormalExit or exit_code) + qWarning() << "avahi daemon start failed with status " << exit_status << "and code" << exit_code; + runningChanged(running()); + pkexec.release()->deleteLater(); + }); +} diff --git a/dashboard/avahi.h b/dashboard/avahi.h new file mode 100644 index 00000000..0edd3fe0 --- /dev/null +++ b/dashboard/avahi.h @@ -0,0 +1,44 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +class avahi : public QObject +{ +public: + Q_OBJECT + QML_NAMED_ELEMENT(Avahi) + QML_SINGLETON + + Q_PROPERTY(bool installed READ installed NOTIFY installChanged) + Q_PROPERTY(bool running READ running NOTIFY runningChanged) + Q_PROPERTY(bool canStart READ canStart CONSTANT) +public: + bool installed(); + bool running(); + + bool canStart(); + Q_INVOKABLE void start(); + +Q_SIGNALS: + void installChanged(bool); + void runningChanged(bool); +}; diff --git a/dashboard/qml/Main.qml b/dashboard/qml/Main.qml index 685d6c09..e810fb3d 100644 --- a/dashboard/qml/Main.qml +++ b/dashboard/qml/Main.qml @@ -124,6 +124,30 @@ Kirigami.ApplicationWindow { Repeater{ model: ObjectModel { id: messages + + Kirigami.InlineMessage { + Layout.fillWidth: true + text: i18n("Avahi daemon is not installed") + type: Kirigami.MessageType.Warning + showCloseButton: true + visible: settings.show_system_checks && !Avahi.installed + } + + Kirigami.InlineMessage { + Layout.fillWidth: true + text: i18n("Avahi daemon is not started") + type: Kirigami.MessageType.Warning + showCloseButton: true + visible: settings.show_system_checks && Avahi.installed && !Avahi.running + actions: [ + Kirigami.Action { + visible: Avahi.canStart + text: i18n("Fix it") + onTriggered: Avahi.start() + } + ] + } + Kirigami.InlineMessage { Layout.fillWidth: true text: i18n("The server does not have CAP_SYS_NICE capabilities")