Add checks and fixes for avahi daemon

This commit is contained in:
Patrick Nicolas
2025-10-26 13:46:03 +01:00
parent e7c0c008a3
commit 38e345025e
4 changed files with 128 additions and 0 deletions
+1
View File
@@ -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
+59
View File
@@ -0,0 +1,59 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "avahi.h"
#include "dashboard_utils.h"
#include "escape_sandbox.h"
#include <QDBusInterface>
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();
});
}
+44
View File
@@ -0,0 +1,44 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QObject>
#include <QtQml/qqmlregistration.h>
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);
};
+24
View File
@@ -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")