Skip to content

Commit

Permalink
migrating to iced 0.13 (window id)
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Sep 21, 2024
1 parent f2ae7dd commit 5b3833c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/gui/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub struct Sniffer {
pub export_pcap: ExportPcap,
/// Whether thumbnail mode is currently active
pub thumbnail: bool,
/// Window id
pub id: Option<Id>,
}

impl Sniffer {
Expand Down Expand Up @@ -170,6 +172,7 @@ impl Sniffer {
timing_events: TimingEvents::default(),
export_pcap: ExportPcap::default(),
thumbnail: false,
id: None,
}
}

Expand Down Expand Up @@ -435,7 +438,7 @@ impl Sniffer {
}
Message::CloseRequested => {
self.configs.lock().unwrap().clone().store();
return window::close(window::get_oldest());
return window::close(self.id.unwrap());
}
Message::CopyIp(string) => {
self.timing_events.copy_ip_now(string.clone());
Expand Down Expand Up @@ -476,25 +479,25 @@ impl Sniffer {
let position = self.configs.lock().unwrap().window.thumbnail_position;
self.timing_events.thumbnail_enter_now();
Task::batch([
window::maximize(Id::MAIN, false),
window::toggle_decorations(Id::MAIN),
window::resize(Id::MAIN, size),
window::move_to(Id::MAIN, position.to_point()),
window::change_level(Id::MAIN, Level::AlwaysOnTop),
window::maximize(self.id.unwrap(), false),
window::toggle_decorations(self.id.unwrap()),
window::resize(self.id.unwrap(), size),
window::move_to(self.id.unwrap(), position.to_point()),
window::change_level(self.id.unwrap(), Level::AlwaysOnTop),
])
} else {
if self.running_page.eq(&RunningPage::Notifications) {
self.unread_notifications = 0;
}
let mut commands = vec![
window::toggle_decorations(Id::MAIN),
window::change_level(Id::MAIN, Level::Normal),
window::toggle_decorations(self.id.unwrap()),
window::change_level(self.id.unwrap(), Level::Normal),
];
if !triggered_by_resize {
let size = self.configs.lock().unwrap().window.size.to_size();
let position = self.configs.lock().unwrap().window.position.to_point();
commands.push(window::move_to(Id::MAIN, position));
commands.push(window::resize(Id::MAIN, size));
commands.push(window::move_to(self.id.unwrap(), position));
commands.push(window::resize(self.id.unwrap(), size));
}
Task::batch(commands)
};
Expand All @@ -503,7 +506,7 @@ impl Sniffer {
let was_just_thumbnail_click = self.timing_events.was_just_thumbnail_click();
self.timing_events.thumbnail_click_now();
if was_just_thumbnail_click {
return window::drag(Id::MAIN);
return window::drag(self.id.unwrap());
}
}
Message::CtrlTPressed => {
Expand All @@ -522,6 +525,7 @@ impl Sniffer {
self.configs.lock().unwrap().settings.scale_factor += delta;
}
}
Message::WindowId(id) => self.id = id,
Message::TickInit => {}
}
Task::none()
Expand Down
3 changes: 3 additions & 0 deletions src/gui/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::report::types::sort_type::SortType;
use crate::utils::types::file_info::FileInfo;
use crate::utils::types::web_page::WebPage;
use crate::{ChartType, IpVersion, Language, Protocol, ReportSortType, StyleType};
use iced::window;

#[derive(Debug, Clone)]
/// Messages types that permit to react to application interactions/subscriptions
Expand Down Expand Up @@ -119,4 +120,6 @@ pub enum Message {
CtrlTPressed,
/// Edit scale factor via keyboard shortcut
ScaleFactorShortcut(bool),
/// Set the window ID
WindowId(Option<window::Id>),
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::configs::types::config_window::{ConfigWindow, ToPosition, ToSize};
use crate::configs::types::configs::Configs;
use crate::gui::sniffer::FONT_FAMILY_NAME;
use crate::gui::styles::style_constants::{ICONS_BYTES, SARASA_MONO_BOLD_BYTES, SARASA_MONO_BYTES};
use crate::gui::types::message::Message;
use crate::secondary_threads::check_updates::set_newer_release_status;

mod chart;
Expand Down Expand Up @@ -125,7 +126,7 @@ pub fn main() -> iced::Result {
.run_with(move || {
(
Sniffer::new(&configs1, newer_release_available1),
Task::none(),
Task::none().chain(window::get_latest().map(Message::WindowId)),
)
})
}

0 comments on commit 5b3833c

Please sign in to comment.