A slow daemon (17-22 s per request during the 2026-11-14 hang) made every 3 s poll open new status + policy requests on top of the unanswered ones. Now each verb has at most one request in flight, and failed status polls back off 2x per failure up to 30 s, restoring the normal rate on success. (The tray's ~1 core of CPU at the time is not yet root-caused: profiling it needs root here; see the Tracy setup follow-up.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
#ifndef STRAWBERRY_APP_APP_CONTROLLER_HPP
|
|
#define STRAWBERRY_APP_APP_CONTROLLER_HPP
|
|
|
|
#include "strawberry/evidence_store.hpp"
|
|
#include "autostart.hpp"
|
|
#include "tray_state.hpp"
|
|
|
|
#include <QJsonObject>
|
|
#include <QObject>
|
|
#include <QSet>
|
|
#include <QSettings>
|
|
#include <QString>
|
|
|
|
class QTimer;
|
|
|
|
namespace strawberry::app {
|
|
|
|
class DaemonClient;
|
|
class MainWindow;
|
|
class Notifier;
|
|
class Tray;
|
|
|
|
struct AppOptions {
|
|
QString socket_path;
|
|
QString db_path_override; // empty = use the daemon's reported path
|
|
bool show_window = false;
|
|
QString initial_tab;
|
|
bool tray = true;
|
|
int poll_ms = 3000;
|
|
};
|
|
|
|
/// Owns the tray, window, daemon client and evidence store; drives polling.
|
|
class AppController : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit AppController(AppOptions options, QObject* parent = nullptr);
|
|
~AppController() override;
|
|
|
|
void start();
|
|
void show_window();
|
|
|
|
private:
|
|
void poll();
|
|
void on_reply(const QString& verb, bool ok, const QJsonObject& data, const QString& error);
|
|
void refresh_evidence(bool force_view_refresh);
|
|
void update_tray();
|
|
void notify_new_findings();
|
|
void mark_seen(const QString& id, qint64 last_seen);
|
|
void mark_all_seen();
|
|
void set_autostart(bool enable);
|
|
void show_autostart_state(const QString& error = {});
|
|
std::vector<FindingSummary> finding_summaries() const;
|
|
|
|
static AckMap load_map(const QSettings& settings, const QString& key);
|
|
static void save_map(QSettings& settings, const QString& key, const AckMap& map);
|
|
|
|
AppOptions options_;
|
|
QSettings settings_;
|
|
EvidenceStore store_;
|
|
DaemonClient* client_ = nullptr;
|
|
Tray* tray_ = nullptr;
|
|
Notifier* notifier_ = nullptr;
|
|
MainWindow* window_ = nullptr;
|
|
QTimer* timer_ = nullptr;
|
|
|
|
DaemonSnapshot snapshot_;
|
|
QJsonObject status_;
|
|
QString status_error_;
|
|
uint64_t previous_scan_errors_ = 0;
|
|
bool first_evidence_load_ = true;
|
|
// Poll hygiene: one outstanding status/policy request at a time, and back off while the daemon
|
|
// is not answering (a slow daemon otherwise collects a pile of overlapping requests per poll).
|
|
bool status_in_flight_ = false;
|
|
bool policy_in_flight_ = false;
|
|
int failed_polls_ = 0;
|
|
AckMap seen_;
|
|
AckMap notified_;
|
|
TrayState tray_state_;
|
|
QSet<QString> known_containments_;
|
|
bool containments_seeded_ = false;
|
|
AutostartEnv autostart_env_;
|
|
QString tray_exec_;
|
|
};
|
|
|
|
} // namespace strawberry::app
|
|
|
|
#endif // STRAWBERRY_APP_APP_CONTROLLER_HPP
|