From 2f8b78e2a694c7ae69ce834c8bffd13c20f30804 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sun, 16 Feb 2025 19:46:00 -0500 Subject: [PATCH] refactor: new private MainWindow method localhostFingerprintDb --- src/apps/deskflow-gui/MainWindow.cpp | 30 ++++++++++------------------ src/apps/deskflow-gui/MainWindow.h | 1 + 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index be1a6f6c9..ee81c4d10 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -160,14 +160,13 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) // Force generation of SHA256 for the localhost if (m_appConfig.tlsEnabled()) { - auto localPath = QStringLiteral("%1/%2").arg(getTlsPath(), kFingerprintLocalFilename); - if (!QFile::exists(localPath)) { + if (!QFile::exists(localFingerPrintDb())) { regenerateLocalFingerprints(); return; } deskflow::FingerprintDatabase db; - db.read(localPath.toStdString()); + db.read(localFingerPrintDb().toStdString()); if (db.fingerprints().size() != kTlsDbSize) { regenerateLocalFingerprints(); } @@ -486,15 +485,14 @@ void MainWindow::updateSize() void MainWindow::showMyFingerprint() { - auto localPath = QStringLiteral("%1/%2").arg(getTlsPath(), kFingerprintLocalFilename); - if (!QFile::exists(localPath)) { + if (!QFile::exists(localFingerPrintDb())) { if (regenerateLocalFingerprints()) showMyFingerprint(); return; } deskflow::FingerprintDatabase db; - db.read(localPath.toStdString()); + db.read(localFingerPrintDb().toStdString()); if (db.fingerprints().size() != kTlsDbSize) { if (regenerateLocalFingerprints()) showMyFingerprint(); @@ -952,20 +950,7 @@ QString MainWindow::getIPAddresses() const void MainWindow::updateLocalFingerprint() { - bool fingerprintExists = false; - try { - auto localPath = QStringLiteral("%1/%2").arg(getTlsPath(), kFingerprintLocalFilename); - fingerprintExists = QFile::exists(localPath); - } catch (const std::exception &e) { - qDebug() << e.what(); - qFatal() << "failed to check if fingerprint exists"; - } - - if (m_appConfig.tlsEnabled() && fingerprintExists) { - ui->lblMyFingerprint->setVisible(true); - } else { - ui->lblMyFingerprint->setVisible(false); - } + ui->lblMyFingerprint->setVisible(m_appConfig.tlsEnabled() && QFile::exists(localFingerPrintDb())); } void MainWindow::autoAddScreen(const QString name) @@ -1086,6 +1071,11 @@ QString MainWindow::getTlsPath() return QStringLiteral("%1/%2").arg(coreTool.getProfileDir(), kSslDir); } +QString MainWindow::localFingerPrintDb() +{ + return QStringLiteral("%1/%2").arg(getTlsPath(), kFingerprintLocalFilename); +} + bool MainWindow::regenerateLocalFingerprints() { TlsCertificate tls; diff --git a/src/apps/deskflow-gui/MainWindow.h b/src/apps/deskflow-gui/MainWindow.h index fe53c0f5d..174272019 100644 --- a/src/apps/deskflow-gui/MainWindow.h +++ b/src/apps/deskflow-gui/MainWindow.h @@ -166,6 +166,7 @@ private: void showAndActivate(); QString getTlsPath(); + QString localFingerPrintDb(); // Generate prints if they are missing // Returns true if successful