Skip to content

Commit f4cb326

Browse files
committed
feat(diagnose): check and enable Avahi Daemon
1 parent aaa5e56 commit f4cb326

5 files changed

Lines changed: 87 additions & 11 deletions

File tree

lib/zupdater

src/diagnosewidget.cpp

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,21 @@ void DependencyItem::setInstalled(bool installed)
9090
setChecking(false);
9191

9292
if (installed) {
93-
m_statusLabel->setText("✓ Installed");
93+
if (m_name == "Avahi Daemon") {
94+
m_statusLabel->setText("✓ Activated");
95+
} else {
96+
m_statusLabel->setText("✓ Installed");
97+
}
9498
m_statusLabel->setStyleSheet("color: green; font-weight: bold;");
9599
m_installButton->setVisible(false);
96100
} else {
97-
m_statusLabel->setText("✗ Not Installed");
101+
if (m_name == "Avahi Daemon") {
102+
m_statusLabel->setText("✗ Not activated");
103+
m_installButton->setText("Enable");
104+
} else {
105+
m_statusLabel->setText("✗ Not Installed");
106+
m_installButton->setText("Install");
107+
}
98108
m_statusLabel->setStyleSheet("color: red; font-weight: bold;");
99109
m_installButton->setVisible(true);
100110
}
@@ -133,17 +143,19 @@ DiagnoseWidget::DiagnoseWidget(QWidget *parent)
133143
setupUI();
134144

135145
#ifdef WIN32
136-
// Add dependency items
137146
addDependencyItem("Apple Mobile Device Support",
138147
"Required for iOS device communication");
139148
addDependencyItem("WinFsp", "Required for mounting your device as a drive");
140149
#endif
141150

142151
#ifdef __linux__
143-
// Add Linux-specific dependency items
152+
#ifdef ENABLE_RECOVERY_DEVICE_SUPPORT
144153
addDependencyItem("USB Device Permissions",
145154
"Required for recovery devices (udev rules)");
146155
#endif
156+
addDependencyItem("Avahi Daemon",
157+
"Required for Airplay, device discovery and more");
158+
#endif
147159

148160
// Auto-check on startup
149161
QTimer::singleShot(100, this, [this]() { checkDependencies(); });
@@ -238,6 +250,8 @@ void DiagnoseWidget::checkDependencies(bool autoExpand)
238250
#ifdef __linux__
239251
if (itemName == "USB Device Permissions") {
240252
installed = checkUdevRulesInstalled();
253+
} else if (itemName == "Avahi Daemon") {
254+
installed = checkAvahiDaemonRunning();
241255
}
242256
#endif
243257

@@ -248,7 +262,7 @@ void DiagnoseWidget::checkDependencies(bool autoExpand)
248262

249263
if (installedCount == totalCount) {
250264
m_summaryLabel->setText(
251-
QString("All dependencies are installed (%1/%2)")
265+
QString("All dependencies are installed/activated (%1/%2)")
252266
.arg(installedCount)
253267
.arg(totalCount));
254268
m_summaryLabel->setStyleSheet("color: green; font-weight: bold;");
@@ -497,6 +511,54 @@ void DiagnoseWidget::onInstallRequested(const QString &name)
497511
args << scriptPath << userName;
498512
installProcess->start("pkexec", args);
499513
}
514+
515+
if (name == "Avahi Daemon") {
516+
DependencyItem *itemToInstall = nullptr;
517+
for (DependencyItem *item : m_dependencyItems) {
518+
if (item->property("name").toString() == name) {
519+
itemToInstall = item;
520+
break;
521+
}
522+
}
523+
524+
if (!itemToInstall)
525+
return;
526+
527+
itemToInstall->setInstalling(true);
528+
529+
QProcess *installProcess = new QProcess(this);
530+
connect(
531+
installProcess, &QProcess::finished, this,
532+
[this, installProcess,
533+
itemToInstall](int exitCode, QProcess::ExitStatus exitStatus) {
534+
if (exitStatus != QProcess::NormalExit || exitCode != 0) {
535+
QString errorOutput =
536+
installProcess->readAllStandardError();
537+
if (errorOutput.isEmpty()) {
538+
errorOutput = installProcess->readAllStandardOutput();
539+
}
540+
QMessageBox::warning(
541+
this, "Error",
542+
"Failed to enable Avahi daemon. "
543+
"This might be because the action was cancelled or an "
544+
"error occurred.\n\nDetails: " +
545+
errorOutput.trimmed());
546+
checkDependencies(false);
547+
} else {
548+
checkDependencies(false);
549+
}
550+
itemToInstall->setInstalling(false);
551+
installProcess->deleteLater();
552+
});
553+
554+
QStringList args;
555+
args << "systemctl"
556+
<< "enable"
557+
<< "--now"
558+
<< "avahi-daemon.service";
559+
installProcess->start("pkexec", args);
560+
}
561+
500562
#endif
501563
}
502564

@@ -546,6 +608,22 @@ bool DiagnoseWidget::checkUdevRulesInstalled()
546608

547609
return isInIdeviceGroup;
548610
}
611+
612+
bool DiagnoseWidget::checkAvahiDaemonRunning()
613+
{
614+
QProcess checkProcess;
615+
checkProcess.start("systemctl", QStringList()
616+
<< "is-active" << "avahi-daemon");
617+
checkProcess.waitForFinished(3000);
618+
619+
if (checkProcess.exitCode() != 0) {
620+
return false;
621+
}
622+
623+
QString output =
624+
QString::fromUtf8(checkProcess.readAllStandardOutput()).trimmed();
625+
return output == "active";
626+
}
549627
#endif
550628

551629
void DiagnoseWidget::onToggleExpand()

src/diagnosewidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private slots:
7777

7878
#ifdef __linux__
7979
bool checkUdevRulesInstalled();
80+
bool checkAvahiDaemonRunning();
8081
#endif
8182

8283
QVBoxLayout *m_mainLayout;

src/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,5 @@ MainWindow::~MainWindow()
369369
#endif
370370
delete ui;
371371
delete m_updater;
372-
sleep(2); // Give some time for cleanup to finish
372+
sleep(2);
373373
}

src/welcomewidget.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ void WelcomeWidget::setupUI()
9090

9191
m_mainLayout->addWidget(m_githubLabel, 0, Qt::AlignCenter);
9292

93-
// FIXME: we need to disable specific deps in diagnosewidget
94-
// not the whole widget when EnableRecoveryDeviceSupport is off
9593
// no additional deps needed on macOS
96-
#if !defined(__APPLE__) && defined(ENABLE_RECOVERY_DEVICE_SUPPORT)
97-
94+
#ifndef __APPLE__
9895
DiagnoseWidget *diagnoseWidget = new DiagnoseWidget();
9996
m_mainLayout->addWidget(diagnoseWidget);
10097
#endif

0 commit comments

Comments
 (0)