Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

The window no longer waits for Windows to look up the time zone (#536) (#551)

Ahmed Nefzaoui0aa8bd67d4ce
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca698138..692cb4bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
- The browser's **video button** over a hover-to-play preview (YouTube's thumbnails) no longer vanishes as the pointer goes to it: it stays where it was while the pointer is on it, a click downloads that video, and it fades once the pointer leaves ([#503](https://github.com/anefzaoui/misterdownloadmanager/issues/503)).
- **Enter new address to download**: an address with a login in **Options → Sites Logins** shows that login under **Use authorization** (ticked, the user name and the password), the one the download uses; it was used but the box stayed empty. A login typed there still goes first ([#511](https://github.com/anefzaoui/misterdownloadmanager/issues/511)).
- The window no longer waits for the disk to write MDM's log or to save the RSS feeds: while Windows held every write on the disk to make a snapshot of it (a restore point or a backup), the window could stop answering until the writes were let go. Both are now written beside the window, as the download list already was (part of [#513](https://github.com/anefzaoui/misterdownloadmanager/issues/513)).
+- The window no longer waits for Windows to look up the time zone: the queues' schedules asked for it at every moment, and once Windows took more than 8 seconds to answer, the window stopped answering meanwhile. The time zone is now looked up beside the window, again each minute, so a change of summer time still shows within a minute ([#536](https://github.com/anefzaoui/misterdownloadmanager/issues/536)).
- Windows: video and gallery look-ups no longer fail with "[WinError 448] The path cannot be traversed because it contains an untrusted mount point" when a folder on PATH goes through a junction Windows won't let yt-dlp cross (one an app installed for itself, Codex's for example): yt-dlp, gallery-dl and the ffmpeg they start get that folder's real place instead, and no folder that can't be opened ([#508](https://github.com/anefzaoui/misterdownloadmanager/issues/508)).
- **Download video** from Dailymotion's player embedded in another site: the look-up no longer sends that site as the Referer, which Dailymotion refused with 403, so its formats are found as with the video's own address ([#359](https://github.com/anefzaoui/misterdownloadmanager/issues/359)).
- The video button fades again after a click on the player, in fullscreen too, and stays while you use the keyboard ([#480](https://github.com/anefzaoui/misterdownloadmanager/issues/480)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 8cabb368..eb0b8a76 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -542,6 +542,9 @@ These ship in a later version, when they're ready.
(a restore point or a backup) ([#513](https://github.com/anefzaoui/misterdownloadmanager/issues/513)):
the log and the RSS feeds are now written beside the window, as the list already was; fix in
review, to confirm on the reporter's computer
+- 🔄 The window not answering while Windows took seconds to look up the time zone for the
+ queues' schedules ([#536](https://github.com/anefzaoui/misterdownloadmanager/issues/536)):
+ looked up beside the window now; fix in review
- 🔄 Video look-ups failing with "WinError 448 ... untrusted mount point" when a folder on PATH
goes through a junction Windows won't let yt-dlp cross
([#508](https://github.com/anefzaoui/misterdownloadmanager/issues/508)): fix in review
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index ab1f6913..4f815999 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -672,8 +672,9 @@ pub struct App {
/// Stopped by hand while they could have run: a running queue leaves them alone until
/// they are started again or the queue is started anew (#341).
stopped_by_hand: std::collections::HashSet<u64>,
- /// Seconds since local midnight at the last scheduler tick.
- clock: u32,
+ /// Seconds since local midnight at the last scheduler tick (`None` until the clock's first
+ /// answer, #536).
+ clock: Option<u32>,
/// Scheduler → "Wake the computer to run this queue": the wake set with the system (#142).
wake: crate::wake::Waker,
/// Commands from ipc.rs (command line, second launch, browser).
@@ -821,12 +822,6 @@ pub fn auth_headers(login: Option<&(String, String)>) -> HeaderMap {
h
}
-/// Seconds since local midnight (for queue schedules).
-fn seconds_now() -> u32 {
- use chrono::Timelike;
- chrono::Local::now().num_seconds_from_midnight()
-}
-
/// A read of the clipboard on a thread of its own, its answer taken when it has come (#418).
struct ClipRead(std::sync::Arc<std::sync::Mutex<Option<Option<String>>>>);
@@ -1219,7 +1214,7 @@ impl App {
queues,
failures: HashMap::new(),
stopped_by_hand: Default::default(),
- clock: seconds_now(),
+ clock: None,
wake: Default::default(),
commands,
}
@@ -4894,24 +4889,29 @@ impl App {
/// Scheduler times, then start what running queues allow (notes/ENGINE.md §5).
fn tick_queues(&mut self) {
- use chrono::Datelike;
- let now_s = seconds_now();
- let prev = std::mem::replace(&mut self.clock, now_s);
- let today = chrono::Local::now().date_naive();
- let weekday = today.weekday().num_days_from_sunday() as usize;
- let date = (today.year(), today.month(), today.day());
- for q in 0..self.queues.len() {
- let sch = self.queues[q].schedule.clone();
- if let Some(t) = sch.start_at
- && sch.starts_on(date, weekday)
- && queue::crossed(t, prev, now_s)
- {
- self.queues[q].running = true;
- }
- if let Some(t) = sch.stop_at
- && queue::crossed(t, prev, now_s)
- {
- self.stop_queue(q);
+ use chrono::{Datelike, Timelike};
+ // The local time with the offset the clock's thread keeps: asking Windows here held the
+ // window for 8 s (#536). Until its first answer, schedules wait.
+ let local = crate::clock::now_known();
+ let now_s = local.map(|t| t.num_seconds_from_midnight());
+ let prev = std::mem::replace(&mut self.clock, now_s).or(now_s);
+ if let (Some(local), Some(now_s), Some(prev)) = (local, now_s, prev) {
+ let today = local.date_naive();
+ let weekday = today.weekday().num_days_from_sunday() as usize;
+ let date = (today.year(), today.month(), today.day());
+ for q in 0..self.queues.len() {
+ let sch = self.queues[q].schedule.clone();
+ if let Some(t) = sch.start_at
+ && sch.starts_on(date, weekday)
+ && queue::crossed(t, prev, now_s)
+ {
+ self.queues[q].running = true;
+ }
+ if let Some(t) = sch.stop_at
+ && queue::crossed(t, prev, now_s)
+ {
+ self.stop_queue(q);
+ }
}
}
let now = Instant::now();
diff --git a/crates/app/src/clock.rs b/crates/app/src/clock.rs
new file mode 100644
index 00000000..288357f1
--- /dev/null
+++ b/crates/app/src/clock.rs
@@ -0,0 +1,286 @@
+//! Local time for the window thread (#536).
+//!
+//! On Windows, chrono asks the system for the time zone's rules at every local time it works
+//! out (`GetTimeZoneInformationForYear`, with no cache), and the system once took more than 8 s
+//! to answer: a frozen window. Here the offset is asked on a thread of its own and kept: the
+//! window reads it without ever waiting, and the thread asks again at each new minute (and when
+//! a reader finds it a minute old, after the computer slept), so a change of summer time or of
+//! the time zone shows within a minute.
+//!
+//! - [`now`]: the local time now, with the offset kept.
+//! - [`local`]: a UTC time (a stored one, for display) with the offset of *now*. A time on the
+//! other side of a summer time change shows an hour off (a log line from before the change),
+//! as a clock read now would show it; nothing that is worked out depends on it.
+//! - [`exact_utc`]: a local time (the Scheduler's start) as UTC by the zone's own rules for that
+//! date, worked out on the clock's thread and kept: `None` until it has been worked out.
+
+use std::collections::HashMap;
+use std::sync::atomic::{AtomicBool, AtomicI32, AtomicI64, Ordering};
+use std::sync::{Arc, Mutex, OnceLock, mpsc};
+use std::time::Duration;
+
+use chrono::{DateTime, FixedOffset, NaiveDateTime, TimeZone, Utc};
+
+/// No answer yet (the minute of the last answer otherwise).
+const NONE: i64 = i64::MIN;
+/// The exact conversions kept at most (a few queues' next starts).
+const KEPT: usize = 256;
+
+type OffsetAt = Box<dyn Fn(DateTime<Utc>) -> FixedOffset + Send>;
+type ToUtc = Box<dyn Fn(NaiveDateTime) -> Option<DateTime<Utc>> + Send>;
+
+enum Ask {
+ /// The offset is a minute old.
+ Offset,
+ /// A local time as UTC.
+ Exact(NaiveDateTime),
+}
+
+#[derive(Default)]
+struct Kept {
+ /// Seconds east of UTC.
+ offset: AtomicI32,
+ /// The UTC minute the offset was asked at, `NONE` before the first answer.
+ minute: AtomicI64,
+ /// A new offset has been asked and not answered yet.
+ asking: AtomicBool,
+ /// Local times as UTC; `None` while being worked out.
+ exact: Mutex<HashMap<NaiveDateTime, Option<Option<DateTime<Utc>>>>>,
+}
+
+pub struct Clock {
+ kept: Arc<Kept>,
+ ask: mpsc::Sender<Ask>,
+}
+
+impl Clock {
+ /// A clock whose thread asks `offset_at` and `to_utc` (the system's, or a test's).
+ fn spawn(offset_at: OffsetAt, to_utc: ToUtc) -> Clock {
+ let kept = Arc::new(Kept {
+ minute: AtomicI64::new(NONE),
+ asking: AtomicBool::new(true),
+ ..Kept::default()
+ });
+ let (ask, asked) = mpsc::channel();
+ let k = kept.clone();
+ let spawned = std::thread::Builder::new()
+ .name("mdm-clock".into())
+ .spawn(move || run(&k, &asked, &offset_at, &to_utc));
+ if let Err(e) = spawned {
+ tracing::warn!("clock: no thread for the local time ({e}); UTC shown");
+ }
+ Clock { kept, ask }
+ }
+
+ /// Whether the offset has been answered (UTC is shown until then).
+ pub fn known(&self) -> bool {
+ self.kept.minute.load(Ordering::Acquire) != NONE
+ }
+
+ /// The offset kept, asked again when it is a minute old. Never waits.
+ pub fn offset(&self) -> FixedOffset {
+ let minute = minute_of(Utc::now());
+ if self.kept.minute.load(Ordering::Acquire) < minute
+ && !self.kept.asking.swap(true, Ordering::AcqRel)
+ {
+ let _ = self.ask.send(Ask::Offset);
+ }
+ FixedOffset::east_opt(self.kept.offset.load(Ordering::Acquire))
+ .unwrap_or_else(|| FixedOffset::east_opt(0).expect("UTC"))
+ }
+
+ pub fn now(&self) -> DateTime<FixedOffset> {
+ self.local(Utc::now())
+ }
+
+ pub fn local(&self, utc: DateTime<Utc>) -> DateTime<FixedOffset> {
+ utc.with_timezone(&self.offset())
+ }
+
+ /// `local` as UTC by the zone's rules for its date; `None` while the clock's thread works it
+ /// out (asked here), `Some(None)` for a time that can't be had.
+ pub fn exact_utc(&self, local: NaiveDateTime) -> Option<Option<DateTime<Utc>>> {
+ let mut exact = self.kept.exact.lock().unwrap_or_else(|e| e.into_inner());
+ if let Some(known) = exact.get(&local) {
+ return *known;
+ }
+ if exact.len() >= KEPT {
+ exact.clear();
+ }
+ exact.insert(local, None);
+ let _ = self.ask.send(Ask::Exact(local));
+ None
+ }
+}
+
+fn minute_of(t: DateTime<Utc>) -> i64 {
+ t.timestamp().div_euclid(60)
+}
+
+/// How long the clock's thread waits before asking again: until just after the next minute.
+fn wait_from(now: DateTime<Utc>) -> Duration {
+ let into =
+ now.timestamp().rem_euclid(60) as u64 * 1000 + u64::from(now.timestamp_subsec_millis());
+ Duration::from_millis(60_000 - into.min(60_000) + 20)
+}
+
+/// The clock's thread: the offset at each new minute, and the conversions asked.
+fn run(kept: &Kept, asked: &mpsc::Receiver<Ask>, offset_at: &OffsetAt, to_utc: &ToUtc) {
+ let mut minute = NONE;
+ loop {
+ let now = Utc::now();
+ if minute_of(now) != minute {
+ let offset = offset_at(now).local_minus_utc();
+ let before = kept.offset.swap(offset, Ordering::AcqRel);
+ minute = minute_of(now);
+ // Another offset: the zone's rules may be others too (the time zone changed).
+ if before != offset || minute.rem_euclid(60) == 0 {
+ kept.exact.lock().unwrap_or_else(|e| e.into_inner()).clear();
+ }
+ kept.minute.store(minute, Ordering::Release);
+ kept.asking.store(false, Ordering::Release);
+ }
+ match asked.recv_timeout(wait_from(Utc::now())) {
+ Ok(Ask::Exact(local)) => {
+ let utc = to_utc(local);
+ kept.exact
+ .lock()
+ .unwrap_or_else(|e| e.into_inner())
+ .insert(local, Some(utc));
+ }
+ Ok(Ask::Offset) | Err(mpsc::RecvTimeoutError::Timeout) => {}
+ Err(mpsc::RecvTimeoutError::Disconnected) => return,
+ }
+ }
+}
+
+/// The system's offset at `utc` (asks the system: the clock's thread only).
+fn system_offset(utc: DateTime<Utc>) -> FixedOffset {
+ chrono::Local.offset_from_utc_datetime(&utc.naive_utc())
+}
+
+fn clock() -> &'static Clock {
+ static CLOCK: OnceLock<Clock> = OnceLock::new();
+ CLOCK.get_or_init(|| Clock::spawn(Box::new(system_offset), Box::new(crate::wake::to_utc)))
+}
+
+/// Starts the clock's thread, so its first answer is there by the first frame.
+pub fn start() {
+ clock();
+}
+
+/// The local time now (UTC until the clock's first answer, a moment after the start).
+pub fn now() -> DateTime<FixedOffset> {
+ clock().now()
+}
+
+/// The local time now, once the clock has answered (what the Scheduler's starts go by).
+pub fn now_known() -> Option<DateTime<FixedOffset>> {
+ let c = clock();
+ let now = c.now();
+ c.known().then_some(now)
+}
+
+/// A UTC time with the offset of now (for display; see the module's notes).
+pub fn local(utc: DateTime<Utc>) -> DateTime<FixedOffset> {
+ clock().local(utc)
+}
+
+/// Seconds since 1970 as a local time with the offset of now (for display).
+pub fn local_at(secs: i64) -> Option<DateTime<FixedOffset>> {
+ DateTime::from_timestamp(secs, 0).map(local)
+}
+
+/// A local time as UTC by the zone's rules for its date (see [`Clock::exact_utc`]).
+pub fn exact_utc(local: NaiveDateTime) -> Option<Option<DateTime<Utc>>> {
+ clock().exact_utc(local)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::time::Instant;
+
+ fn until<T>(limit: Duration, mut f: impl FnMut() -> Option<T>) -> Option<T> {
+ let t = Instant::now();
+ while t.elapsed() < limit {
+ if let Some(v) = f() {
+ return Some(v);
+ }
+ std::thread::sleep(Duration::from_millis(5));
+ }
+ None
+ }
+
+ #[test]
+ fn a_held_lookup_never_holds_the_caller() {
+ // The system holds the answer until the test lets it go.
+ let hold = Arc::new(Mutex::new(()));
+ let held = hold.lock().unwrap();
+ let (h1, h2) = (hold.clone(), hold.clone());
+ let two_hours = FixedOffset::east_opt(7200).unwrap();
+ let c = Clock::spawn(
+ Box::new(move |_| {
+ let _wait = h1.lock().unwrap();
+ two_hours
+ }),
+ Box::new(move |l| {
+ let _wait = h2.lock().unwrap();
+ Some(DateTime::from_naive_utc_and_offset(l, Utc))
+ }),
+ );
+ let local = DateTime::from_timestamp(1_800_000_000, 0)
+ .unwrap()
+ .naive_utc();
+ let t = Instant::now();
+ for _ in 0..100 {
+ let _ = c.now();
+ assert_eq!(c.exact_utc(local), None);
+ }
+ let took = t.elapsed();
+ assert!(took < Duration::from_millis(500), "{took:?}");
+ assert!(!c.known());
+ assert_eq!(c.now().offset().local_minus_utc(), 0);
+ // Let go: the answers come.
+ drop(held);
+ assert!(until(Duration::from_secs(5), || c.known().then_some(())).is_some());
+ assert_eq!(c.now().offset(), &two_hours);
+ let utc = until(Duration::from_secs(5), || c.exact_utc(local));
+ assert_eq!(
+ utc,
+ Some(Some(DateTime::from_naive_utc_and_offset(local, Utc)))
+ );
+ }
+
+ #[test]
+ fn its_time_is_chronos() {
+ let c = Clock::spawn(Box::new(system_offset), Box::new(crate::wake::to_utc));
+ assert!(until(Duration::from_secs(10), || c.known().then_some(())).is_some());
+ let (ours, theirs) = (c.now(), chrono::Local::now());
+ assert_eq!(ours.offset(), theirs.offset());
+ let apart = (ours.naive_local() - theirs.naive_local())
+ .num_milliseconds()
+ .abs();
+ assert!(apart < 2000, "{apart} ms apart");
+ // Exact conversions, in winter and in summer (the rules for that date, not now's).
+ let year = theirs.naive_local().date().format("%Y").to_string();
+ let year: i32 = year.parse().unwrap();
+ for month in [1, 7] {
+ let local = chrono::NaiveDate::from_ymd_opt(year + 1, month, 15)
+ .unwrap()
+ .and_hms_opt(23, 0, 0)
+ .unwrap();
+ let utc = until(Duration::from_secs(10), || c.exact_utc(local));
+ assert_eq!(utc, Some(crate::wake::to_utc(local)), "{local}");
+ }
+ }
+
+ #[test]
+ fn it_asks_again_at_the_next_minute() {
+ // 1_800_000_000 is a whole minute (30_000_000 × 60).
+ for (secs, millis, want) in [(0, 0, 60_020), (59, 990, 30), (30, 500, 29_520)] {
+ let t = DateTime::from_timestamp(1_800_000_000 + secs, millis * 1_000_000).unwrap();
+ assert_eq!(wait_from(t), Duration::from_millis(want), "{t}");
+ }
+ }
+}
diff --git a/crates/app/src/dialogs.rs b/crates/app/src/dialogs.rs
index 9dac1337..a8839ff0 100644
--- a/crates/app/src/dialogs.rs
+++ b/crates/app/src/dialogs.rs
@@ -2018,7 +2018,7 @@ pub struct LimitNotice {
impl LimitNotice {
pub fn new(mb: u32, hours: u32, wait: std::time::Duration) -> Self {
- let at = chrono::Local::now()
+ let at = crate::clock::now()
+ chrono::Duration::from_std(wait).unwrap_or_else(|_| chrono::Duration::zero());
LimitNotice {
lines: [
diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs
index 5ce76e04..ab4468d8 100644
--- a/crates/app/src/main.rs
+++ b/crates/app/src/main.rs
@@ -5,6 +5,7 @@ mod batch;
mod categories;
mod checksum;
mod chrome;
+mod clock;
mod countries;
mod crash;
mod crashui;
@@ -223,6 +224,8 @@ fn main() -> std::process::ExitCode {
if std::env::args().nth(1).as_deref() == Some("--forget-sign-ins") {
return secrets::forget_all();
}
+ // The local time's offset, asked on a thread of its own from now on (#536).
+ clock::start();
// A server (#157): the app without a window.
let all: Vec<String> = std::env::args().skip(1).collect();
let code = if headless::asked(&all) {
diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs
index 69cbcd46..bb93118a 100644
--- a/crates/app/src/model.rs
+++ b/crates/app/src/model.rs
@@ -651,7 +651,6 @@ impl Item {
/// The last `n` log entries as tooltip lines ("14:02:11 Connected to …").
pub fn log_lines(&self, n: usize) -> String {
- use chrono::TimeZone;
self.log
.iter()
.rev()
@@ -659,9 +658,8 @@ impl Item {
.rev()
.map(|(at, text)| {
// In the interface's way (English month names in every language before).
- let t = chrono::Local
- .timestamp_opt(*at, 0)
- .single()
+ // With the offset of now (crate::clock, #536).
+ let t = crate::clock::local_at(*at)
.map(|t| when_text(t.naive_local()))
.unwrap_or_default();
format!("{t} {text}")
@@ -970,7 +968,7 @@ impl Item {
/// The "Last Try Date" and "Added" columns as stored, e.g. `Oct 28 21:44:12 2026` (the list's
/// format; read back by `stamp_time`).
pub fn now_stamp() -> String {
- chrono::Local::now().format(STAMP).to_string()
+ crate::clock::now().format(STAMP).to_string()
}
const STAMP: &str = "%b %d %H:%M:%S %Y";
diff --git a/crates/app/src/options.rs b/crates/app/src/options.rs
index 552978ae..7800fb0b 100644
--- a/crates/app/src/options.rs
+++ b/crates/app/src/options.rs
@@ -2324,7 +2324,7 @@ impl OptionsDialog {
reg.week_start = [0, 1, 6][i];
}
// What it looks like, now.
- let now = chrono::Local::now().naive_local();
+ let now = crate::clock::now().naive_local();
let sample = crate::regional::format_with(crate::regional::effective(reg), now);
// i18n: label before an example date and time written the chosen way
let label = crate::i18n::t("Example:");
@@ -2748,10 +2748,8 @@ impl OptionsDialog {
.map(|r| r.devices())
.unwrap_or_default();
let when = |secs: i64| {
- chrono::DateTime::from_timestamp(secs, 0)
- .map(|t| {
- crate::regional::short_date_time(t.with_timezone(&chrono::Local).naive_local())
- })
+ crate::clock::local_at(secs)
+ .map(|t| crate::regional::short_date_time(t.naive_local()))
.unwrap_or_default()
};
let rows: Vec<Vec<String>> = devices
diff --git a/crates/app/src/rssdlg.rs b/crates/app/src/rssdlg.rs
index 1fd8d917..96354378 100644
--- a/crates/app/src/rssdlg.rs
+++ b/crates/app/src/rssdlg.rs
@@ -771,8 +771,8 @@ impl RssWindow {
);
// What the rules did last, at the bottom.
if let Some((t, what)) = store.log.last() {
- let at = chrono::DateTime::from_timestamp(*t, 0)
- .map(|d| d.with_timezone(&chrono::Local).format("%H:%M").to_string())
+ let at = crate::clock::local_at(*t)
+ .map(|d| d.format("%H:%M").to_string())
.unwrap_or_default();
winui::fit(
ui,
diff --git a/crates/app/src/scheduler.rs b/crates/app/src/scheduler.rs
index 7cdf77c4..6f216a2f 100644
--- a/crates/app/src/scheduler.rs
+++ b/crates/app/src/scheduler.rs
@@ -2,7 +2,7 @@
//! modes, as IDM's. Queues on the left; on the right the selected queue's Schedule and Files in
//! the queue, or the Download limits page. Edits stay in a draft until Apply, Start now or Close.
-use chrono::{Datelike, Duration as Days, Local, NaiveDate};
+use chrono::{Datelike, Duration as Days, NaiveDate};
use egui::{Color32, Pos2, Rect, Sense, Ui, pos2, vec2};
use crate::chrome::{IconKey, ShellIcons};
@@ -85,7 +85,7 @@ struct Form {
impl Form {
fn of(q: &Queue) -> Self {
let s = &q.schedule;
- let today = Local::now().date_naive();
+ let today = crate::clock::now().date_naive();
Form {
start_on_startup: s.start_on_startup,
start_at_on: s.start_at.is_some(),
@@ -707,7 +707,7 @@ impl Scheduler {
}
// A start that can never come says so where it is set (the queue just never ran).
if f.start_at_on {
- let today = Local::now().date_naive();
+ let today = crate::clock::now().date_naive();
let (bad, rc, why) = if f.once {
(
f.date < today,
@@ -908,7 +908,7 @@ impl Scheduler {
Some(e) => (e.to_owned(), None, true),
None => {
f.apply_to(&mut q);
- let now = Local::now().naive_local();
+ let now = crate::clock::now().naive_local();
match crate::wake::next_start(&q.schedule, now) {
Some(start) => (wake_note(crate::wake::wake_for(start, now)), None, false),
None => (String::new(), None, false),
@@ -1958,7 +1958,7 @@ fn calendar(ui: &mut Ui, key: egui::Id, under: Rect, date: NaiveDate) -> (Option
let (cw, ch) = (28.0, 19.0);
let size = vec2(cw * 7.0 + 12.0, 26.0 + 18.0 + ch * 6.0 + 8.0 + 18.0);
let mut picked = None;
- let today = Local::now().date_naive();
+ let today = crate::clock::now().date_naive();
// The keys (the week runs from the right in RTL: Left and Right swap there).
let back = if winui::rtl() { 1 } else { -1 };
let moves = [
diff --git a/crates/app/src/wake.rs b/crates/app/src/wake.rs
index eccfb561..c418422a 100644
--- a/crates/app/src/wake.rs
+++ b/crates/app/src/wake.rs
@@ -101,7 +101,8 @@ pub fn next_wake(queues: &[Queue], now: NaiveDateTime) -> Option<Wake> {
.min_by_key(|w| w.at)
}
-/// A local time as UTC. A time the clocks skip (summer time) is taken an hour later, as the
+/// A local time as UTC (asks the system: the clock's thread uses it, `crate::clock::exact_utc`
+/// for the window). A time the clocks skip (summer time) is taken an hour later, as the
/// clock reads then; a time they pass twice, the first time.
pub fn to_utc(local: NaiveDateTime) -> Option<DateTime<Utc>> {
Local
@@ -194,8 +195,18 @@ impl Waker {
/// Set, move or cancel the system's wake for `queues` (called with the Scheduler's clock;
/// it asks the system only when the wake changes, and once a minute).
pub fn sync(&mut self, queues: &[Queue]) {
- let now = Local::now().naive_local();
- let mut want = next_wake(queues, now).and_then(|w| Some((to_utc(w.at)?, w.queue, w.start)));
+ // The local time and the start's UTC time from the clock's thread: asking the system here
+ // could hold the window (#536). Until they have come, the wake stays as it is.
+ let Some(now) = crate::clock::now_known() else {
+ return;
+ };
+ let mut want = match next_wake(queues, now.naive_local()) {
+ None => None,
+ Some(w) => match crate::clock::exact_utc(w.at) {
+ None => return,
+ Some(at) => at.map(|at| (at, w.queue, w.start)),
+ },
+ };
// A start keeps the wake set for it: in the minute before the start, the wake worked out
// now would be the start itself, moving a timer that is just going off.
if let (Some(w), Some(set)) = (&mut want, &self.wanted)