Public Access
Fix Toast timing and alert once per shown Toast
- ToastQueue compared times unsigned: a Toast stamped a few ms after the main loop read the clock looked expired, so Toasts were skipped or shown late and bursts chained wrongly - Notifier now beeps and flashes when each Toast appears instead of when the Notification arrives, so a burst alerts once per Toast Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -9,7 +9,7 @@ void ToastQueue::push(const std::string& text, NotificationLevel level, uint32_t
|
||||
queue_.erase(queue_.begin() + (showing_ && queue_.size() > 1 ? 1 : 0));
|
||||
if (!showing_) changed_ = true;
|
||||
}
|
||||
queue_.push_back({text, level});
|
||||
queue_.push_back({text, level, nextId_++});
|
||||
if (!showing_) {
|
||||
showing_ = true;
|
||||
shownAtMs_ = nowMs;
|
||||
@@ -19,7 +19,9 @@ void ToastQueue::push(const std::string& text, NotificationLevel level, uint32_t
|
||||
|
||||
const Toast* ToastQueue::current(uint32_t nowMs) {
|
||||
if (!showing_) return nullptr;
|
||||
if (nowMs - shownAtMs_ >= durationMs_) dismiss(shownAtMs_ + durationMs_);
|
||||
// Signed: a caller's clock reading may be a few ms older than the Toast's stamp.
|
||||
int32_t elapsed = static_cast<int32_t>(nowMs - shownAtMs_);
|
||||
if (elapsed >= static_cast<int32_t>(durationMs_)) dismiss(shownAtMs_ + durationMs_);
|
||||
return showing_ ? &queue_.front() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace roro {
|
||||
struct Toast {
|
||||
std::string text;
|
||||
NotificationLevel level;
|
||||
uint32_t id; // unique per push, to tell two identical Toasts apart
|
||||
};
|
||||
|
||||
// Notifications waiting to be shown as Toasts, one at a time, each for the same duration.
|
||||
@@ -34,6 +35,7 @@ class ToastQueue {
|
||||
bool showing_ = false;
|
||||
uint32_t shownAtMs_ = 0;
|
||||
bool changed_ = false;
|
||||
uint32_t nextId_ = 1;
|
||||
};
|
||||
|
||||
} // namespace roro
|
||||
|
||||
Reference in New Issue
Block a user