diff --git a/crates/platform/src/appearance.rs b/crates/platform/src/appearance.rs index c143ac8e2..d92ac9db8 100644 --- a/crates/platform/src/appearance.rs +++ b/crates/platform/src/appearance.rs @@ -171,7 +171,8 @@ impl Watcher { self.shared.get() } /// Rises each time the theme, [`Watcher::contrast`] or [`Watcher::reduced_motion`] changes, before the wake - /// callback runs; a layout or icon theme change leaves it. Read the preferences again when it moved. + /// callback runs; a layout or icon theme change leaves it. Read the preferences again when it moved, + /// after reading this: a value is stored before the generation rises. pub fn generation(&self) -> u64 { self.shared.generation.load(Ordering::Acquire) } diff --git a/crates/platform/src/appearance/reader.rs b/crates/platform/src/appearance/reader.rs index a3556c8fc..e55455567 100644 --- a/crates/platform/src/appearance/reader.rs +++ b/crates/platform/src/appearance/reader.rs @@ -100,7 +100,8 @@ impl SystemReader { /// Rises each time a preference [`SystemReader::read`] answers from changes, as its source /// reports it: the watcher's theme, contrast or reduced motion, or a reported value. Read - /// again when it moved. On the web the browser's queries raise it in no case. + /// again when it moved. On the web the browser's queries raise it in no case. Read it before + /// [`SystemReader::read`]: the watcher stores a value before it raises the generation. pub fn generation(&self) -> u64 { self.watcher.as_ref().map_or(0, Watcher::generation) + self.reported.generation.load(Ordering::Acquire) } diff --git a/crates/ui-contract/src/runtime/env/system.rs b/crates/ui-contract/src/runtime/env/system.rs index 811f8dbe7..36a2cdb69 100644 --- a/crates/ui-contract/src/runtime/env/system.rs +++ b/crates/ui-contract/src/runtime/env/system.rs @@ -29,7 +29,11 @@ pub struct SystemState { /// What the OS reports on `ctx` now: the host's reader (`InstallSpec::system`), with the colour scheme egui's /// integration reports (`Event::SystemTheme`) where the reader's own watcher has none. pub fn system_appearance(ctx: &Context) -> SystemState { - Service::::run(ctx, |source| SystemState { appearance: source.0.read().into(), generation: source.0.generation() }) + Service::::run(ctx, |source| { + // Generation first: a change landing between the two reads then shows again at the next read. + let generation = source.0.generation(); + SystemState { appearance: source.0.read().into(), generation } + }) } pub(crate) fn install(ctx: &Context, reader: SystemReader) {