strawberry/app/app_controller.hpp
trvon 2e5637fe6c
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Add "Start at login" to the tray app
A checkable tray menu item and a Diagnostics-tab checkbox write or
remove ~/.config/autostart/strawberry-tray.desktop (XDG autostart,
atomic write), pointing at the installed strawberry-tray when there is
one. Sessions that do not run autostart entries on their own (sway, i3,
Hyprland, niri without uwsm/dex) get a note with the exact line to add
to the compositor config instead of a silent no-op; GNOME, KDE, XFCE and
the like, or an active xdg-desktop-autostart.target, need nothing more.

The logic is Qt-free (app/autostart.cpp) with a unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:59:52 -06:00

83 lines
2.2 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;
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