use welcome screen reversed for quit animation

This commit is contained in:
GyulyVGC 2025-11-07 11:51:26 +01:00
parent 7f1c73a70c
commit 2cbddaee36
3 changed files with 55 additions and 49 deletions

View file

@ -8,36 +8,36 @@ use iced::{Alignment, Font, Length};
pub fn welcome_page<'a>(font: Font, x: u8) -> Container<'a, Message, StyleType> {
let icon = match x {
0..=3 | 26.. => Text::new(""),
4 | 25 => Icon::Sniffnet1.to_text(),
5 | 24 => Icon::Sniffnet2.to_text(),
6 | 23 => Icon::Sniffnet3.to_text(),
7 | 22 => Icon::Sniffnet4.to_text(),
8..=21 => Icon::Sniffnet.to_text(),
0..=3 | 20.. => Text::new(""),
4 => Icon::Sniffnet1.to_text(),
5 => Icon::Sniffnet2.to_text(),
6 => Icon::Sniffnet3.to_text(),
7 => Icon::Sniffnet4.to_text(),
8..=19 => Icon::Sniffnet.to_text(),
};
let text = Text::new(match x {
0..=3 | 26.. => "",
4 | 25 => "S",
5 | 24 => "Sn",
6 | 23 => "Sni",
7 | 22 => "Snif",
8 | 21 => "Sniff",
9 | 20 => "Sniffn",
10 | 19 => "Sniffne",
11..=18 => "Sniffnet",
0..=3 | 20.. => "",
4 => "S",
5 => "Sn",
6 => "Sni",
7 => "Snif",
8 => "Sniff",
9 => "Sniffn",
10 => "Sniffne",
11..=19 => "Sniffnet",
});
let text_type = match x {
0..=3 | 26.. => TextType::Welcome(0.0),
4 | 25 => TextType::Welcome(0.125),
5 | 24 => TextType::Welcome(0.25),
6 | 23 => TextType::Welcome(0.375),
7 | 22 => TextType::Welcome(0.5),
8 | 21 => TextType::Welcome(0.625),
9 | 20 => TextType::Welcome(0.750),
10 | 19 => TextType::Welcome(0.875),
11..=18 => TextType::Welcome(1.0),
0..=3 | 20.. => TextType::Welcome(0.0),
4 => TextType::Welcome(0.125),
5 => TextType::Welcome(0.25),
6 => TextType::Welcome(0.375),
7 => TextType::Welcome(0.5),
8 => TextType::Welcome(0.625),
9 => TextType::Welcome(0.750),
10 => TextType::Welcome(0.875),
11..=19 => TextType::Welcome(1.0),
};
let body = Column::new()

View file

@ -78,8 +78,8 @@ pub const ICON_FONT_FAMILY_NAME: &str = "Icons for Sniffnet";
pub struct Sniffer {
/// Parameters that are persistent across runs
pub conf: Conf,
/// Are we in welcome page
pub welcome: Option<u8>,
/// Are we during welcome / quit animation? None if not, true if welcome, false if quit
pub welcome: Option<(bool, u8)>,
/// Capture receiver clone (to close the channel after every run), with the current capture id (to ignore pending messages from previous captures)
pub current_capture_rx: (usize, Option<Receiver<BackendTrafficMessage>>),
/// Capture data
@ -143,7 +143,7 @@ impl Sniffer {
let capture_source = CaptureSource::from_conf(&conf);
Self {
conf,
welcome: Some(0),
welcome: Some((true, 0)),
current_capture_rx: (0, None),
info_traffic: InfoTraffic::default(),
addresses_resolved: HashMap::new(),
@ -240,8 +240,13 @@ impl Sniffer {
}
fn time_subscription(&self) -> Subscription<Message> {
if self.welcome.is_some() {
iced::time::every(Duration::from_millis(100)).map(|_| Message::Welcome)
if let Some((w, _)) = self.welcome {
let sub = iced::time::every(Duration::from_millis(100));
if w {
sub.map(|_| Message::Welcome)
} else {
sub.map(|_| Message::Quit)
}
} else {
iced::time::every(Duration::from_millis(1000)).map(|_| Message::Periodic)
}
@ -269,15 +274,6 @@ impl Sniffer {
Task::perform(set_newer_release_status(), Message::SetNewerReleaseStatus),
]);
}
Message::Welcome => {
if let Some(x) = self.welcome {
if x >= 26 {
self.welcome = None;
} else {
self.welcome = Some(x + 1);
}
}
}
Message::TickRun(cap_id, msg, host_msgs, no_more_packets) => {
if cap_id == self.current_capture_rx.0 {
for host_msg in host_msgs {
@ -451,8 +447,25 @@ impl Sniffer {
}
Message::QuitWrapper => return self.quit_wrapper(),
Message::Quit => {
let _ = self.conf.clone().store();
return window::close(self.id.unwrap_or_else(Id::unique));
if self.welcome.is_none() {
self.welcome = Some((false, 13));
} else if let Some((false, x)) = self.welcome {
if x <= 2 {
let _ = self.conf.clone().store();
return window::close(self.id.unwrap_or_else(Id::unique));
} else {
self.welcome = Some((false, x.saturating_sub(1)));
}
}
}
Message::Welcome => {
if let Some((true, x)) = self.welcome {
if x >= 19 {
self.welcome = None;
} else {
self.welcome = Some((true, x + 1));
}
}
}
Message::CopyIp(ip) => {
self.timing_events.copy_ip_now(ip);
@ -616,7 +629,7 @@ impl Sniffer {
let font = style.get_extension().font;
let font_headers = style.get_extension().font_headers;
if let Some(x) = self.welcome {
if let Some((_, x)) = self.welcome {
return welcome_page(font, x).into();
}

View file

@ -76,14 +76,7 @@ pub fn highlight(style: &StyleType, element: TextType) -> Color {
if n < 0.0 || n > 1.0 {
n = 1.0
};
let std = colors.text_body;
let end = secondary;
Color {
r: std.r * (1.0 - n) + end.r * n,
g: std.g * (1.0 - n) + end.g * n,
b: std.b * (1.0 - n) + end.b * n,
a: 1.0,
}
Color { a: n, ..secondary }
}
TextType::Incoming => colors.secondary,
TextType::Outgoing => colors.outgoing,