Remove the browser UI, its Python server and the web API contract test. Add the Qt6 tray app (status, findings, process search, policy controls, notifications) and EvidenceStore, the read-only view of the daemon's evidence that the app and MCP server share. The GUI demo config becomes strawberry.demo.conf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
3.9 KiB
C++
116 lines
3.9 KiB
C++
#include "tray.hpp"
|
|
|
|
#include <QAction>
|
|
#include <QMenu>
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
#include <QPixmap>
|
|
#include <QSystemTrayIcon>
|
|
|
|
namespace strawberry::app {
|
|
|
|
namespace {
|
|
|
|
QColor level_color(TrayLevel level) {
|
|
switch (level) {
|
|
case TrayLevel::ok: return QColor(0x2e, 0xa0, 0x43);
|
|
case TrayLevel::warning: return QColor(0xe0, 0xa1, 0x00);
|
|
case TrayLevel::alert: return QColor(0xd7, 0x26, 0x38);
|
|
case TrayLevel::unknown: break;
|
|
}
|
|
return QColor(0x8a, 0x8f, 0x98);
|
|
}
|
|
|
|
// A small strawberry: state-coloured body, dark leaves, light seeds.
|
|
QPixmap paint_icon(TrayLevel level, int size) {
|
|
QPixmap pixmap(size, size);
|
|
pixmap.fill(Qt::transparent);
|
|
QPainter p(&pixmap);
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
const qreal s = size;
|
|
|
|
QPainterPath body;
|
|
body.moveTo(0.50 * s, 0.96 * s);
|
|
body.cubicTo(0.12 * s, 0.72 * s, 0.04 * s, 0.42 * s, 0.20 * s, 0.30 * s);
|
|
body.cubicTo(0.34 * s, 0.20 * s, 0.66 * s, 0.20 * s, 0.80 * s, 0.30 * s);
|
|
body.cubicTo(0.96 * s, 0.42 * s, 0.88 * s, 0.72 * s, 0.50 * s, 0.96 * s);
|
|
p.setPen(QPen(QColor(0, 0, 0, 120), s * 0.04));
|
|
p.setBrush(level_color(level));
|
|
p.drawPath(body);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(QColor(0x1f, 0x5f, 0x2c));
|
|
QPainterPath leaves;
|
|
leaves.moveTo(0.50 * s, 0.30 * s);
|
|
leaves.lineTo(0.24 * s, 0.14 * s);
|
|
leaves.lineTo(0.40 * s, 0.24 * s);
|
|
leaves.lineTo(0.50 * s, 0.04 * s);
|
|
leaves.lineTo(0.60 * s, 0.24 * s);
|
|
leaves.lineTo(0.76 * s, 0.14 * s);
|
|
leaves.closeSubpath();
|
|
p.drawPath(leaves);
|
|
|
|
p.setBrush(QColor(255, 255, 255, 200));
|
|
const qreal r = s * 0.035;
|
|
for (const auto& [x, y] : {std::pair{0.36, 0.45}, {0.64, 0.45}, {0.50, 0.55}, {0.40, 0.68}, {0.60, 0.68}, {0.50, 0.80}}) {
|
|
p.drawEllipse(QPointF(x * s, y * s), r, r * 1.4);
|
|
}
|
|
return pixmap;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
QIcon Tray::icon_for(TrayLevel level) {
|
|
QIcon icon;
|
|
for (const int size : {16, 22, 24, 32, 48, 64}) {
|
|
icon.addPixmap(paint_icon(level, size));
|
|
}
|
|
return icon;
|
|
}
|
|
|
|
Tray::Tray(QObject* parent) : QObject(parent) {
|
|
icon_ = new QSystemTrayIcon(icon_for(TrayLevel::unknown), this);
|
|
icon_->setToolTip(QStringLiteral("Strawberry: connecting…"));
|
|
|
|
auto* menu = new QMenu();
|
|
connect(this, &QObject::destroyed, menu, &QObject::deleteLater);
|
|
|
|
connect(menu->addAction(QStringLiteral("Open Strawberry")), &QAction::triggered,
|
|
this, &Tray::open_requested);
|
|
menu->addSeparator();
|
|
reload_action_ = menu->addAction(QStringLiteral("Reload rules"));
|
|
connect(reload_action_, &QAction::triggered, this, [this]() { emit command_requested(QStringLiteral("reload-rules")); });
|
|
rescan_action_ = menu->addAction(QStringLiteral("Rescan running processes"));
|
|
connect(rescan_action_, &QAction::triggered, this, [this]() { emit command_requested(QStringLiteral("rescan")); });
|
|
connect(menu->addAction(QStringLiteral("Mark all findings seen")), &QAction::triggered,
|
|
this, &Tray::mark_all_seen_requested);
|
|
menu->addSeparator();
|
|
connect(menu->addAction(QStringLiteral("Quit")), &QAction::triggered, this, &Tray::quit_requested);
|
|
icon_->setContextMenu(menu);
|
|
|
|
connect(icon_, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
|
if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick) {
|
|
emit open_requested();
|
|
}
|
|
});
|
|
}
|
|
|
|
void Tray::show() {
|
|
icon_->show();
|
|
}
|
|
|
|
void Tray::apply(const TrayState& state) {
|
|
if (!level_applied_ || state.level != level_) {
|
|
icon_->setIcon(icon_for(state.level));
|
|
level_ = state.level;
|
|
level_applied_ = true;
|
|
}
|
|
icon_->setToolTip(QString::fromStdString(state.tooltip));
|
|
}
|
|
|
|
void Tray::set_controls_enabled(bool enabled) {
|
|
reload_action_->setEnabled(enabled);
|
|
rescan_action_->setEnabled(enabled);
|
|
}
|
|
|
|
} // namespace strawberry::app
|