mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 06:24:39 +00:00
SystemState reads the generation before the appearance
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+5
-1
@@ -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::<Source>::run(ctx, |source| SystemState { appearance: source.0.read().into(), generation: source.0.generation() })
|
||||
Service::<Source>::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) {
|
||||
|
||||
Reference in New Issue
Block a user