Skip to content

A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.

feat: add mascot reaction for unplugging charger and update changelog

CristianOlivera15a7b9d2dbdb7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5bb1c43..3db7f70 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,18 @@ copia la sección de la versión que se publica a la release de GitHub.
## [Unreleased]
+### English
+
+- Unplugging the charger now plays a short mascot reaction above the dock,
+ including when unplugging also enables energy saver. It replaces an ongoing
+ charging reaction and temporarily reveals an auto-hidden dock.
+
+### Español
+
+- Al desconectar el cargador, la mascota también aparece sobre el dock,
+ incluso si se activa el ahorro de energía a la vez. Sustituye la reacción
+ de carga si todavía está en curso y muestra temporalmente el dock oculto.
+
## [0.1.11]
### English
diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rs
index ed84073..791b988 100644
--- a/apps/dock/src/app.rs
+++ b/apps/dock/src/app.rs
@@ -457,7 +457,11 @@ fn power_act(
charging_allowed: bool,
) -> Option<mascot::Act> {
let before = before?;
- if now.1 && !before.1 {
+ // Unplugging can also enable energy saver. Keep the charger reaction
+ // instead of replacing it with the less specific saver-only moment.
+ if now.0 == Some(false) && before.0 == Some(true) {
+ Some(mascot::Act::Unplugged)
+ } else if now.1 && !before.1 {
Some(mascot::Act::Sleepy)
} else if now.0 == Some(true) && before.0 == Some(false) && charging_allowed {
Some(mascot::Act::Charging)
@@ -1882,7 +1886,7 @@ impl App {
}
}
- /// The charger plugged in, or energy saver turned on: the crab walks
+ /// The charger plugged in or out, or energy saver turned on: the crab walks
/// along the dock. Only on the change itself, never at startup.
fn power_moment(&mut self) {
let now = (
@@ -1894,11 +1898,21 @@ impl App {
.charging_shown
.is_none_or(|shown| shown.elapsed() >= CHARGING_AGAIN);
let act = power_act(before, now, charging_allowed);
- if let Some(act) = act
- && self.can_perform()
- && let Some(place) = self.dock_edge()
- {
- self.perform(act, place);
+ if let Some(act) = act {
+ if matches!(act, mascot::Act::Charging | mascot::Act::Unplugged)
+ && self.config.mascot
+ && !self.fullscreen
+ && animations_enabled()
+ {
+ // A disconnect must still show if it happens during the
+ // charging reaction; keep only one scene and cleanup timer.
+ self.stop_mascot();
+ }
+ if self.can_perform()
+ && let Some(place) = self.dock_edge()
+ {
+ self.perform(act, place);
+ }
}
}
@@ -3915,9 +3929,32 @@ mod mascot_power_tests {
);
assert_eq!(
power_act(Some((Some(true), true)), (Some(false), false), true),
- None
+ Some(Act::Unplugged)
+ );
+ }
+
+ #[test]
+ fn unplugging_is_not_suppressed_by_charging_cooldown_or_automatic_saver() {
+ assert_eq!(
+ power_act(Some((Some(true), false)), (Some(false), true), false),
+ Some(Act::Unplugged)
+ );
+ assert_eq!(
+ power_act(Some((Some(true), false)), (Some(false), false), false),
+ Some(Act::Unplugged)
);
}
+
+ #[test]
+ fn missing_or_repeated_power_readings_do_not_announce_a_disconnect() {
+ for (before, now) in [
+ (None, Some(false)),
+ (Some(true), None),
+ (Some(false), Some(false)),
+ ] {
+ assert_eq!(power_act(Some((before, false)), (now, false), true), None);
+ }
+ }
}
#[cfg(test)]
diff --git a/apps/dock/src/mascot.rs b/apps/dock/src/mascot.rs
index 3ca8b07..7f595f5 100644
--- a/apps/dock/src/mascot.rs
+++ b/apps/dock/src/mascot.rs
@@ -1,5 +1,5 @@
//! The crab: a pixel-art mascot that comes out only for moments worth it
-//! (an AI plan resetting or running out, the charger plugged in, energy
+//! (an AI plan resetting or running out, the charger plugged in or out, energy
//! saver starting) and plays a short act, then leaves.
//!
//! Cost: nothing while it is away. An act creates a small click-through
@@ -287,6 +287,8 @@ pub enum Act {
Exhausted,
/// The charger was plugged in.
Charging,
+ /// The charger was unplugged: back on battery.
+ Unplugged,
/// Energy saver started.
Sleepy,
}
@@ -373,6 +375,15 @@ impl Script {
emote: Some((Emote::Heart, 2.05, 3.0)),
}
}
+ Act::Unplugged => Self {
+ seconds: 3.2,
+ path: vec![(0.0, centre)],
+ hops: vec![(0.4, 2.0)],
+ shake: None,
+ faces: vec![(0.0, Face::Neutral), (0.8, Face::Sad), (2.0, Face::Neutral)],
+ walking: Vec::new(),
+ emote: Some((Emote::Drop, 0.85, 2.2)),
+ },
// Shuffles in slowly from the right, stops and falls asleep.
Act::Sleepy => {
let rest = width * 0.62 - crab / 2.0;
@@ -912,6 +923,7 @@ mod tests {
Act::Nervous,
Act::Exhausted,
Act::Charging,
+ Act::Unplugged,
Act::Sleepy,
] {
let script = Script::new(act, 800.0, 44.0);
diff --git a/spikes/src/bin/spike_mascot.rs b/spikes/src/bin/spike_mascot.rs
index 05b62e4..c02125b 100644
--- a/spikes/src/bin/spike_mascot.rs
+++ b/spikes/src/bin/spike_mascot.rs
@@ -1,6 +1,6 @@
//! Plays one of the crab's acts (the real `mascot.rs` and `gfx.rs`) on the
//! screen and saves frames of it, to review the choreography. Usage:
-//! `spike_mascot <fresh|nervous|exhausted|charging|sleepy> <out folder>`.
+//! `spike_mascot <fresh|nervous|exhausted|charging|unplugged|sleepy> <out folder>`.
#![allow(dead_code, clippy::unwrap_used, clippy::expect_used)]
@@ -32,6 +32,7 @@ fn main() {
Some("nervous") => mascot::Act::Nervous,
Some("exhausted") => mascot::Act::Exhausted,
Some("charging") => mascot::Act::Charging,
+ Some("unplugged") => mascot::Act::Unplugged,
Some("sleepy") => mascot::Act::Sleepy,
_ => mascot::Act::Fresh,
};
@@ -74,7 +75,7 @@ fn main() {
return;
}
let (place, area) = match act {
- mascot::Act::Charging | mascot::Act::Sleepy => (
+ mascot::Act::Charging | mascot::Act::Unplugged | mascot::Act::Sleepy => (
mascot::Place::Along {
left: 560,
right: 1360,