mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
Merge remote-tracking branch 'origin/next' into sync/delta11
This commit is contained in:
Generated
+1
@@ -6026,6 +6026,7 @@ dependencies = [
|
||||
"craft-timeline",
|
||||
"craft-ui-gallery",
|
||||
"craft-update",
|
||||
"epaint_default_fonts",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -371,3 +371,60 @@ fn a_repeated_auth_is_answered_already_authenticated_without_dispatching() {
|
||||
assert_eq!(after["result"], "still serving");
|
||||
handler.join().expect("handler ran");
|
||||
}
|
||||
|
||||
/// Ported from WordCraft (#7317). A request that is complete JSON but ends at EOF with no newline (the client wrote it
|
||||
/// and shut its end down) still reaches the app and is answered: a client cannot know it was dropped.
|
||||
#[trial]
|
||||
fn a_complete_json_request_at_eof_can_reach_the_app() {
|
||||
let (rx, server) = server::listen(0, TOKEN.into(), host()).expect("started");
|
||||
let handler = std::thread::spawn(move || {
|
||||
let req = rx.recv_timeout(Duration::from_secs(5)).expect("the request reached the app");
|
||||
assert_eq!(req.method, "test.once");
|
||||
req.reply.send(json!({"ok": true, "result": "once"})).expect("replied");
|
||||
assert!(rx.recv_timeout(Duration::from_millis(300)).is_err(), "it ran exactly once");
|
||||
});
|
||||
let (mut stream, mut reader) = authenticated(server.addr);
|
||||
stream.write_all(json!({"id": 3, "method": "test.once"}).to_string().as_bytes()).expect("written");
|
||||
stream.shutdown(std::net::Shutdown::Write).expect("shut down");
|
||||
let reply = read_json(&mut reader).expect("a reply");
|
||||
assert_eq!((&reply["id"], &reply["result"]), (&json!(3), &json!("once")));
|
||||
let mut rest = String::new();
|
||||
assert_eq!(reader.read_line(&mut rest).expect("closed, not timed out"), 0, "closed after the last request: {rest:?}");
|
||||
handler.join().expect("handler ran");
|
||||
}
|
||||
|
||||
/// Ported from WordCraft (#7317). Connections that never authenticate cannot fill the server: past the limit a new
|
||||
/// one is refused, and a slot freed by a closed connection is admitted again.
|
||||
#[trial]
|
||||
fn idle_unauthenticated_connections_are_limited() {
|
||||
use craft_automation::security::MAX_CONNECTIONS;
|
||||
// Far longer than the trial, so only the limit refuses.
|
||||
let (rx, server) = server::serve_with_deadline(TcpListener::bind("127.0.0.1:0").expect("bound"), TOKEN.into(), host(), Duration::from_secs(60))
|
||||
.expect("started");
|
||||
let idle: Vec<TcpStream> = (0..MAX_CONNECTIONS).map(|_| TcpStream::connect(server.addr).expect("connected")).collect();
|
||||
// Admission is counted by the accept thread: it is done once the next connection is answered.
|
||||
let refused = |addr| {
|
||||
let stream = TcpStream::connect(addr).expect("connected");
|
||||
stream.set_read_timeout(Some(Duration::from_secs(5))).expect("timeout");
|
||||
read_json(&mut BufReader::new(stream))
|
||||
};
|
||||
let reply = refused(server.addr).expect("a refusal");
|
||||
assert_eq!(reply["ok"], false);
|
||||
assert!(reply["error"].as_str().is_some_and(|e| e.contains("limit")), "{reply}");
|
||||
drop(idle);
|
||||
// The freed slots go back as the closed connections are noticed.
|
||||
let started = motion::now();
|
||||
loop {
|
||||
let mut stream = TcpStream::connect(server.addr).expect("connected");
|
||||
stream.set_read_timeout(Some(Duration::from_secs(5))).expect("timeout");
|
||||
let mut reader = BufReader::new(stream.try_clone().expect("cloned"));
|
||||
// A refused connection may already be closed when the request is written (Windows resets it).
|
||||
let auth = json!({"id": "auth", "method": "auth", "params": {"token": TOKEN}});
|
||||
if writeln!(stream, "{auth}").is_ok() && read_json(&mut reader).is_some_and(|r| r["ok"] == true) {
|
||||
break;
|
||||
}
|
||||
assert!(started.elapsed() < Duration::from_secs(10), "no slot came back");
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
assert!(rx.try_recv().is_err());
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ craft-text = { workspace = true, features = ["suite", "find"] }
|
||||
craft-theme-store = { workspace = true, features = ["suite"] }
|
||||
craft-timeline = { workspace = true, features = ["suite", "xml", "otio"] }
|
||||
|
||||
# craft-ui-contract's tests ask for the bundled monochrome emoji faces (their font oracle); asked here, every build has
|
||||
# them, so those tests share egui and the framework with the rest. The feature only adds two byte constants, which
|
||||
# nothing else reads; egui's emoji fallback is epaint's own feature of the same name, not this one.
|
||||
epaint_default_fonts = { version = "0.37", features = ["monochrome_emoji_fonts"] }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
craft-dialogs = { workspace = true, features = ["suite"] }
|
||||
craft-font-manager = { workspace = true, features = ["suite"] }
|
||||
|
||||
@@ -26,3 +26,15 @@ fn cf_html_offsets_delimit_the_fragment_bytes() {
|
||||
assert_eq!(&data[end_html..], b"\0", "EndHTML excludes the trailing NUL");
|
||||
assert_eq!(end_html, data.len() - 1);
|
||||
}
|
||||
|
||||
/// Ported from WordCraft (#7317). An X11 property read is taken only when it came whole and within the cap: over the
|
||||
/// cap, or with bytes still left to read, it is refused rather than pasted truncated.
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
#[test]
|
||||
fn property_reads_must_be_whole_and_capped() {
|
||||
use super::unix::complete;
|
||||
assert!(complete(10, 0, 10));
|
||||
assert!(!complete(11, 0, 10), "over the cap");
|
||||
assert!(!complete(8, 4, 10), "more left to read");
|
||||
assert!(complete(0, 0, 0));
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ font-manager = ["craft-ui-gallery/font-manager"]
|
||||
update = ["craft-ui-gallery/update"]
|
||||
|
||||
[dependencies]
|
||||
# The same framework features as the gallery (the runtime's `testing` includes the snapshot renderer), so the
|
||||
# framework builds once for the gallery, the tests and this bin.
|
||||
# The same framework features as the gallery (the gallery's `suite` brings the snapshot renderer), so the framework
|
||||
# builds once for the gallery, the tests and this bin.
|
||||
craft-behavior = { workspace = true }
|
||||
craft-ui = { workspace = true, features = ["app", "testing"] }
|
||||
craft-ui-gallery = { path = "../ui-gallery", default-features = false }
|
||||
|
||||
+14
-10
@@ -201,8 +201,8 @@ fn derived_values(unpinned: &ColorTokens, before_pass: &ColorTokens, pinned: &BT
|
||||
}
|
||||
Source::Same(other) | Source::SolidFrom(other) => unpinned.get(other),
|
||||
Source::Faded(other, a) => unpinned.get(other).with_alpha(a),
|
||||
Source::ShiftedFrom { base, from, to, away_from } => {
|
||||
shifted(unpinned.get(base), unpinned.get(from), unpinned.get(to), unpinned.get(away_from))
|
||||
Source::ShiftedFrom { base, from, to, away_from, min } => {
|
||||
shifted(unpinned.get(base), unpinned.get(from), unpinned.get(to), unpinned.get(away_from), min)
|
||||
}
|
||||
// Lit like the anchored greys: from the panel's own value, pinned or not.
|
||||
Source::Lighting(amount) => lighting(before_pass.surface.panel, amount),
|
||||
@@ -411,8 +411,8 @@ fn follow(c: &mut ColorTokens, ramp: &ColorTokens, pinned: &BTreeSet<ColorToken>
|
||||
Source::Faded(other, a) => c.set(t, c.get(other).with_alpha(a)),
|
||||
Source::Lighting(amount) => c.set(t, lighting(c.surface.panel, amount)),
|
||||
Source::SolidFrom(other) if on_solid => c.set(t, c.get(other)),
|
||||
Source::ShiftedFrom { base, from, to, away_from } if on_solid => {
|
||||
c.set(t, shifted(c.get(base), ramp.get(from), ramp.get(to), c.get(away_from)))
|
||||
Source::ShiftedFrom { base, from, to, away_from, min } if on_solid => {
|
||||
c.set(t, shifted(c.get(base), ramp.get(from), ramp.get(to), c.get(away_from), min))
|
||||
}
|
||||
Source::OnSolid(solids) if on_solid => c.set(t, best_extreme(c, solids)),
|
||||
_ => {}
|
||||
@@ -435,11 +435,15 @@ fn lighting(panel: Rgba, amount: f64) -> Rgba {
|
||||
}
|
||||
|
||||
/// `base` with its OKLCH lightness moved by the distance between `from` and `to`, away from
|
||||
/// `text`: darker under lighter text, lighter under darker. Clamped to 0..=1, hue and chroma kept.
|
||||
fn shifted(base: Rgba, from: Rgba, to: Rgba, text: Rgba) -> Rgba {
|
||||
/// `text`: darker under lighter text, lighter under darker, by at least `min`. Toward `text` instead when there is no room. Clamped to 0..=1, hue and chroma kept.
|
||||
fn shifted(base: Rgba, from: Rgba, to: Rgba, text: Rgba, min: f64) -> Rgba {
|
||||
let o = base.to_oklch();
|
||||
let step = (to.to_oklch().l - from.to_oklch().l).abs();
|
||||
let sign = if relative_luminance(text) >= relative_luminance(base) { -1.0 } else { 1.0 };
|
||||
let step = (to.to_oklch().l - from.to_oklch().l).abs().max(min);
|
||||
let mut sign = if relative_luminance(text) >= relative_luminance(base) { -1.0 } else { 1.0 };
|
||||
// A base too close to white or black to move that far away from the text moves toward it.
|
||||
if !(0.0..=1.0).contains(&(o.l + sign * step)) {
|
||||
sign = -sign;
|
||||
}
|
||||
Oklch { l: (o.l + sign * step).clamp(0.0, 1.0), ..o }.to_rgba().with_alpha(base.a())
|
||||
}
|
||||
|
||||
@@ -512,8 +516,8 @@ fn fix_rule(c: &mut ColorTokens, pass: &Pass, rule: &PairRule, done: &[PairRule]
|
||||
{
|
||||
match values::source(t, pass.mode) {
|
||||
Source::SolidFrom(other) => c.set(t, c.get(other)),
|
||||
Source::ShiftedFrom { base, from, to, away_from } => {
|
||||
c.set(t, shifted(c.get(base), pass.ramp.get(from), pass.ramp.get(to), c.get(away_from)));
|
||||
Source::ShiftedFrom { base, from, to, away_from, min } => {
|
||||
c.set(t, shifted(c.get(base), pass.ramp.get(from), pass.ramp.get(to), c.get(away_from), min));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -126,9 +126,13 @@ fn source_words(source: ColorSource, anchored_on: Option<ColorToken>) -> String
|
||||
ColorSource::Fixed(c) => format!("fixed {}", c.to_hex()),
|
||||
ColorSource::Oklch(l, c, h) => format!("oklch {l} {c} {h}"),
|
||||
ColorSource::Same(t) | ColorSource::SolidFrom(t) => format!("= {}", t.path()),
|
||||
ColorSource::ShiftedFrom { base, from, to, away_from } => {
|
||||
format!("= {} moved away from {} as far as {} lies from {}", base.path(), away_from.path(), to.path(), from.path())
|
||||
}
|
||||
ColorSource::ShiftedFrom { base, from, to, away_from, min } => format!(
|
||||
"= {} moved away from {} as far as {} lies from {}, at least {min} lightness (toward it when there is no room)",
|
||||
base.path(),
|
||||
away_from.path(),
|
||||
to.path(),
|
||||
from.path()
|
||||
),
|
||||
ColorSource::OnSolid([only]) => format!("white or black on {}", only.path()),
|
||||
ColorSource::OnSolid(solids) => match solids.first() {
|
||||
Some(first) => format!("white or black on {} and {} more solids", first.path(), solids.len() - 1),
|
||||
|
||||
@@ -98,6 +98,9 @@ pub enum ColorSource {
|
||||
to: ColorToken,
|
||||
/// The text the fill moves away from.
|
||||
away_from: ColorToken,
|
||||
/// The least OKLCH lightness distance from `base`, so a variant under a seed whose ramp
|
||||
/// steps lie close together (a light dark-mode accent) still shows.
|
||||
min: f64,
|
||||
},
|
||||
/// White or black, whichever has the higher lowest contrast on all of these tokens.
|
||||
OnSolid(&'static [ColorToken]),
|
||||
@@ -137,6 +140,11 @@ const SOLID_HOVER: usize = 10;
|
||||
/// `status.<s>.solid_pressed`).
|
||||
const SOLID_PRESSED: (usize, usize, f64) = (10, 11, 0.5);
|
||||
|
||||
/// The least OKLCH lightness a hovered `accent.strong` moves from rest, and a pressed one. The
|
||||
/// dark ramp's steps 9 and 10 lie 0.01 apart for a light seed, which hides the hover.
|
||||
const STRONG_HOVER_MIN: f64 = 0.06;
|
||||
const STRONG_PRESSED_MIN: f64 = 0.10;
|
||||
|
||||
/// How far a bevel's lit edge (`edge.light`) lies above `surface.panel` in OKLCH lightness, in
|
||||
/// either mode. Windows 2000's #d4d0c8 face (L 0.86) has a white lit edge.
|
||||
pub const BEVEL_LIT: f64 = 0.15;
|
||||
@@ -238,8 +246,12 @@ pub(super) fn source(token: ColorToken, mode: Mode) -> ColorSource {
|
||||
T::AccentHover => Accent(SOLID_HOVER),
|
||||
T::AccentPressed => AccentMix { from: pressed_from, to: pressed_to, t: pressed_t },
|
||||
T::AccentStrong => SolidFrom(T::AccentSolid),
|
||||
T::AccentStrongHover => ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentHover, away_from: T::TextOnStrong },
|
||||
T::AccentStrongPressed => ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentPressed, away_from: T::TextOnStrong },
|
||||
T::AccentStrongHover => {
|
||||
ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentHover, away_from: T::TextOnStrong, min: STRONG_HOVER_MIN }
|
||||
}
|
||||
T::AccentStrongPressed => {
|
||||
ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentPressed, away_from: T::TextOnStrong, min: STRONG_PRESSED_MIN }
|
||||
}
|
||||
T::AccentSoft => Accent(pick(4, 3)),
|
||||
T::AccentBorder => Same(T::AccentSolid),
|
||||
T::AccentText => Accent(11),
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #0058adff
|
||||
accent.hover = #0058adff
|
||||
accent.pressed = #0958abff
|
||||
accent.strong = #0058adff
|
||||
accent.strong_hover = #004c98ff
|
||||
accent.strong_pressed = #004182ff
|
||||
accent.strong_hover = #00488fff
|
||||
accent.strong_pressed = #003d7cff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #486c99ff
|
||||
accent.text = #034d98ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #0058adff
|
||||
accent.hover = #0058adff
|
||||
accent.pressed = #0958abff
|
||||
accent.strong = #0058adff
|
||||
accent.strong_hover = #004c98ff
|
||||
accent.strong_pressed = #004182ff
|
||||
accent.strong_hover = #00488fff
|
||||
accent.strong_pressed = #003d7cff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #486c99ff
|
||||
accent.text = #034d98ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3584e4ff
|
||||
accent.hover = #2977d3ff
|
||||
accent.pressed = #226abeff
|
||||
accent.strong = #2676d5ff
|
||||
accent.strong_hover = #1569c7ff
|
||||
accent.strong_pressed = #005bb6ff
|
||||
accent.strong_hover = #0b63c1ff
|
||||
accent.strong_pressed = #0058b0ff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #3584e482
|
||||
accent.text = #1b5daaff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3584e4ff
|
||||
accent.hover = #2977d3ff
|
||||
accent.pressed = #226abeff
|
||||
accent.strong = #2676d5ff
|
||||
accent.strong_hover = #1569c7ff
|
||||
accent.strong_pressed = #005bb6ff
|
||||
accent.strong_hover = #0b63c1ff
|
||||
accent.strong_pressed = #0058b0ff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #3584e482
|
||||
accent.text = #1b5daaff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #bbdaffff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #405b7aff
|
||||
accent.strong_hover = #3d5877ff
|
||||
accent.strong_pressed = #375170ff
|
||||
accent.strong_hover = #304a68ff
|
||||
accent.strong_pressed = #26405dff
|
||||
accent.soft = #595959ff
|
||||
accent.border = #bbdaffff
|
||||
accent.text = #ffffffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #bbdaffff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #405b7aff
|
||||
accent.strong_hover = #3d5877ff
|
||||
accent.strong_pressed = #375170ff
|
||||
accent.strong_hover = #304a68ff
|
||||
accent.strong_pressed = #26405dff
|
||||
accent.soft = #595959ff
|
||||
accent.border = #bbdaffff
|
||||
accent.text = #ffffffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #1674d4ff
|
||||
accent.strong_pressed = #066ccbff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #6e6e6eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #bad6ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #1674d4ff
|
||||
accent.strong_pressed = #066ccbff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #6e6e6eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #bad6ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #005d92ff
|
||||
accent.strong_hover = #005a8eff
|
||||
accent.strong_pressed = #004e7cff
|
||||
accent.strong_hover = #004c78ff
|
||||
accent.strong_pressed = #004168ff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #5199c2ff
|
||||
accent.text = #59c1f7ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #005d92ff
|
||||
accent.strong_hover = #005a8eff
|
||||
accent.strong_pressed = #004e7cff
|
||||
accent.strong_hover = #004c78ff
|
||||
accent.strong_pressed = #004168ff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #5199c2ff
|
||||
accent.text = #59c1f7ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #1e76b0ff
|
||||
accent.strong_hover = #1a73adff
|
||||
accent.strong_pressed = #00669fff
|
||||
accent.strong_hover = #00649cff
|
||||
accent.strong_pressed = #00588aff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #3aace8a0
|
||||
accent.text = #50b8eeff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #1e76b0ff
|
||||
accent.strong_hover = #1a73adff
|
||||
accent.strong_pressed = #00669fff
|
||||
accent.strong_hover = #00649cff
|
||||
accent.strong_pressed = #00588aff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #3aace8a0
|
||||
accent.text = #50b8eeff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #5394feff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #1354b9ff
|
||||
accent.strong_hover = #054aaeff
|
||||
accent.strong_pressed = #003a90ff
|
||||
accent.strong_hover = #0042a2ff
|
||||
accent.strong_pressed = #00398dff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #5394feff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #5394feff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #1354b9ff
|
||||
accent.strong_hover = #054aaeff
|
||||
accent.strong_pressed = #003a90ff
|
||||
accent.strong_hover = #0042a2ff
|
||||
accent.strong_pressed = #00398dff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #5394feff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #4b8bf5ff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #3573dbff
|
||||
accent.strong_hover = #2b69d0ff
|
||||
accent.strong_pressed = #1856bbff
|
||||
accent.strong_hover = #2360c7ff
|
||||
accent.strong_pressed = #1554b9ff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #4b8bf5ff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #4b8bf5ff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #3573dbff
|
||||
accent.strong_hover = #2b69d0ff
|
||||
accent.strong_pressed = #1856bbff
|
||||
accent.strong_hover = #2360c7ff
|
||||
accent.strong_pressed = #1554b9ff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #4b8bf5ff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #60a9ffff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #0359a8ff
|
||||
accent.strong_hover = #004f97ff
|
||||
accent.strong_pressed = #003f7bff
|
||||
accent.strong_hover = #00498cff
|
||||
accent.strong_pressed = #003e79ff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #60a9ffff
|
||||
accent.text = #add1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #60a9ffff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #0359a8ff
|
||||
accent.strong_hover = #004f97ff
|
||||
accent.strong_pressed = #003f7bff
|
||||
accent.strong_hover = #00498cff
|
||||
accent.strong_pressed = #003e79ff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #60a9ffff
|
||||
accent.text = #add1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #056bcaff
|
||||
accent.strong_pressed = #005baeff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #8fc1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #056bcaff
|
||||
accent.strong_pressed = #005baeff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #8fc1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #056bcaff
|
||||
accent.strong_pressed = #005baeff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #8fc1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #97a8f7ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #4251abff
|
||||
accent.strong_hover = #404ea8ff
|
||||
accent.strong_pressed = #35429aff
|
||||
accent.strong_hover = #333f98ff
|
||||
accent.strong_pressed = #2a338bff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #9eaadfff
|
||||
accent.text = #cbd4ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #97a8f7ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #4251abff
|
||||
accent.strong_hover = #404ea8ff
|
||||
accent.strong_pressed = #35429aff
|
||||
accent.strong_hover = #333f98ff
|
||||
accent.strong_pressed = #2a338bff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #9eaadfff
|
||||
accent.text = #cbd4ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8a9ae8ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #5668c4ff
|
||||
accent.strong_hover = #5465c1ff
|
||||
accent.strong_pressed = #4859b3ff
|
||||
accent.strong_hover = #4656b0ff
|
||||
accent.strong_pressed = #3c4aa3ff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #8a9ae896
|
||||
accent.text = #bec8fcff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8a9ae8ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #5668c4ff
|
||||
accent.strong_hover = #5465c1ff
|
||||
accent.strong_pressed = #4859b3ff
|
||||
accent.strong_hover = #4656b0ff
|
||||
accent.strong_pressed = #3c4aa3ff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #8a9ae896
|
||||
accent.text = #bec8fcff
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #4551a5ff
|
||||
accent.hover = #4552a4ff
|
||||
accent.pressed = #46539fff
|
||||
accent.strong = #4151acff
|
||||
accent.strong_hover = #33409aff
|
||||
accent.strong_hover = #323f99ff
|
||||
accent.strong_pressed = #29338bff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6069a1ff
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #4551a5ff
|
||||
accent.hover = #4552a4ff
|
||||
accent.pressed = #46539fff
|
||||
accent.strong = #4151acff
|
||||
accent.strong_hover = #33409aff
|
||||
accent.strong_hover = #323f99ff
|
||||
accent.strong_pressed = #29338bff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6069a1ff
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #6e80d8ff
|
||||
accent.hover = #5f6fc4ff
|
||||
accent.pressed = #5463b0ff
|
||||
accent.strong = #5062beff
|
||||
accent.strong_hover = #4151abff
|
||||
accent.strong_hover = #4050aaff
|
||||
accent.strong_pressed = #36449dff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6e80d8aa
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #6e80d8ff
|
||||
accent.hover = #5f6fc4ff
|
||||
accent.pressed = #5463b0ff
|
||||
accent.strong = #5062beff
|
||||
accent.strong_hover = #4151abff
|
||||
accent.strong_hover = #4050aaff
|
||||
accent.strong_pressed = #36449dff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6e80d8aa
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #9385ffff
|
||||
accent.hover = #9385fdff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #8884b7ff
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #9385ffff
|
||||
accent.hover = #9385fdff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #8884b7ff
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8b7cf6ff
|
||||
accent.hover = #9284fcff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #a094ff6e
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8b7cf6ff
|
||||
accent.hover = #9284fcff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #a094ff6e
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
|
||||
mod dumps;
|
||||
mod selection;
|
||||
mod strong_hover;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//! Primary / accent buttons (`accent.strong`) must show hover and press in every built-in theme,
|
||||
//! in both modes, without the text on them dropping below the text minimum (wordcraft#7317 C7-14).
|
||||
|
||||
use craft_theme::contrast::contrast_ratio;
|
||||
use craft_theme::{Appearance, Contrast, Mode, Size, TextSize, Variants, builtins, resolve};
|
||||
|
||||
/// Least OKLCH lightness change of hover and of press from rest. Below about 0.05 a fill change is
|
||||
/// hard to see next to a neighbouring control.
|
||||
const HOVER_MIN: f64 = 0.05;
|
||||
const PRESSED_MIN: f64 = 0.08;
|
||||
|
||||
#[test]
|
||||
fn strong_accent_hover_and_pressed_are_visible_and_keep_text_contrast() {
|
||||
for theme in builtins() {
|
||||
// Classic pins all three states to one grey: its bevel, not the fill, shows the state.
|
||||
if theme.name == "Classic" {
|
||||
continue;
|
||||
}
|
||||
let modes = match theme.variants {
|
||||
Variants::Both => vec![Mode::Light, Mode::Dark],
|
||||
Variants::LightOnly => vec![Mode::Light],
|
||||
Variants::DarkOnly => vec![Mode::Dark],
|
||||
};
|
||||
for mode in modes {
|
||||
let appearance =
|
||||
Appearance { mode, contrast: Contrast::Standard, size: Size::Comfortable, text_size: TextSize::Small, reduced_motion: false };
|
||||
let c = resolve(theme, appearance, None).tokens.color;
|
||||
let (rest, hover, pressed) = (c.accent.strong, c.accent.strong_hover, c.accent.strong_pressed);
|
||||
let l = |x: craft_theme::color::Rgba| x.to_oklch().l;
|
||||
let who = format!("{} {mode:?}", theme.name);
|
||||
assert!((l(hover) - l(rest)).abs() >= HOVER_MIN, "{who}: hover barely differs from rest");
|
||||
assert!((l(pressed) - l(rest)).abs() >= PRESSED_MIN, "{who}: pressed barely differs from rest");
|
||||
for (state, fill) in [("rest", rest), ("hover", hover), ("pressed", pressed)] {
|
||||
let ratio = contrast_ratio(c.text.on_strong, fill);
|
||||
assert!(ratio >= 4.5, "{who}: text.on_strong on {state} is {ratio:.2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A user asking why the hover fill differs from rest is told which token it starts from and how much
|
||||
/// lightness it moves at least; the floor shown is the one the colour is held to.
|
||||
#[test]
|
||||
fn explaining_strong_hover_names_its_base_and_the_lightness_floor() {
|
||||
use craft_theme::{ColorSource, ColorToken, explain};
|
||||
let theme = builtins().iter().find(|t| t.name != "Classic" && t.variants != Variants::LightOnly).unwrap();
|
||||
let appearance =
|
||||
Appearance { mode: Mode::Dark, contrast: Contrast::Standard, size: Size::Comfortable, text_size: TextSize::Small, reduced_motion: false };
|
||||
let e = explain(theme, appearance, None);
|
||||
let origin = e.color(ColorToken::AccentStrongHover).unwrap();
|
||||
let ColorSource::ShiftedFrom { min, .. } = origin.source else { panic!("hover is a shifted colour: {:?}", origin.source) };
|
||||
let words = origin.source_words();
|
||||
assert!(words.contains(ColorToken::AccentStrong.path()), "names the base token: {words}");
|
||||
assert!(words.contains(&min.to_string()), "names the floor {min}: {words}");
|
||||
}
|
||||
@@ -20,6 +20,8 @@ pub(crate) enum Reply {
|
||||
Corrupt,
|
||||
/// The whole body, already a gzip stream, announced as `Content-Encoding: gzip`.
|
||||
Gzipped,
|
||||
/// GitHub's answer when the quota is used up: 403 with no requests remaining.
|
||||
RateLimited,
|
||||
}
|
||||
|
||||
/// Serves `body` over plain HTTP following `script`, one reply per connection; records the
|
||||
@@ -55,6 +57,10 @@ pub(crate) fn serve(body: Vec<u8>, script: Vec<Reply>) -> (String, Arc<Mutex<Vec
|
||||
.and_then(|()| stream.write_all(&vec![b'x'; len])),
|
||||
Reply::Gzipped => write!(stream, "HTTP/1.1 200 OK\r\nContent-Length: {len}\r\nContent-Encoding: gzip\r\nConnection: close\r\n\r\n")
|
||||
.and_then(|()| stream.write_all(&body)),
|
||||
Reply::RateLimited => write!(
|
||||
stream,
|
||||
"HTTP/1.1 403 Forbidden\r\nx-ratelimit-remaining: 0\r\nx-ratelimit-reset: 4102444800\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
|
||||
),
|
||||
Reply::Ranged => {
|
||||
let from = range.unwrap_or(0);
|
||||
write!(
|
||||
@@ -141,3 +147,18 @@ fn gzip(data: &[u8]) -> Vec<u8> {
|
||||
enc.write_all(data).unwrap();
|
||||
enc.finish().unwrap()
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_rate_limited_release_check_is_typed_not_english_text() {
|
||||
let http = Http::new(crate::TEST_AGENT).unwrap();
|
||||
let app = crate::suite::PHOTOCRAFT;
|
||||
let (url, _) = serve(Vec::new(), vec![Reply::RateLimited]);
|
||||
assert_eq!(crate::check_releases_at(&url, &app, &http, "0.1.0"), Err(crate::CheckError::RateLimited));
|
||||
// A normal answer is not mistaken for the limit, and a failure keeps its reason as data.
|
||||
let (url, _) = serve(b"[]".to_vec(), vec![Reply::Full]);
|
||||
assert_eq!(crate::check_releases_at(&url, &app, &http, "0.1.0"), Ok(None));
|
||||
// A port that was free a moment ago: the connection is refused.
|
||||
let closed = format!("http://{}/", TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap());
|
||||
let why = crate::check_releases_at(&closed, &app, &http, "0.1.0").unwrap_err();
|
||||
assert!(matches!(&why, crate::CheckError::Failed(text) if why.to_string() == *text));
|
||||
}
|
||||
|
||||
@@ -56,14 +56,50 @@ pub mod testing {
|
||||
craft_ui::registry!();
|
||||
}
|
||||
|
||||
/// Why a check for an update failed. [`RateLimited`](Self::RateLimited) is a typed reason, so the app
|
||||
/// words it in the interface language ([`stack_dialogs::UpdateWords`] has the crate's wording); the text
|
||||
/// of [`Failed`](Self::Failed) is data (GitHub's, the network's, or the crate's English) and stays as it came.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CheckError {
|
||||
/// GitHub refused the request because its quota is used up.
|
||||
RateLimited,
|
||||
/// Any other failure, with its English reason.
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CheckError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::RateLimited => f.write_str("GitHub's request limit was reached"),
|
||||
Self::Failed(why) => f.write_str(why),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for CheckError {
|
||||
fn from(why: String) -> Self {
|
||||
Self::Failed(why)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for CheckError {
|
||||
fn from(why: &str) -> Self {
|
||||
Self::Failed(why.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks for an update against GitHub releases for the given app.
|
||||
pub fn check_for_update(app: &App, http: &Http, current_version: &str) -> Result<Option<Release>, String> {
|
||||
pub fn check_for_update(app: &App, http: &Http, current_version: &str) -> Result<Option<Release>, CheckError> {
|
||||
check_releases_at(&format!("https://api.github.com/repos/{}/releases?per_page=30", app.repo), app, http, current_version)
|
||||
}
|
||||
|
||||
/// [`check_for_update`] against the release list at `url` (a loopback server in tests).
|
||||
fn check_releases_at(url: &str, app: &App, http: &Http, current_version: &str) -> Result<Option<Release>, CheckError> {
|
||||
let version = self_update::current_version(app, current_version).map(|v| v.to_string());
|
||||
let current_version = version.as_deref().unwrap_or(current_version);
|
||||
let url = format!("https://api.github.com/repos/{}/releases?per_page=30", app.repo);
|
||||
match http.get_api(&url, None)? {
|
||||
crate::http::Fetched::Body { text, .. } => offered_release(&text, app.repo, current_version),
|
||||
crate::http::Fetched::RateLimited { .. } => Err("GitHub's request limit was reached".into()),
|
||||
match http.get_api(url, None)? {
|
||||
crate::http::Fetched::Body { text, .. } => Ok(offered_release(&text, app.repo, current_version)?),
|
||||
crate::http::Fetched::RateLimited { .. } => Err(CheckError::RateLimited),
|
||||
crate::http::Fetched::NotModified | crate::http::Fetched::NotFound => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ pub enum LatestRelease {
|
||||
Found(Release),
|
||||
/// The repo exists but has no published release.
|
||||
None,
|
||||
/// Couldn't find out (offline, rate-limited, unreadable answer).
|
||||
/// GitHub's request limit was reached and nothing was saved to answer from.
|
||||
RateLimited,
|
||||
/// Couldn't find out (offline, unreadable answer); the reason is data.
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
|
||||
@@ -171,10 +171,9 @@ impl ReleaseSource for GitHubSource {
|
||||
Err(e) => log::warn!("{repo}: release pages: {e}"),
|
||||
}
|
||||
}
|
||||
let why = api_error.unwrap_or_else(|| "GitHub's request limit was reached".into());
|
||||
match self.cached(repo, prereleases) {
|
||||
Some(latest) => Answer { latest, source: Source::Cache },
|
||||
None => Answer { latest: LatestRelease::Failed(why), source: Source::Cache },
|
||||
None => Answer { latest: api_error.map_or(LatestRelease::RateLimited, LatestRelease::Failed), source: Source::Cache },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +217,16 @@ pub(crate) mod tests {
|
||||
use super::*;
|
||||
use craft_ui::testing::trial;
|
||||
|
||||
#[trial]
|
||||
fn a_rate_limited_source_with_nothing_saved_answers_rate_limited_not_english_text() {
|
||||
// Nothing is written (a rate-limited answer saves nothing), and a name only this run uses has no cache to read.
|
||||
let dir = std::env::temp_dir().join(format!("craft-update-source-rate-limited-{}-{}", std::process::id(), crate::now()));
|
||||
let http = Http::new("craft-update-test/0.0").expect("an HTTP client");
|
||||
let source = GitHubSource::new(http, dir.join("releases.json"));
|
||||
*source.limited_until.lock().expect("lock") = Some(crate::now() + 600);
|
||||
assert_eq!(source.latest("storytold/none", true).latest, LatestRelease::RateLimited);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_reset_past_the_quota_window_cannot_stop_the_api_for_good() {
|
||||
assert_eq!(retry_at(Some(i64::MAX), 1_000), 1_000 + 60 * 60);
|
||||
|
||||
@@ -56,6 +56,8 @@ craft_ui::words! {
|
||||
checking: "updateDialog.checking" = "Checking for updates…";
|
||||
up_to_date: template "updateDialog.upToDate" = "{app} {running} is the newest version.";
|
||||
failed: "updateDialog.failed" = "The update check failed.";
|
||||
/// The check dialog's reason when GitHub's request limit was reached ([`crate::updater::Status::RateLimited`]).
|
||||
rate_limited: "updateDialog.rateLimited" = "GitHub's request limit was reached. Try again later.";
|
||||
check_again: "updateDialog.checkAgain" = "Check Again";
|
||||
check_now: "updateDialog.checkNow" = "Check Now";
|
||||
not_checked: "updateDialog.notChecked" = "Updates have not been checked yet.";
|
||||
@@ -462,7 +464,7 @@ impl UpdateCheckDialog {
|
||||
Status::Idle => vec![(CheckChoice::CheckNow, DialogRole::Accept)],
|
||||
Status::Checking | Status::Installing | Status::Updated(_) => vec![(CheckChoice::Close, DialogRole::Accept)],
|
||||
Status::Ready => vec![(CheckChoice::Close, DialogRole::Accept), (CheckChoice::RestartToUpdate, DialogRole::Other)],
|
||||
Status::UpToDate | Status::Managed | Status::Failed(_) | Status::InstallFailed(_) => {
|
||||
Status::UpToDate | Status::Managed | Status::Failed(_) | Status::RateLimited | Status::InstallFailed(_) => {
|
||||
vec![(CheckChoice::Close, DialogRole::Accept), (CheckChoice::CheckAgain, DialogRole::Other)]
|
||||
}
|
||||
}
|
||||
@@ -538,8 +540,12 @@ impl UpdateCheckDialog {
|
||||
Status::UpToDate => {
|
||||
Text::new(words.up_to_date.fill(&[("app", subject.name), ("running", running)])).show(ui);
|
||||
}
|
||||
Status::Failed(error) => {
|
||||
Notice::new(Tone::Bad, error.clone()).title(words.failed.clone()).show(ui);
|
||||
Status::Failed(_) | Status::RateLimited => {
|
||||
let notice = match status {
|
||||
Status::Failed(error) => Notice::new(Tone::Bad, error.clone()),
|
||||
_ => Notice::new(Tone::Bad, words.rate_limited.clone()),
|
||||
};
|
||||
notice.title(words.failed.clone()).show(ui);
|
||||
if let Some(app) = subject.app {
|
||||
let url = app.releases_url();
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
|
||||
@@ -23,11 +23,11 @@ use crate::release::Release;
|
||||
use crate::self_update::{Outcome, Restart};
|
||||
use crate::stack_dialogs::{UpdateChoice, UpdatePromptDialog};
|
||||
use crate::translate::{Note, Translate, english};
|
||||
use crate::{App, Http, Paths, Platform, Stop, check_for_update, self_update};
|
||||
use crate::{App, CheckError, Http, Paths, Platform, Stop, check_for_update, self_update};
|
||||
|
||||
/// Asks for the newest release (blocking; it runs on its own thread). Tests stand in for the network
|
||||
/// with one; without it the check asks GitHub.
|
||||
pub type CheckSource = Arc<dyn Fn() -> Result<Option<Release>, String> + Send + Sync>;
|
||||
pub type CheckSource = Arc<dyn Fn() -> Result<Option<Release>, CheckError> + Send + Sync>;
|
||||
|
||||
/// What a requested check came to, for a window that answers Help ▸ Check for Updates, and what
|
||||
/// the last update came to, at the first start after it.
|
||||
@@ -40,8 +40,10 @@ pub enum Status {
|
||||
Checking,
|
||||
/// A requested check found nothing newer.
|
||||
UpToDate,
|
||||
/// A requested check failed.
|
||||
/// A requested check failed, for this English reason (data, not translated).
|
||||
Failed(String),
|
||||
/// A requested check hit GitHub's request limit; the app words it ([`crate::stack_dialogs::UpdateWords`]).
|
||||
RateLimited,
|
||||
/// A requested check found an update downloading and installing; the startup prompt shows
|
||||
/// its progress.
|
||||
Installing,
|
||||
@@ -81,11 +83,11 @@ pub enum Action {
|
||||
Close,
|
||||
}
|
||||
|
||||
type Checked = Result<Option<Release>, String>;
|
||||
type Checked = Result<Option<Release>, CheckError>;
|
||||
|
||||
/// What the check's thread sends: the release it found, if any, with whether this copy can install
|
||||
/// it itself ([`can_install_itself`]).
|
||||
type Found = Result<Option<(Release, bool)>, String>;
|
||||
type Found = Result<Option<(Release, bool)>, CheckError>;
|
||||
|
||||
/// Says whether this copy can install a release itself (tests stand in for the files with one).
|
||||
type InstallProbe = Arc<dyn Fn(&'static App, &Release) -> bool + Send + Sync>;
|
||||
@@ -559,7 +561,9 @@ impl Updater {
|
||||
let ask = || -> Found {
|
||||
let checked: Checked = match source {
|
||||
Some(ask) => ask(),
|
||||
None => Http::new(&format!("{}/Update", app.name)).and_then(|http| check_for_update(app, &http, &version)),
|
||||
None => {
|
||||
Http::new(&format!("{}/Update", app.name)).map_err(CheckError::from).and_then(|http| check_for_update(app, &http, &version))
|
||||
}
|
||||
};
|
||||
// Whether the copy installs the release itself is read from the installed files
|
||||
// here, on the check's thread, and not in a pass.
|
||||
@@ -577,7 +581,7 @@ impl Updater {
|
||||
});
|
||||
match spawned {
|
||||
Ok(_) => self.check = Some(rx),
|
||||
Err(e) => self.finish_check(Err(format!("couldn't start the update check ({e})"))),
|
||||
Err(e) => self.finish_check(Err(format!("couldn't start the update check ({e})").into())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,7 +665,10 @@ impl Updater {
|
||||
Err(e) => {
|
||||
log::warn!("{} update check failed: {e}", self.app.name);
|
||||
if requested {
|
||||
self.status = Status::Failed(e);
|
||||
self.status = match e {
|
||||
CheckError::RateLimited => Status::RateLimited,
|
||||
CheckError::Failed(why) => Status::Failed(why),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ fn a_finished_update_is_announced_once_by_the_version_it_installed() {
|
||||
#[trial]
|
||||
fn a_check_answering_during_an_update_reports_the_update() {
|
||||
let ctx = egui::Context::default();
|
||||
for answer in [Ok(None), Err("offline".to_owned()), Ok(Some((newer(), false)))] {
|
||||
for answer in [Ok(None), Err("offline".into()), Ok(Some((newer(), false)))] {
|
||||
let mut u = updater(Ok(None));
|
||||
offer_now(&mut u);
|
||||
u.check_now();
|
||||
|
||||
@@ -6,7 +6,7 @@ use craft_ui::dialog::{DialogHost, dialog_id};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_update::pins::{Pins, VersionTrack};
|
||||
use craft_update::release::Release;
|
||||
use craft_update::stack_dialogs::UpdatePromptDialog;
|
||||
use craft_update::stack_dialogs::{UpdateCheckDialog, UpdatePromptDialog, UpdateWords};
|
||||
use craft_update::suite::PHOTOCRAFT;
|
||||
use craft_update::updater::{CheckSource, Status, Updater};
|
||||
use std::cell::RefCell;
|
||||
@@ -15,7 +15,7 @@ use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
type Dialogs = Rc<RefCell<DialogHost>>;
|
||||
type Checked = Result<Option<Release>, String>;
|
||||
type Checked = Result<Option<Release>, craft_update::CheckError>;
|
||||
|
||||
fn newer() -> Release {
|
||||
Release { tag: "v9.0.0".into(), version: craft_update::parse_version("9.0.0"), ..Release::default() }
|
||||
@@ -73,6 +73,37 @@ fn a_check_exposes_the_release_it_found_and_an_up_to_date_one_exposes_none() {
|
||||
assert!(current.available().is_none());
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_rate_limited_check_is_its_own_status_so_the_app_can_translate_it() {
|
||||
let ctx = ctx();
|
||||
let mut u = updater(Err(craft_update::CheckError::RateLimited));
|
||||
u.check_now();
|
||||
u.settle_for_tests(&ctx);
|
||||
assert_eq!(u.status(), &Status::RateLimited);
|
||||
let mut other = updater(Err("offline".into()));
|
||||
other.check_now();
|
||||
other.settle_for_tests(&ctx);
|
||||
assert_eq!(other.status(), &Status::Failed("offline".into()), "any other reason stays data");
|
||||
}
|
||||
|
||||
/// The check dialog open in `status`: whether `text` is on screen.
|
||||
fn check_dialog_shows(status: Status, text: &str) -> bool {
|
||||
let mut dialog = UpdateCheckDialog::new("0.1.0");
|
||||
dialog.set_status(status);
|
||||
let mut dialogs = DialogHost::new();
|
||||
dialogs.open(dialog);
|
||||
let (fixture, _) = rig(dialogs);
|
||||
fixture.texts().iter().any(|t| t.text.contains(text)) || fixture.by_label(text).is_some()
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_check_dialog_words_a_rate_limit_itself_and_passes_other_reasons_through() {
|
||||
let words = UpdateWords::default();
|
||||
assert!(check_dialog_shows(Status::RateLimited, words.rate_limited.as_str()));
|
||||
assert!(!check_dialog_shows(Status::Failed("offline".into()), words.rate_limited.as_str()));
|
||||
assert!(check_dialog_shows(Status::Failed("offline".into()), "offline"));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_panicking_check_is_an_error_not_a_hang() {
|
||||
let ctx = ctx();
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ cargo compiles a crate once per distinct feature set, and every crate above it o
|
||||
|
||||
`cl` selects the `feature-root` package beside the package of every command (`-p <crate> -p feature-root`). Its dependencies are the gallery's, with every domain crate's `suite`, so every local build resolves features as the gallery does, and a target directory holds one build of each crate. Nothing of `feature-root` is compiled: its one target is a bin no `cl` command selects (`cl` names the crate's own targets), and only the targets a command names are built, so a render still links one domain crate and a framework crate's tests still link no app. On top, `cl` adds the crate's own test feature (`suite`, else `screen-testing`, else `testing`). The Mac's and CI's commands never select `feature-root` and are unaffected.
|
||||
|
||||
Four manifest facts keep this true, and `cl doctor` checks them: `feature-root` lists every optional domain crate of the gallery with the gallery's features, and depends on the gallery without its default features (so the gallery lib's own features stay each command's: `apps` for the gallery, one crate for a render); the story renderer asks its shared dependencies for no feature the gallery's lines lack; dev-dependency lines ask egui for no features (a feature there differs between a crate's tests and everything else); the proc-macro crate pins syn's and proc-macro2's features to everything other derive crates may add, so the one syn every proc macro shares is the same with or without design-lint in the graph. `cl` names any new build of a framework crate in the target directory after each command; after a manifest change one is expected, otherwise run `cl doctor`.
|
||||
Five manifest facts keep this true, and `cl doctor` checks them: the gallery links each domain crate's stories as an optional dependency behind a feature of its own (so a render links one domain crate); `feature-root` lists every optional domain crate of the gallery with the gallery's features, and depends on the gallery without its default features (so the gallery lib's own features stay each command's: `apps` for the gallery, one crate for a render); the story renderer asks its shared dependencies for no feature beyond what the gallery's lines turn on (one those features imply, as `suite` implies `testing`, adds nothing); dev-dependency lines ask the egui crates (egui, epaint, epaint_default_fonts, emath, ecolor) for no feature that `feature-root`'s or the normal lines lack (a feature there differs between a crate's tests and everything else); the proc-macro crate pins syn's and proc-macro2's features to everything other derive crates may add, so the one syn every proc macro shares is the same with or without design-lint in the graph. `cl` names any new build of a framework crate in the target directory after each command; after a manifest change one is expected, otherwise run `cl doctor`.
|
||||
|
||||
The `testing` feature (or `screen-testing` on domain crates) supplies fixtures and helpers for app tests. The `suite` feature implies that kit and adds framework stories, registrations, trials, snapshots, and the suite runner. Framework and gallery tests enable `suite`; apps should use the kit without it.
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ RENDER_FEATURES = {
|
||||
"automation", "browse", "color-ui", "draw", "imaging", "layers", "menu", "pages", "print", "review", "table", "text",
|
||||
"theme-editor", "theme-store", "timeline", "dialogs", "font-manager", "update",
|
||||
}
|
||||
# The egui crates every framework crate builds on: a feature only a dev-dependency line asks of one rebuilds the framework.
|
||||
EGUI_FAMILY = {"egui", "epaint", "epaint_default_fonts", "emath", "ecolor"}
|
||||
REFUSED = {
|
||||
"--all-features": "it enables snapshot, system_fonts, color_fonts, all-languages and more, a set no loop uses, which rebuilds every dependency and the whole framework once; CI runs it",
|
||||
"--bins": "the gallery's binaries are 1 GB links each; build the one you need (`cl build gallery`)",
|
||||
@@ -120,8 +122,6 @@ PINS = [
|
||||
"craft-ui-macros must ask proc-macro2 for span-locations, or a build with design-lint in it changes the shared proc-macro2 and rebuilds the framework"),
|
||||
("crates/ui-contract/Cargo.toml", r'^craft-window = \{[^\n]*features = \[[^\]]*"ui"',
|
||||
"craft-ui-contract must depend on craft-window with ui, or the shell's app flips craft-window under the whole framework"),
|
||||
("crates/ui-contract/Cargo.toml", r'^testing = \[[^\]]*"snapshot"',
|
||||
"craft-ui-contract's testing must include snapshot, or crates above widgets cannot ask the runtime for the renderer and build a second variant"),
|
||||
]
|
||||
|
||||
|
||||
@@ -203,6 +203,18 @@ def own_targets(p):
|
||||
return flags
|
||||
|
||||
|
||||
def implied(p, features):
|
||||
"""The features a dependency line turns on in workspace package `p`: `features` and every feature of `p`'s own that
|
||||
they imply. Without `p` (a crate outside the workspace) just `features`."""
|
||||
on, todo = set(), list(features)
|
||||
while todo:
|
||||
f = todo.pop()
|
||||
if f not in on:
|
||||
on.add(f)
|
||||
todo += [e for e in (p["features"].get(f, []) if p else []) if "/" not in e and not e.startswith("dep:")]
|
||||
return on
|
||||
|
||||
|
||||
def doctor(top, packages, quiet=False):
|
||||
"""Manifest lines that would bring the variant churn back. Returns the number of problems."""
|
||||
if APP:
|
||||
@@ -212,16 +224,24 @@ def doctor(top, packages, quiet=False):
|
||||
text = open(os.path.join(top, path)).read()
|
||||
if not re.search(pattern, text, re.M):
|
||||
problems.append(f"{path}: {why}")
|
||||
asked = {}
|
||||
for p in packages.values():
|
||||
for d in p["dependencies"]:
|
||||
if d["name"] in EGUI_FAMILY and d["kind"] is None:
|
||||
asked.setdefault(d["name"], set()).update(d["features"])
|
||||
for p in packages.values():
|
||||
manifest = os.path.relpath(p["manifest_path"], top)
|
||||
for d in p["dependencies"]:
|
||||
if d["name"] == "egui" and d["kind"] == "dev" and d["features"]:
|
||||
problems.append(f"{manifest}: the egui dev-dependency asks for {d['features']}; a feature on a dev-dependency "
|
||||
"line changes egui under the framework between a crate's tests and its render")
|
||||
extra = set(d["features"]) - asked.get(d["name"], set())
|
||||
if d["name"] in EGUI_FAMILY and d["kind"] == "dev" and extra:
|
||||
problems.append(f"{manifest}: the {d['name']} dev-dependency asks for {sorted(extra)}, which no normal line "
|
||||
f"(feature-root's included) asks for; it changes {d['name']} under the framework between the "
|
||||
"crate's tests and every other build")
|
||||
gallery = packages.get("craft-ui-gallery")
|
||||
if gallery:
|
||||
for d in gallery["dependencies"]:
|
||||
if d["name"].startswith("craft-") and "suite" in d["features"] and not d["optional"]:
|
||||
domain = d["name"].startswith("craft-") and d["name"] not in FRAMEWORK
|
||||
if domain and "suite" in d["features"] and not d["optional"]:
|
||||
problems.append(f"crates/ui-gallery/Cargo.toml: {d['name']} must be optional (one feature per domain crate), or the story renderer links every crate")
|
||||
root = packages.get(ROOT)
|
||||
if not root:
|
||||
@@ -243,9 +263,11 @@ def doctor(top, packages, quiet=False):
|
||||
theirs = {d["name"]: d for d in gallery["dependencies"] if d["kind"] is None}
|
||||
for d in render["dependencies"]:
|
||||
g = theirs.get(d["name"])
|
||||
if d["kind"] is None and g and not set(d["features"]) <= set(g["features"]):
|
||||
problems.append(f"crates/story-render/Cargo.toml: {d['name']} asks for {sorted(set(d['features']) - set(g['features']))} "
|
||||
"beyond the gallery's line, so renders build a second copy of it and everything above")
|
||||
if d["kind"] is None and g:
|
||||
extra = set(d["features"]) - implied(packages.get(d["name"]), g["features"])
|
||||
if extra:
|
||||
problems.append(f"crates/story-render/Cargo.toml: {d['name']} asks for {sorted(extra)} beyond what the "
|
||||
"gallery's line turns on, so renders build a second copy of it and everything above")
|
||||
for problem in problems:
|
||||
print(f"cl doctor: {problem}", file=sys.stderr)
|
||||
if not problems and not quiet:
|
||||
@@ -732,7 +754,7 @@ def run(top, cargo_args, then=None, timings=True):
|
||||
"""Runs cargo; `then` (a binary in the target's debug dir and its arguments) runs after a successful cargo. Exits
|
||||
with the last return code."""
|
||||
rc, target, _ = cargo(top, cargo_args, timings=timings)
|
||||
if rc == 0 and then:
|
||||
if rc == 0 and then and not DRY_RUN:
|
||||
rc = run_binary([os.path.join(target, "debug", then[0])] + then[1:], top)
|
||||
sys.exit(rc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user