From fed9372b35a1b5817b664d61b0d7dc5638d90249 Mon Sep 17 00:00:00 2001 From: AramJonghu Date: Tue, 30 Jun 2026 01:54:22 +0200 Subject: [PATCH] refactor(tickingservice): flatten nested if blocks with early returns --- Plugins/ZShell/Services/tickingservice.cpp | 61 +++++++++++++--------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/Plugins/ZShell/Services/tickingservice.cpp b/Plugins/ZShell/Services/tickingservice.cpp index 4485d86..5c51cdc 100644 --- a/Plugins/ZShell/Services/tickingservice.cpp +++ b/Plugins/ZShell/Services/tickingservice.cpp @@ -10,43 +10,52 @@ namespace ZShell::services { TickingService::TickingService(QObject* parent) - : Service(parent) - , m_timer(new QTimer(this)) { + : Service(parent), m_timer(new QTimer(this)) { m_timer->setSingleShot(false); - QObject::connect(m_timer, &QTimer::timeout, this, [this] { - tick(); - }); + QObject::connect(m_timer, &QTimer::timeout, this, [this] { tick(); }); - QString configPath = QDir::homePath() + QStringLiteral("/.config/zshell/config.json"); + QString configPath = + QDir::homePath() + QStringLiteral("/.config/zshell/config.json"); auto reloadConfig = [this, configPath]() { - QFile file(configPath); - if (file.open(QIODevice::ReadOnly)) { - QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); - if (!doc.isNull()) { - QJsonObject dashboard = doc.object().value("dashboard").toObject(); - if (dashboard.contains("resourceUpdateInterval")) { - applyInterval(dashboard.value("resourceUpdateInterval").toInt(1000)); - } - } - } - }; + QFile file(configPath); + if (!file.open(QIODevice::ReadOnly)) { + return; + } + QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); + if (doc.isNull()) { + return; + } + QJsonObject dashboard = doc.object().value("dashboard").toObject(); + if (dashboard.contains("resourceUpdateInterval")) { + applyInterval( + dashboard.value("resourceUpdateInterval").toInt(1000)); + } + }; reloadConfig(); static auto* watcher = new QFileSystemWatcher(); if (!watcher->files().contains(configPath)) { - QObject::connect(watcher, &QFileSystemWatcher::fileChanged, this, [this, configPath]() { + QObject::connect( + watcher, + &QFileSystemWatcher::fileChanged, + this, + [this, configPath]() { QTimer::singleShot(100, this, [this, configPath]() { QFile file(configPath); - if (file.exists()) { - QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); - if (!doc.isNull()) { - QJsonObject dashboard = doc.object().value("dashboard").toObject(); - if (dashboard.contains("resourceUpdateInterval")) { - applyInterval(dashboard.value("resourceUpdateInterval").toInt(1000)); - } - } + if (!file.exists()) { + return; + } + QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); + if (doc.isNull()) { + return; + } + QJsonObject dashboard = + doc.object().value("dashboard").toObject(); + if (dashboard.contains("resourceUpdateInterval")) { + applyInterval(dashboard.value("resourceUpdateInterval") + .toInt(1000)); } }); });