feat: add desktop start and native reminders
- Notify at schedule start and optionally N minutes before\n- Add reminder lead setting and TOML persistence\n- Use Linux DBus native notifications with action handling\n- Focus the matching block when a notification is clicked\n- Keep overdue reminders and update validation docs/screenshots
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Core Gui Widgets Sql Network Concurrent WebSockets Test)
|
||||
if(UNIX AND NOT APPLE)
|
||||
find_package(Qt6 REQUIRED COMPONENTS DBus)
|
||||
endif()
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
|
||||
@@ -115,6 +115,9 @@ target_link_libraries(schedule_ui
|
||||
PUBLIC schedule_ai schedule_sync Qt6::Widgets ElaWidgetTools
|
||||
PRIVATE schedule_warnings
|
||||
)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(schedule_ui PRIVATE Qt6::DBus)
|
||||
endif()
|
||||
|
||||
qt_add_executable(Schedule
|
||||
main.cpp
|
||||
|
||||
@@ -76,6 +76,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
ScheduleService scheduleService(store, settings.deviceId());
|
||||
NotificationService notificationService(scheduleService);
|
||||
notificationService.setLeadMinutes(settings.reminderLeadMinutes());
|
||||
AIService aiService(scheduleService, store, settings);
|
||||
SyncService syncService(scheduleService, store, settings);
|
||||
|
||||
|
||||
@@ -3,12 +3,43 @@
|
||||
#include <QAction>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#endif
|
||||
|
||||
#include "ElaMenu.h"
|
||||
#include "ui/AppIcon.h"
|
||||
|
||||
SystemTray::SystemTray(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
m_notifications = new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QDBusConnection::sessionBus(),
|
||||
this);
|
||||
if (m_notifications->isValid())
|
||||
{
|
||||
QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("ActionInvoked"),
|
||||
this,
|
||||
SLOT(handleDbusAction(uint, QString)));
|
||||
QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("NotificationClosed"),
|
||||
this,
|
||||
SLOT(handleDbusClosed(uint, uint)));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!QSystemTrayIcon::isSystemTrayAvailable())
|
||||
{
|
||||
return;
|
||||
@@ -33,7 +64,18 @@ SystemTray::SystemTray(QObject* parent)
|
||||
break;
|
||||
}
|
||||
});
|
||||
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this, &SystemTray::showRequested);
|
||||
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this, [this]() {
|
||||
if (!m_pendingBlockId.isEmpty())
|
||||
{
|
||||
const QString blockId = m_pendingBlockId;
|
||||
m_pendingBlockId.clear();
|
||||
Q_EMIT notificationClicked(blockId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_EMIT showRequested();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SystemTray::~SystemTray()
|
||||
@@ -73,13 +115,69 @@ void SystemTray::hide()
|
||||
|
||||
void SystemTray::showNotification(const QString& title, const QString& message, int timeoutMs)
|
||||
{
|
||||
showNotification(title, message, timeoutMs, QString());
|
||||
}
|
||||
|
||||
void SystemTray::showNotification(const QString& title,
|
||||
const QString& message,
|
||||
int timeoutMs,
|
||||
const QString& blockId)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
if (m_notifications && m_notifications->isValid())
|
||||
{
|
||||
QStringList actions;
|
||||
actions << QStringLiteral("default")
|
||||
<< (blockId.isEmpty() ? QStringLiteral("打开应用") : QStringLiteral("打开日程"));
|
||||
QVariantMap hints;
|
||||
hints.insert(QStringLiteral("desktop-entry"), QStringLiteral("Schedule"));
|
||||
const QDBusReply<uint> reply = m_notifications->call(QStringLiteral("Notify"),
|
||||
QStringLiteral("AI 日程"),
|
||||
0u,
|
||||
QStringLiteral("x-office-calendar"),
|
||||
title,
|
||||
message,
|
||||
actions,
|
||||
hints,
|
||||
timeoutMs);
|
||||
if (reply.isValid())
|
||||
{
|
||||
m_dbusTargets.insert(reply.value(), blockId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!m_trayIcon || !m_trayIcon->isVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_pendingBlockId = blockId;
|
||||
m_trayIcon->showMessage(title, message, QSystemTrayIcon::Information, timeoutMs);
|
||||
}
|
||||
|
||||
void SystemTray::handleDbusAction(uint id, const QString& key)
|
||||
{
|
||||
if (!key.isEmpty() && key != QStringLiteral("default"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
const QString blockId = m_dbusTargets.take(id);
|
||||
if (!blockId.isEmpty())
|
||||
{
|
||||
Q_EMIT notificationClicked(blockId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_EMIT showRequested();
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTray::handleDbusClosed(uint id, uint reason)
|
||||
{
|
||||
Q_UNUSED(reason)
|
||||
m_dbusTargets.remove(id);
|
||||
}
|
||||
|
||||
void SystemTray::setOverdueCount(int count)
|
||||
{
|
||||
m_overdueCount = count;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
@@ -27,12 +28,21 @@ public:
|
||||
void hide();
|
||||
|
||||
void showNotification(const QString& title, const QString& message, int timeoutMs = 6000);
|
||||
void showNotification(const QString& title,
|
||||
const QString& message,
|
||||
int timeoutMs,
|
||||
const QString& blockId);
|
||||
void setOverdueCount(int count);
|
||||
|
||||
signals:
|
||||
void showRequested();
|
||||
void newBlockRequested();
|
||||
void quitRequested();
|
||||
void notificationClicked(const QString& blockId);
|
||||
|
||||
private slots:
|
||||
void handleDbusAction(uint id, const QString& key);
|
||||
void handleDbusClosed(uint id, uint reason);
|
||||
|
||||
private:
|
||||
void rebuildMenu();
|
||||
@@ -41,4 +51,9 @@ private:
|
||||
ElaMenu* m_menu = nullptr;
|
||||
QAction* m_statusAction = nullptr;
|
||||
int m_overdueCount = 0;
|
||||
QString m_pendingBlockId;
|
||||
#ifdef Q_OS_LINUX
|
||||
class QDBusInterface* m_notifications = nullptr;
|
||||
QHash<uint, QString> m_dbusTargets;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -32,7 +32,8 @@ void NotificationService::stop()
|
||||
|
||||
void NotificationService::checkNow()
|
||||
{
|
||||
const QVector<ScheduleItem> current = m_scheduleService.overdueItems(QDateTime::currentDateTime());
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
const QVector<ScheduleItem> current = m_scheduleService.overdueItems(now);
|
||||
|
||||
QSet<QString> currentIds;
|
||||
currentIds.reserve(current.size());
|
||||
@@ -84,6 +85,55 @@ void NotificationService::checkNow()
|
||||
{
|
||||
Q_EMIT overdueListChanged(m_overdueItems);
|
||||
}
|
||||
|
||||
const QVector<ScheduleItem> upcoming =
|
||||
m_scheduleService.itemsForRange(now.date().addDays(-1), now.date().addDays(2));
|
||||
for (const ScheduleItem& item : upcoming)
|
||||
{
|
||||
if (item.block.status != QStringLiteral("scheduled") &&
|
||||
item.block.status != QStringLiteral("in_progress"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!item.block.startAt.isValid() || !item.block.endAt.isValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const QString startKey = QStringLiteral("%1@%2")
|
||||
.arg(item.block.id,
|
||||
item.block.startAt.toUTC().toString(Qt::ISODateWithMs));
|
||||
if (m_leadMinutes > 0 && now >= item.block.startAt.addSecs(-m_leadMinutes * 60) &&
|
||||
now < item.block.startAt)
|
||||
{
|
||||
const QString leadKey = QStringLiteral("%1@%2").arg(startKey).arg(m_leadMinutes);
|
||||
if (!m_leadNotifiedKeys.contains(leadKey))
|
||||
{
|
||||
m_leadNotifiedKeys.insert(leadKey);
|
||||
Q_EMIT leadReminderDue(item, m_leadMinutes);
|
||||
}
|
||||
}
|
||||
if (now >= item.block.startAt &&
|
||||
now < item.block.endAt &&
|
||||
now < item.block.startAt.addSecs(10 * 60))
|
||||
{
|
||||
const QString key = startKey + QStringLiteral("@start");
|
||||
if (!m_startNotifiedKeys.contains(key))
|
||||
{
|
||||
m_startNotifiedKeys.insert(key);
|
||||
Q_EMIT startReminderDue(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int NotificationService::leadMinutes() const
|
||||
{
|
||||
return m_leadMinutes;
|
||||
}
|
||||
|
||||
void NotificationService::setLeadMinutes(int minutes)
|
||||
{
|
||||
m_leadMinutes = qBound(0, minutes, 24 * 60);
|
||||
}
|
||||
|
||||
QVector<ScheduleItem> NotificationService::overdueItems() const
|
||||
|
||||
@@ -26,13 +26,21 @@ public:
|
||||
void checkNow();
|
||||
QVector<ScheduleItem> overdueItems() const;
|
||||
|
||||
int leadMinutes() const;
|
||||
void setLeadMinutes(int minutes);
|
||||
|
||||
signals:
|
||||
void overdueDetected(const ScheduleItem& item);
|
||||
void leadReminderDue(const ScheduleItem& item, int minutesBefore);
|
||||
void startReminderDue(const ScheduleItem& item);
|
||||
void overdueListChanged(const QVector<ScheduleItem>& items);
|
||||
|
||||
private:
|
||||
ScheduleService& m_scheduleService;
|
||||
QTimer m_timer;
|
||||
QSet<QString> m_notifiedIds;
|
||||
QSet<QString> m_leadNotifiedKeys;
|
||||
QSet<QString> m_startNotifiedKeys;
|
||||
QVector<ScheduleItem> m_overdueItems;
|
||||
int m_leadMinutes = 10;
|
||||
};
|
||||
|
||||
@@ -1145,6 +1145,21 @@ bool ScheduleService::applyProposedCreates(const ProposedDiff& diff,
|
||||
return applyProposedDiff(diff, acceptedTempIds, error);
|
||||
}
|
||||
|
||||
std::optional<ScheduleItem> ScheduleService::itemForBlock(const QString& blockId) const
|
||||
{
|
||||
const auto block = m_store.timeBlockById(blockId);
|
||||
if (!block.has_value())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto task = m_store.taskById(block->taskId);
|
||||
if (!task.has_value())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return ScheduleItem{*task, *block};
|
||||
}
|
||||
|
||||
QVector<ScheduleItem> ScheduleService::itemsForDay(const QDate& date) const
|
||||
{
|
||||
auto items = m_store.blocksInRange(DateTimeUtils::localDayStartUtc(date),
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
QString* error = nullptr);
|
||||
|
||||
QVector<ScheduleItem> itemsForDay(const QDate& date) const;
|
||||
std::optional<ScheduleItem> itemForBlock(const QString& blockId) const;
|
||||
// 返回 [from, to] 闭区间内的所有日程,按开始时间升序。
|
||||
QVector<ScheduleItem> itemsForRange(const QDate& from, const QDate& to) const;
|
||||
QVector<ScheduleItem> overdueItems(const QDateTime& now = QDateTime::currentDateTime()) const;
|
||||
|
||||
@@ -193,6 +193,14 @@ void CompactWindow::buildUi()
|
||||
void CompactWindow::setupTray()
|
||||
{
|
||||
m_tray = new SystemTray(this);
|
||||
connect(m_tray, &SystemTray::notificationClicked, this, [this](const QString& blockId) {
|
||||
const auto item = m_scheduleService.itemForBlock(blockId);
|
||||
openSchedule();
|
||||
if (m_scheduleWindow && item.has_value())
|
||||
{
|
||||
m_scheduleWindow->focusBlock(item->block.startAt.date(), blockId);
|
||||
}
|
||||
});
|
||||
if (!SystemTray::isAvailable())
|
||||
{
|
||||
return;
|
||||
@@ -276,7 +284,7 @@ void CompactWindow::connectSignals()
|
||||
QStringLiteral("「%1」原定 %2 尚未完成,点击打开处理。")
|
||||
.arg(item.task.title,
|
||||
DateTimeUtils::formatTimeRange(item.block.startAt, item.block.endAt));
|
||||
m_tray->showNotification(QStringLiteral("日程超时"), body);
|
||||
m_tray->showNotification(QStringLiteral("日程超时"), body, 6000, item.block.id);
|
||||
}
|
||||
if (isVisible())
|
||||
{
|
||||
@@ -288,6 +296,26 @@ void CompactWindow::connectSignals()
|
||||
}
|
||||
});
|
||||
|
||||
connect(&m_notificationService, &NotificationService::leadReminderDue, this, [this](const ScheduleItem& item, int minutesBefore) {
|
||||
if (m_tray)
|
||||
{
|
||||
const QString body = QStringLiteral("「%1」将在 %2 分钟后开始(%3)。")
|
||||
.arg(item.task.title)
|
||||
.arg(minutesBefore)
|
||||
.arg(item.block.startAt.toString(QStringLiteral("HH:mm")));
|
||||
m_tray->showNotification(QStringLiteral("日程即将开始"), body, 6000, item.block.id);
|
||||
}
|
||||
});
|
||||
connect(&m_notificationService, &NotificationService::startReminderDue, this, [this](const ScheduleItem& item) {
|
||||
if (m_tray)
|
||||
{
|
||||
const QString body = QStringLiteral("「%1」现在开始(%2)。")
|
||||
.arg(item.task.title,
|
||||
DateTimeUtils::formatTimeRange(item.block.startAt, item.block.endAt));
|
||||
m_tray->showNotification(QStringLiteral("日程开始"), body, 6000, item.block.id);
|
||||
}
|
||||
});
|
||||
|
||||
connect(&m_themeManager, &ThemeManager::themeChanged, this, &CompactWindow::applyTheme);
|
||||
connect(&m_themeManager, &ThemeManager::preferenceChanged, this, [this](ThemeManager::Preference) {
|
||||
applyTheme(m_themeManager.tokens());
|
||||
@@ -377,6 +405,10 @@ void CompactWindow::openSettings()
|
||||
{
|
||||
connect(&dialog, &SettingsDialog::syncSettingsChanged, m_syncService, &SyncService::reloadConfig);
|
||||
}
|
||||
connect(&dialog, &SettingsDialog::reminderSettingsChanged, this, [this]() {
|
||||
m_notificationService.setLeadMinutes(m_settings.reminderLeadMinutes());
|
||||
m_notificationService.checkNow();
|
||||
});
|
||||
dialog.moveToCenter();
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
@@ -867,6 +867,10 @@ void MainWindow::openSettings()
|
||||
{
|
||||
connect(&dialog, &SettingsDialog::syncSettingsChanged, m_syncService, &SyncService::reloadConfig);
|
||||
}
|
||||
connect(&dialog, &SettingsDialog::reminderSettingsChanged, this, [this]() {
|
||||
m_notificationService.setLeadMinutes(m_settings.reminderLeadMinutes());
|
||||
m_notificationService.checkNow();
|
||||
});
|
||||
dialog.moveToCenter();
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ SettingsDialog::SettingsDialog(ThemeManager& themeManager, AppSettings& settings
|
||||
{
|
||||
setWindowTitle(QStringLiteral("设置"));
|
||||
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
||||
resize(560, 720);
|
||||
resize(560, 820);
|
||||
setMinimumWidth(520);
|
||||
|
||||
auto* root = new QVBoxLayout(this);
|
||||
@@ -155,6 +155,39 @@ SettingsDialog::SettingsDialog(ThemeManager& themeManager, AppSettings& settings
|
||||
keyNote->setWordWrap(true);
|
||||
root->addWidget(keyNote);
|
||||
|
||||
addDivider();
|
||||
addSectionTitle(QStringLiteral("日程提醒"));
|
||||
|
||||
auto* reminderDescription = new ElaText(
|
||||
QStringLiteral("日程开始时发送系统通知;可额外提前 N 分钟再提醒一次。"),
|
||||
11,
|
||||
this);
|
||||
reminderDescription->setTextStyle(ElaTextType::Caption);
|
||||
reminderDescription->setWordWrap(true);
|
||||
root->addWidget(reminderDescription);
|
||||
|
||||
auto* reminderRow = new QHBoxLayout();
|
||||
reminderRow->setSpacing(16);
|
||||
auto* reminderLabel = new ElaText(QStringLiteral("提前提醒"), 13, this);
|
||||
m_reminderLeadCombo = new ElaComboBox(this);
|
||||
const QList<int> leadValues = {0, 5, 10, 15, 30, 60};
|
||||
for (int minutes : leadValues)
|
||||
{
|
||||
m_reminderLeadCombo->addItem(minutes == 0 ? QStringLiteral("仅开始时")
|
||||
: QStringLiteral("提前 %1 分钟").arg(minutes));
|
||||
}
|
||||
int leadIndex = leadValues.indexOf(m_settings.reminderLeadMinutes());
|
||||
if (leadIndex < 0)
|
||||
{
|
||||
leadIndex = 2;
|
||||
}
|
||||
m_reminderLeadCombo->setCurrentIndex(leadIndex);
|
||||
m_reminderLeadCombo->setFixedSize(180, 32);
|
||||
reminderRow->addWidget(reminderLabel, 0, Qt::AlignVCenter);
|
||||
reminderRow->addWidget(m_reminderLeadCombo, 0, Qt::AlignVCenter);
|
||||
reminderRow->addStretch(1);
|
||||
root->addLayout(reminderRow);
|
||||
|
||||
addDivider();
|
||||
addSectionTitle(QStringLiteral("同步服务"));
|
||||
|
||||
@@ -238,6 +271,14 @@ SettingsDialog::SettingsDialog(ThemeManager& themeManager, AppSettings& settings
|
||||
connect(m_modelEdit, &ElaLineEdit::editingFinished, this, &SettingsDialog::saveAiConfig);
|
||||
connect(m_apiKeyEdit, &ElaLineEdit::editingFinished, this, &SettingsDialog::saveAiConfig);
|
||||
connect(m_keyVisibilityButton, &ElaToolButton::clicked, this, &SettingsDialog::toggleKeyVisibility);
|
||||
connect(m_reminderLeadCombo, &ElaComboBox::currentIndexChanged, this, [this](int index) {
|
||||
static const int values[] = {0, 5, 10, 15, 30, 60};
|
||||
if (index >= 0 && index < 6)
|
||||
{
|
||||
m_settings.setReminderLeadMinutes(values[index]);
|
||||
Q_EMIT reminderSettingsChanged();
|
||||
}
|
||||
});
|
||||
connect(m_syncUrlEdit, &ElaLineEdit::editingFinished, this, &SettingsDialog::saveSyncConfig);
|
||||
connect(m_syncEnabledSwitch, &ElaToggleSwitch::toggled, this, [this](bool) { saveSyncConfig(); });
|
||||
connect(doneButton, &ElaPushButton::clicked, this, [this]() {
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
signals:
|
||||
void micaChanged(bool enabled);
|
||||
void syncSettingsChanged();
|
||||
void reminderSettingsChanged();
|
||||
|
||||
private:
|
||||
void saveAiConfig();
|
||||
@@ -38,6 +39,7 @@ private:
|
||||
ElaLineEdit* m_modelEdit = nullptr;
|
||||
ElaLineEdit* m_apiKeyEdit = nullptr;
|
||||
ElaToolButton* m_keyVisibilityButton = nullptr;
|
||||
ElaComboBox* m_reminderLeadCombo = nullptr;
|
||||
ElaLineEdit* m_syncUrlEdit = nullptr;
|
||||
ElaToggleSwitch* m_syncEnabledSwitch = nullptr;
|
||||
};
|
||||
|
||||
@@ -195,6 +195,10 @@ void AppSettings::load()
|
||||
m_snapMinutes = normalizedSnap(intValue(ui, "snap_minutes", 15));
|
||||
m_trayHintShown = boolValue(ui, "tray_hint_shown", false);
|
||||
}
|
||||
if (const toml::table* reminders = subTable(root, "reminders"))
|
||||
{
|
||||
m_reminderLeadMinutes = qBound(0, intValue(reminders, "lead_minutes", 10), 24 * 60);
|
||||
}
|
||||
if (const toml::table* window = subTable(root, "window"))
|
||||
{
|
||||
m_compactGeometry = QByteArray::fromBase64(stringValue(window, "compact_geometry").toLatin1());
|
||||
@@ -288,6 +292,10 @@ void AppSettings::save()
|
||||
ui.insert("tray_hint_shown", m_trayHintShown);
|
||||
root.insert("ui", std::move(ui));
|
||||
|
||||
toml::table reminders;
|
||||
reminders.insert("lead_minutes", m_reminderLeadMinutes);
|
||||
root.insert("reminders", std::move(reminders));
|
||||
|
||||
toml::table window;
|
||||
window.insert("compact_geometry", m_compactGeometry.toBase64().toStdString());
|
||||
window.insert("schedule_geometry", m_scheduleGeometry.toBase64().toStdString());
|
||||
@@ -395,6 +403,17 @@ void AppSettings::setSnapMinutes(int minutes)
|
||||
save();
|
||||
}
|
||||
|
||||
int AppSettings::reminderLeadMinutes() const
|
||||
{
|
||||
return m_reminderLeadMinutes;
|
||||
}
|
||||
|
||||
void AppSettings::setReminderLeadMinutes(int minutes)
|
||||
{
|
||||
m_reminderLeadMinutes = qBound(0, minutes, 24 * 60);
|
||||
save();
|
||||
}
|
||||
|
||||
bool AppSettings::trayHintShown() const
|
||||
{
|
||||
return m_trayHintShown;
|
||||
|
||||
@@ -47,6 +47,9 @@ public:
|
||||
int snapMinutes() const;
|
||||
void setSnapMinutes(int minutes);
|
||||
|
||||
int reminderLeadMinutes() const;
|
||||
void setReminderLeadMinutes(int minutes);
|
||||
|
||||
bool trayHintShown() const;
|
||||
void setTrayHintShown(bool shown);
|
||||
|
||||
@@ -80,6 +83,7 @@ private:
|
||||
QString m_themePreference = QStringLiteral("system");
|
||||
bool m_micaEnabled = false;
|
||||
int m_snapMinutes = 15;
|
||||
int m_reminderLeadMinutes = 10;
|
||||
bool m_trayHintShown = false;
|
||||
QByteArray m_compactGeometry;
|
||||
QByteArray m_scheduleGeometry;
|
||||
|
||||
@@ -28,6 +28,7 @@ void TestConfig::defaultsAndRoundTrip()
|
||||
QCOMPARE(settings.themePreference(), QStringLiteral("system"));
|
||||
QCOMPARE(settings.micaEnabled(), false);
|
||||
QCOMPARE(settings.snapMinutes(), 15);
|
||||
QCOMPARE(settings.reminderLeadMinutes(), 10);
|
||||
QCOMPARE(settings.trayHintShown(), false);
|
||||
QCOMPARE(settings.aiConfig().baseUrl, QStringLiteral("https://api.openai.com/v1"));
|
||||
QCOMPARE(settings.aiConfig().model, QStringLiteral("gpt-4o-mini"));
|
||||
@@ -39,6 +40,7 @@ void TestConfig::defaultsAndRoundTrip()
|
||||
settings.setThemePreference(QStringLiteral("dark"));
|
||||
settings.setMicaEnabled(true);
|
||||
settings.setSnapMinutes(30);
|
||||
settings.setReminderLeadMinutes(30);
|
||||
settings.setTrayHintShown(true);
|
||||
settings.setCompactGeometry(QByteArray("compact-geometry"));
|
||||
settings.setScheduleGeometry(QByteArray("schedule-geometry"));
|
||||
@@ -63,6 +65,7 @@ void TestConfig::defaultsAndRoundTrip()
|
||||
QCOMPARE(reloaded.themePreference(), QStringLiteral("dark"));
|
||||
QCOMPARE(reloaded.micaEnabled(), true);
|
||||
QCOMPARE(reloaded.snapMinutes(), 30);
|
||||
QCOMPARE(reloaded.reminderLeadMinutes(), 30);
|
||||
QCOMPARE(reloaded.trayHintShown(), true);
|
||||
QCOMPARE(reloaded.compactGeometry(), QByteArray("compact-geometry"));
|
||||
QCOMPARE(reloaded.scheduleGeometry(), QByteArray("schedule-geometry"));
|
||||
|
||||
@@ -28,6 +28,7 @@ private slots:
|
||||
void energyProfileLearnsFromHistory();
|
||||
void searchFindsSchedules();
|
||||
void createsRecurringSchedules();
|
||||
void startAndLeadReminders();
|
||||
};
|
||||
|
||||
namespace
|
||||
@@ -439,5 +440,39 @@ void TestServices::createsRecurringSchedules()
|
||||
QVERIFY(!error.isEmpty());
|
||||
}
|
||||
|
||||
void TestServices::startAndLeadReminders()
|
||||
{
|
||||
Context context;
|
||||
QVERIFY(context.open());
|
||||
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
QString error;
|
||||
QVERIFY(context.service->createBlock(QStringLiteral("即将开始"),
|
||||
now.addSecs(5 * 60),
|
||||
now.addSecs(65 * 60),
|
||||
&error));
|
||||
QVERIFY(context.service->createBlock(QStringLiteral("已经开始"),
|
||||
now.addSecs(-5 * 60),
|
||||
now.addSecs(55 * 60),
|
||||
&error));
|
||||
|
||||
NotificationService notifications(*context.service);
|
||||
QSignalSpy leadSpy(¬ifications, &NotificationService::leadReminderDue);
|
||||
QSignalSpy startSpy(¬ifications, &NotificationService::startReminderDue);
|
||||
notifications.checkNow();
|
||||
QCOMPARE(leadSpy.count(), 1);
|
||||
QCOMPARE(startSpy.count(), 1);
|
||||
QCOMPARE(leadSpy.first().at(0).value<ScheduleItem>().task.title, QStringLiteral("即将开始"));
|
||||
QCOMPARE(leadSpy.first().at(1).toInt(), 10);
|
||||
QCOMPARE(startSpy.first().at(0).value<ScheduleItem>().task.title, QStringLiteral("已经开始"));
|
||||
|
||||
notifications.checkNow();
|
||||
QCOMPARE(leadSpy.count(), 1);
|
||||
QCOMPARE(startSpy.count(), 1);
|
||||
|
||||
notifications.setLeadMinutes(0);
|
||||
QCOMPARE(leadSpy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestServices)
|
||||
#include "test_services.moc"
|
||||
|
||||
Reference in New Issue
Block a user