fix: sync completion across clients and restore Windows build

- Guard SystemTray DBus members correctly for MinGW builds\n- Let remote done override local scheduled/in-progress despite clock skew\n- Add Android start/lead reminders and lead-minute setting\n- Use expedited WorkManager for local Android changes\n- Add desktop/Android completion and reminder validation
This commit is contained in:
Misaki
2026-10-26 21:30:58 +08:00
parent 795f9730f8
commit f68b4f7c6f
22 changed files with 468 additions and 15 deletions
+1 -1
View File
@@ -52,8 +52,8 @@ private:
QAction* m_statusAction = nullptr;
int m_overdueCount = 0;
QString m_pendingBlockId;
QHash<uint, QString> m_dbusTargets;
#ifdef Q_OS_LINUX
class QDBusInterface* m_notifications = nullptr;
QHash<uint, QString> m_dbusTargets;
#endif
};
+20 -1
View File
@@ -967,7 +967,26 @@ bool SqliteStore::applyRemoteChange(const RemoteChange& change, QString* error)
{
return setError(QStringLiteral("查询远程 upsert 目标失败: %1").arg(current.lastError().text()));
}
if (current.next() && !remoteWins(current.value(0).toString(), remoteTime, false))
bool hasLocal = current.next();
const QString localUpdated = hasLocal ? current.value(0).toString() : QString();
bool forceCompletion = false;
if (change.entityType == QStringLiteral("timeblock"))
{
const QString remoteStatus = jsonString(change.payload, "status").toString();
if (remoteStatus == QStringLiteral("done"))
{
QSqlQuery statusQuery(m_database);
statusQuery.prepare(QStringLiteral("SELECT status FROM timeblock WHERE id = :id"));
statusQuery.bindValue(QStringLiteral(":id"), change.entityId);
if (statusQuery.exec() && statusQuery.next())
{
const QString localStatus = statusQuery.value(0).toString();
forceCompletion = localStatus == QStringLiteral("scheduled") ||
localStatus == QStringLiteral("in_progress");
}
}
}
if (hasLocal && !forceCompletion && !remoteWins(localUpdated, remoteTime, false))
{
return true;
}
+63
View File
@@ -17,6 +17,7 @@ private slots:
void proposedDiffRoundTrip();
void outboxCapturesLocalChanges();
void remoteApplySuppressesOutboxAndUsesLww();
void remoteCompletionWinsOverOlderTimestamp();
};
void TestStorage::migrationCreatesSchema()
@@ -260,5 +261,67 @@ void TestStorage::remoteApplySuppressesOutboxAndUsesLww()
QCOMPARE(store.outboxCount(), 0);
}
void TestStorage::remoteCompletionWinsOverOlderTimestamp()
{
QTemporaryDir dir;
QVERIFY(dir.isValid());
SqliteStore store(dir.filePath(QStringLiteral("schedule.db")));
QString error;
QVERIFY2(store.open(&error), qPrintable(error));
const QDateTime now = QDateTime::currentDateTime();
Task task;
task.id = QStringLiteral("completion-task");
task.title = QStringLiteral("完成同步");
task.createdAt = now;
task.updatedAt = now;
task.deviceId = QStringLiteral("device-a");
QVERIFY(store.insertTask(task));
TimeBlock block;
block.id = QStringLiteral("completion-block");
block.taskId = task.id;
block.startAt = now.addSecs(3600);
block.endAt = now.addSecs(7200);
block.createdAt = now;
block.updatedAt = now;
block.deviceId = QStringLiteral("device-a");
QVERIFY(store.insertTimeBlock(block));
RemoteChange change;
change.seq = 2;
change.deviceId = QStringLiteral("device-b");
change.entityType = QStringLiteral("timeblock");
change.entityId = block.id;
change.op = QStringLiteral("upsert");
change.version = 1;
change.updatedAt = DateTimeUtils::toDb(now.addSecs(-60));
change.payload = QJsonObject{
{QStringLiteral("id"), block.id},
{QStringLiteral("task_id"), task.id},
{QStringLiteral("start_at"), DateTimeUtils::toDb(block.startAt)},
{QStringLiteral("end_at"), DateTimeUtils::toDb(block.endAt)},
{QStringLiteral("granularity"), 15},
{QStringLiteral("splittable"), 1},
{QStringLiteral("breakable"), 1},
{QStringLiteral("status"), QStringLiteral("done")},
{QStringLiteral("done_at"), DateTimeUtils::toDb(now.addSecs(-60))},
{QStringLiteral("created_at"), DateTimeUtils::toDb(block.createdAt)},
{QStringLiteral("updated_at"), DateTimeUtils::toDb(now.addSecs(-60))},
{QStringLiteral("version"), 1},
{QStringLiteral("device_id"), QStringLiteral("device-b")},
};
QVERIFY(store.beginTransaction());
QVERIFY(store.setRemoteApplySuppressed(true));
QVERIFY(store.applyRemoteChange(change));
QVERIFY(store.setRemoteApplySuppressed(false));
QVERIFY(store.commit());
const auto updated = store.timeBlockById(block.id);
QVERIFY(updated.has_value());
QCOMPARE(updated->status, QStringLiteral("done"));
QVERIFY(updated->doneAt.has_value());
}
QTEST_GUILESS_MAIN(TestStorage)
#include "test_storage.moc"
+13
View File
@@ -115,6 +115,19 @@ void TestSyncIntegration::twoClientsConverge()
QTRY_VERIFY_WITH_TIMEOUT(serviceB.itemsForDay(tomorrow).size() == 1, 20000);
QCOMPARE(serviceB.itemsForDay(tomorrow).first().task.title, QStringLiteral("跨设备任务"));
const QString sharedBlockId = serviceA.itemsForDay(tomorrow).first().block.id;
QVERIFY2(serviceA.setBlockStatus(sharedBlockId, QStringLiteral("done"), &error), qPrintable(error));
QTRY_VERIFY_WITH_TIMEOUT(!serviceB.itemsForDay(tomorrow).isEmpty() &&
serviceB.itemsForDay(tomorrow).first().block.status ==
QStringLiteral("done"),
20000);
QVERIFY2(serviceB.setBlockStatus(sharedBlockId, QStringLiteral("scheduled"), &error),
qPrintable(error));
QTRY_VERIFY_WITH_TIMEOUT(!serviceA.itemsForDay(tomorrow).isEmpty() &&
serviceA.itemsForDay(tomorrow).first().block.status ==
QStringLiteral("scheduled"),
20000);
QVERIFY2(serviceA.updateBlock(serviceA.itemsForDay(tomorrow).first().block.id,
QStringLiteral("跨设备任务 v2"),
start.addSecs(3600),