diff --git a/README.md b/README.md index 9d016e7..4dac204 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 细粒度个人日程 + AI 自然语言排程 + 自部署多设备同步。 -当前进度:**阶段 0–4 + 搜索 / 重复日程 / Windows 安装包 / 界面动画 + Android 同步客户端 v1**。 +当前进度:**阶段 0–4 + 搜索 / 重复日程 / Windows 安装包 / 界面动画 + 桌面日程提醒 + Android 同步客户端 v1**。 本地模型 50 条指令回归已完成:完整 49/50(98%),失败项 #42 单独复测通过。 详细计划见 [`docs/PLAN.md`](docs/PLAN.md),验证记录见 [`docs/validation/`](docs/validation/)。 @@ -14,7 +14,7 @@ - **智能增强**:今日任务面板显示主动建议;日视图绘制幽灵时间;提供每日复盘对话框。 - **搜索与重复**:详细日程支持标题/说明搜索(`Ctrl+F`);新建日程可设置每天/每周/每月重复。 - **轻量动画**:窗口淡入、视图切换淡入、任务列表刷新与 Diff 卡片淡入。 -- **设置**:主题(跟随系统/浅色/深色)、ElaMica 云母效果、AI 接口地址/模型/API Key、同步服务地址/开关。 +- **设置**:主题(跟随系统/浅色/深色)、ElaMica 云母效果、AI 接口地址/模型/API Key、日程提前提醒分钟数、同步服务地址/开关。 > 云母效果使用 ElaWidgetTools 的 `ElaMica` 跨平台模拟背景(内置模糊基底图), > 在 Linux 下不是系统级窗口模糊;后续可在 Windows 上扩展系统 Mica。 @@ -67,6 +67,21 @@ - 重复规则元数据保存在本机 `recurrence` 表;具体时间块照常参与多设备同步。其他设备能看到所有已物化的日程。 - 编辑某个重复日程的标题会修改共享任务标题(影响该系列);删除单个块只删除该次。 +## 桌面日程提醒 + +桌面端现在提供三种系统通知: + +- **日程开始**:时间块到达开始时间时通知(App 需运行,轮询间隔 20 秒)。 +- **提前提醒**:在开始前 N 分钟再通知一次;N 可在设置中选择 0(仅开始时)、5、10、15、30、60 分钟。 +- **日程超时**:结束时间后仍未完成时通知(原有行为)。 + +通知后端: +- Linux 使用 `org.freedesktop.Notifications` DBus 原生通知,并在支持动作的桌面环境提供「打开日程」按钮。 +- Windows/macOS 使用 `QSystemTrayIcon` 的系统托盘通知。 +- 点击通知会打开详细日程并定位到对应时间块;Linux DBus 点击走 `ActionInvoked`,Windows/macOS 走 `messageClicked`。 + +限制:应用必须仍在运行(可最小化到托盘);没有开机自启;轮询不是精确闹钟;同一时间块提醒状态只保存在内存中,重启后可能再次提醒。 + ## 同步冲突行为 同步是后台无感进行的:不弹冲突对话框,失败自动重试,状态只显示在顶部标签。 @@ -280,6 +295,9 @@ temperature = 0.2 enabled = false server_url = "http://127.0.0.1:8787" token = "" + +[reminders] +lead_minutes = 10 ``` AI 接口地址、模型、API Key 与同步服务地址/开关可直接在设置对话框中修改。同步令牌由客户端在注册后自动写入,文件权限 0600。 diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7e0305e..4b66785 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -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() diff --git a/client/src/CMakeLists.txt b/client/src/CMakeLists.txt index 15f3a19..af22c23 100644 --- a/client/src/CMakeLists.txt +++ b/client/src/CMakeLists.txt @@ -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 diff --git a/client/src/main.cpp b/client/src/main.cpp index 70f87ab..c8b317e 100644 --- a/client/src/main.cpp +++ b/client/src/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); diff --git a/client/src/platform/SystemTray.cpp b/client/src/platform/SystemTray.cpp index 6af7c17..cccede1 100644 --- a/client/src/platform/SystemTray.cpp +++ b/client/src/platform/SystemTray.cpp @@ -3,12 +3,43 @@ #include #include +#ifdef Q_OS_LINUX +#include +#include +#include +#include +#include +#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 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; diff --git a/client/src/platform/SystemTray.h b/client/src/platform/SystemTray.h index 261870b..1ad883e 100644 --- a/client/src/platform/SystemTray.h +++ b/client/src/platform/SystemTray.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -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 m_dbusTargets; +#endif }; diff --git a/client/src/services/NotificationService.cpp b/client/src/services/NotificationService.cpp index 48b13ad..f725a5d 100644 --- a/client/src/services/NotificationService.cpp +++ b/client/src/services/NotificationService.cpp @@ -32,7 +32,8 @@ void NotificationService::stop() void NotificationService::checkNow() { - const QVector current = m_scheduleService.overdueItems(QDateTime::currentDateTime()); + const QDateTime now = QDateTime::currentDateTime(); + const QVector current = m_scheduleService.overdueItems(now); QSet currentIds; currentIds.reserve(current.size()); @@ -84,6 +85,55 @@ void NotificationService::checkNow() { Q_EMIT overdueListChanged(m_overdueItems); } + + const QVector 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 NotificationService::overdueItems() const diff --git a/client/src/services/NotificationService.h b/client/src/services/NotificationService.h index a75920d..222c308 100644 --- a/client/src/services/NotificationService.h +++ b/client/src/services/NotificationService.h @@ -26,13 +26,21 @@ public: void checkNow(); QVector 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& items); private: ScheduleService& m_scheduleService; QTimer m_timer; QSet m_notifiedIds; + QSet m_leadNotifiedKeys; + QSet m_startNotifiedKeys; QVector m_overdueItems; + int m_leadMinutes = 10; }; diff --git a/client/src/services/ScheduleService.cpp b/client/src/services/ScheduleService.cpp index fa78eb8..d6d61c7 100644 --- a/client/src/services/ScheduleService.cpp +++ b/client/src/services/ScheduleService.cpp @@ -1145,6 +1145,21 @@ bool ScheduleService::applyProposedCreates(const ProposedDiff& diff, return applyProposedDiff(diff, acceptedTempIds, error); } +std::optional 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 ScheduleService::itemsForDay(const QDate& date) const { auto items = m_store.blocksInRange(DateTimeUtils::localDayStartUtc(date), diff --git a/client/src/services/ScheduleService.h b/client/src/services/ScheduleService.h index bd56ad5..c3bf7c2 100644 --- a/client/src/services/ScheduleService.h +++ b/client/src/services/ScheduleService.h @@ -58,6 +58,7 @@ public: QString* error = nullptr); QVector itemsForDay(const QDate& date) const; + std::optional itemForBlock(const QString& blockId) const; // 返回 [from, to] 闭区间内的所有日程,按开始时间升序。 QVector itemsForRange(const QDate& from, const QDate& to) const; QVector overdueItems(const QDateTime& now = QDateTime::currentDateTime()) const; diff --git a/client/src/ui/CompactWindow.cpp b/client/src/ui/CompactWindow.cpp index 033933e..da48ddc 100644 --- a/client/src/ui/CompactWindow.cpp +++ b/client/src/ui/CompactWindow.cpp @@ -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(); } diff --git a/client/src/ui/MainWindow.cpp b/client/src/ui/MainWindow.cpp index e36738a..a7daa93 100644 --- a/client/src/ui/MainWindow.cpp +++ b/client/src/ui/MainWindow.cpp @@ -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(); } diff --git a/client/src/ui/dialogs/SettingsDialog.cpp b/client/src/ui/dialogs/SettingsDialog.cpp index f3be980..ae1f06f 100644 --- a/client/src/ui/dialogs/SettingsDialog.cpp +++ b/client/src/ui/dialogs/SettingsDialog.cpp @@ -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 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]() { diff --git a/client/src/ui/dialogs/SettingsDialog.h b/client/src/ui/dialogs/SettingsDialog.h index 12d7a71..e78a754 100644 --- a/client/src/ui/dialogs/SettingsDialog.h +++ b/client/src/ui/dialogs/SettingsDialog.h @@ -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; }; diff --git a/client/src/utils/AppSettings.cpp b/client/src/utils/AppSettings.cpp index 7e6ccd7..efd4032 100644 --- a/client/src/utils/AppSettings.cpp +++ b/client/src/utils/AppSettings.cpp @@ -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; diff --git a/client/src/utils/AppSettings.h b/client/src/utils/AppSettings.h index 01a07cc..182000a 100644 --- a/client/src/utils/AppSettings.h +++ b/client/src/utils/AppSettings.h @@ -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; diff --git a/client/tests/test_config.cpp b/client/tests/test_config.cpp index 05cb4b1..56ed1cc 100644 --- a/client/tests/test_config.cpp +++ b/client/tests/test_config.cpp @@ -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")); diff --git a/client/tests/test_services.cpp b/client/tests/test_services.cpp index 699af3f..2ca44db 100644 --- a/client/tests/test_services.cpp +++ b/client/tests/test_services.cpp @@ -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().task.title, QStringLiteral("即将开始")); + QCOMPARE(leadSpy.first().at(1).toInt(), 10); + QCOMPARE(startSpy.first().at(0).value().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" diff --git a/docs/PLAN.md b/docs/PLAN.md index 665a6ef..a5fe252 100644 --- a/docs/PLAN.md +++ b/docs/PLAN.md @@ -10,6 +10,7 @@ > 阶段 3(Go 同步服务端 / 多设备)已验证:[`validation/phase-3.md`](validation/phase-3.md)。 > 阶段 4(精力曲线 / 幽灵时间 / 每日复盘 / 主动建议)已验证:[`validation/phase-4.md`](validation/phase-4.md)。 > 阶段 4.1(搜索 / 重复日程 / Windows 安装包 / 动画)已验证:[`validation/phase-4-1.md`](validation/phase-4-1.md)。 +> 阶段 4.2(桌面开始提醒 / 原生通知 / 点击定位)已验证:[`validation/phase-4-2.md`](validation/phase-4-2.md)。 > 阶段 5.0(Android 同步客户端)已构建验证:[`validation/phase-5.md`](validation/phase-5.md)。 ## 0. 当前环境 @@ -144,6 +145,14 @@ Schedule/ - [x] 轻量动画:窗口/对话框淡入、视图切换淡入、任务列表与 Diff 卡片淡入 - 验收:`ctest --preset linux-gcc` 12/12;见 [`validation/phase-4-1.md`](validation/phase-4-1.md) +### 阶段 4.2:桌面日程提醒与原生通知(已完成) +- [x] 开始时提醒 + 提前 N 分钟提醒(0/5/10/15/30/60) +- [x] 保留结束未完成提醒 +- [x] Linux DBus 原生通知;Windows/macOS 系统托盘通知 +- [x] 通知点击打开详细日程并定位时间块 +- [x] 设置页提前提醒选项、TOML `[reminders] lead_minutes` +- 验收:`ctest --preset linux-gcc` 12/12;见 [`validation/phase-4-2.md`](validation/phase-4-2.md) + ### 阶段 5.0:Android 同步客户端(已完成 v1) - [x] 独立 Kotlin/Android 工程,不依赖 Qt - [x] SQLite task/timeblock/outbox/sync_state、LWW、删除墓碑 diff --git a/docs/validation/ctest-phase-4-2.txt b/docs/validation/ctest-phase-4-2.txt new file mode 100644 index 0000000..e758668 --- /dev/null +++ b/docs/validation/ctest-phase-4-2.txt @@ -0,0 +1,29 @@ +Test project /home/misaki/MisakiCodes/Schedule/build/linux-gcc + Start 1: go_server_tests + 1/12 Test #1: go_server_tests .................. Passed 0.09 sec + Start 2: storage + 2/12 Test #2: storage .......................... Passed 0.02 sec + Start 3: services + 3/12 Test #3: services ......................... Passed 0.05 sec + Start 4: grid + 4/12 Test #4: grid ............................. Passed 0.38 sec + Start 5: mainwindow + 5/12 Test #5: mainwindow ....................... Passed 1.25 sec + Start 6: compactwindow + 6/12 Test #6: compactwindow .................... Passed 4.31 sec + Start 7: config + 7/12 Test #7: config ........................... Passed 0.01 sec + Start 8: scheduler + 8/12 Test #8: scheduler ........................ Passed 0.01 sec + Start 9: energy + 9/12 Test #9: energy ........................... Passed 0.01 sec + Start 10: ai +10/12 Test #10: ai ............................... Passed 0.11 sec + Start 11: openai_provider +11/12 Test #11: openai_provider .................. Passed 0.21 sec + Start 12: sync_integration +12/12 Test #12: sync_integration ................. Passed 7.71 sec + +100% tests passed, 0 tests failed out of 12 + +Total Test time (real) = 14.17 sec diff --git a/docs/validation/phase-4-2.md b/docs/validation/phase-4-2.md new file mode 100644 index 0000000..c03ecc1 --- /dev/null +++ b/docs/validation/phase-4-2.md @@ -0,0 +1,69 @@ +# 阶段 4.2 验证报告:桌面开始提醒 / 原生通知 / 点击定位 + +> 日期:2026-10-26 +> 环境:Ubuntu 24.04 / GCC 13.3 / Qt 6.6.3(Linux DBus 通知) + +## 1. 本次交付 + +1. **开始时间提醒**:时间块到达开始时间后发送系统通知;20 秒轮询,最多有 20 秒延迟。为避免启动时补发过多历史提醒,开始提醒只覆盖开始后 10 分钟内。 +2. **提前 N 分钟提醒**:设置页可选择 0(仅开始时)、5、10、15、30、60 分钟;提前量保存在 TOML `[reminders] lead_minutes`。 +3. **保留超时提醒**:结束时间后仍未完成的日程继续通知,并支持点击定位。 +4. **原生通知**: + - Linux:`org.freedesktop.Notifications` DBus `Notify`,支持 `ActionInvoked`「打开日程」动作。 + - Windows/macOS:`QSystemTrayIcon` 系统托盘通知,使用 `messageClicked` 处理点击。 +5. **点击定位**:通知携带 block id;点击后打开详细日程并按日期定位到对应时间块。Linux DBus 使用通知 id → block id 映射;Windows/macOS 使用待处理 block id。 +6. **设置同步**:设置对话框修改提前分钟后立即更新 NotificationService,并重新检查当前提醒。 + +## 2. 构建与自动化测试 + +```bash +cmake --preset linux-gcc +cmake --build --preset linux-gcc --clean-first -j$(nproc) +ctest --preset linux-gcc +``` + +| 项目 | 结果 | +|---|---| +| 客户端全量构建 | 成功,0 警告(`-Werror`) | +| `ctest --preset linux-gcc` | **12/12 通过** | +| 新增提醒测试 | `NotificationService` 提前/开始提醒各一次,重复检查不重复通知 | +| 配置测试 | `[reminders] lead_minutes` 默认值/写入/重载 | + +完整输出见 [`ctest-phase-4-2.txt`](ctest-phase-4-2.txt)。 + +## 3. 界面截图 + +| 截图 | 说明 | +|---|---| +| [`settings-dark.png`](settings-dark.png) | 设置 · 日程提前提醒(深色) | +| [`settings-light.png`](settings-light.png) | 设置 · 日程提前提醒(浅色) | + +系统通知截图未保存:当前验证环境没有可交互的桌面通知中心;通知发送路径通过代码审查和 Linux DBus 编译验证。 + +## 4. 行为说明 + +- 应用必须运行(窗口可最小化到托盘)。完全退出后不会提醒。 +- 开始提醒:`now >= start` 且 `now < end` 且开始时间不超过 10 分钟前;只提醒一次。 +- 提前提醒:`start - N <= now < start`;只提醒一次。 +- 超时提醒:`now >= end` 且状态仍为 scheduled/in_progress;沿用原有逻辑。 +- 提前量为 0 时不发提前提醒,仅开始时提醒。 +- 通知点击:Linux DBus 点击「打开日程」;Windows/macOS 点击托盘通知。 +- 通知状态只保存在内存,重启应用后可能再次提醒。 +- 没有桌面开机自启(按要求未添加)。 + +## 5. 已知限制 + +1. 20 秒轮询不是精确闹钟;系统休眠或应用被挂起时可能延迟。 +2. 应用必须运行;退出进程后无法提醒。 +3. Linux 通知动作取决于桌面通知服务是否支持 actions;不支持时仍会显示通知,但点击可能只聚焦应用。 +4. Windows/macOS 使用 Qt 托盘通知,具体视觉样式由系统决定;不是自绘窗口。 +5. 通知去重仅在内存;重启后同一开始/提前提醒可能再次出现。 +6. 没有开机自启(用户明确不要求)。 + +## 6. 人工验收建议 + +1. 设置提前提醒为 5 分钟,创建一条 6 分钟后开始的日程;等待/触发检查,确认收到系统通知。 +2. 到开始时间再次收到「日程开始」通知;点击通知,确认打开详细日程并定位。 +3. 把提前提醒改为「仅开始时」,确认不再出现提前通知。 +4. 创建一条已结束但未完成的日程,确认原有超时通知仍工作且点击定位。 +5. 最小化到托盘/隐藏主窗口,确认通知仍出现;退出应用后确认不再提醒。 diff --git a/docs/validation/settings-dark.png b/docs/validation/settings-dark.png index 1e12032..69fa2f5 100644 Binary files a/docs/validation/settings-dark.png and b/docs/validation/settings-dark.png differ diff --git a/docs/validation/settings-light.png b/docs/validation/settings-light.png index 4bedecb..2639471 100644 Binary files a/docs/validation/settings-light.png and b/docs/validation/settings-light.png differ