Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ tokio = { version = "1.41", default-features = false, features = ["time", "rt",
log = { version = "0.4.22", default-features = false }

# used by piggui in GUI only
iced_aw = { version = "0.11", default-features = false, features = ["menu"] }
iced_aw = { git = "https://github.com/andrewdavidmackenzie/iced_aw.git", branch = "fix_menu_crash", version = "0.11", default-features = false, features = ["menu"] }
iced_futures = { version = "0.13", default-features = false }
plotters-iced = { version = "0.11", default-features = false }
plotters = { version = "0.3", default-features = false, features = [
Expand Down
2 changes: 2 additions & 0 deletions src/piggui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
};
#[cfg(feature = "usb-raw")]
use crate::views::hardware_menu;
#[cfg(any(feature = "iroh", feature = "tcp"))]
use crate::views::hardware_view::HardwareTarget::NoHW;
#[cfg(feature = "usb-raw")]
use crate::views::message_box::MessageRowMessage::ShowStatusMessage;
Expand Down Expand Up @@ -273,6 +274,7 @@
self.connect_dialog.enable_widgets_and_hide_spinner();
#[cfg(any(feature = "iroh", feature = "tcp"))]
self.connect_dialog.hide_modal();
self.modal_handler.show_modal = false;

Check warning on line 277 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L277

Added line #L277 was not covered by tests
self.info_row
.add_info_message(Info("Connected to hardware".to_string()));
#[cfg(debug_assertions)] // Output used in testing - DON'T REMOVE
Expand Down
127 changes: 77 additions & 50 deletions src/views/hardware_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
use std::collections::HashMap;
#[cfg(feature = "usb-raw")]
use std::fmt::{Display, Formatter};
#[cfg(all(feature = "tcp", feature = "usb-raw"))]
use std::net::{IpAddr, Ipv4Addr};

#[cfg(feature = "usb-raw")]
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -89,58 +91,83 @@
});

if hardware_description.details.wifi {
#[allow(unused_mut)]
let mut menu_items = vec![
Item::new(
button("Configure Device Wi-Fi...")
.width(Length::Fill)
.on_press(Message::SsidDialog(SsidDialogMessage::Show(
hardware_description.details.clone(),
wifi_details.as_ref().and_then(|wf| wf.ssid_spec.clone()),
)))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE

Check warning on line 105 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L95-L105

Added lines #L95 - L105 were not covered by tests
} else {
MENU_BUTTON_STYLE

Check warning on line 107 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L107

Added line #L107 was not covered by tests
}
}),
),
Item::new(
button("Display Device Details...")
.width(Length::Fill)
.on_press(Message::Modal(HardwareDetailsModal(
hardware_description.details.clone(),
wifi_details.as_ref().unwrap().tcp,
)))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE

Check warning on line 120 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L109-L120

Added lines #L109 - L120 were not covered by tests
} else {
MENU_BUTTON_STYLE

Check warning on line 122 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L122

Added line #L122 was not covered by tests
}
}),
),
Item::new(
button("Reset Device Wi-Fi to Default")
.width(Length::Fill)
.on_press(Message::ResetSsid(
hardware_description.details.serial.clone(),
))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE

Check warning on line 134 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L124-L134

Added lines #L124 - L134 were not covered by tests
} else {
MENU_BUTTON_STYLE

Check warning on line 136 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L136

Added line #L136 was not covered by tests
}
}),
),
];

Check warning on line 140 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L138-L140

Added lines #L138 - L140 were not covered by tests

#[cfg(feature = "tcp")]
if let Porky(
_,
_,
Some(WiFiDetails {
ssid_spec: _,
tcp: Some((ip, port)),

Check warning on line 148 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L148

Added line #L148 was not covered by tests
}),
) = device
{
let target =
Tcp(IpAddr::V4(Ipv4Addr::new(ip[0], ip[1], ip[2], ip[3])), *port);
menu_items.push(Item::new(
button("Connect to Device by TCP")
.width(Length::Fill)
.on_press(Message::ConnectRequest(target))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE

Check warning on line 160 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L150-L160

Added lines #L150 - L160 were not covered by tests
} else {
MENU_BUTTON_STYLE

Check warning on line 162 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L162

Added line #L162 was not covered by tests
}
}),
));
}

Check warning on line 166 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L164-L166

Added lines #L164 - L166 were not covered by tests

device_items.push(Item::with_menu(
device_button,
Menu::new(vec![
Item::new(
button("Configure Device Wi-Fi...")
.width(Length::Fill)
.on_press(Message::SsidDialog(
SsidDialogMessage::ShowSsidDialog(
hardware_description.details.clone(),
wifi_details.as_ref().unwrap().ssid_spec.clone(), // TODO unwrap
),
))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE
} else {
MENU_BUTTON_STYLE
}
}),
),
Item::new(
button("Display Device Details...")
.width(Length::Fill)
.on_press(Message::Modal(HardwareDetailsModal(
hardware_description.details.clone(),
wifi_details.as_ref().unwrap().tcp,
)))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE
} else {
MENU_BUTTON_STYLE
}
}),
),
Item::new(
button("Reset Device Wi-Fi to Default")
.width(Length::Fill)
.on_press(Message::ResetSsid(
hardware_description.details.serial.clone(),
))
.style(|_, status| {
if status == Hovered {
MENU_BUTTON_HOVER_STYLE
} else {
MENU_BUTTON_STYLE
}
}),
),
])
.width(280.0)
.offset(10.0),
Menu::new(menu_items).width(280.0).offset(10.0),

Check warning on line 170 in src/views/hardware_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/views/hardware_menu.rs#L170

Added line #L170 was not covered by tests
));
} else {
device_items.push(Item::new(device_button));
Expand Down
50 changes: 40 additions & 10 deletions src/views/info_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
MODAL_CANCEL_BUTTON_STYLE, MODAL_CONNECT_BUTTON_HOVER_STYLE, MODAL_CONNECT_BUTTON_STYLE,
MODAL_CONTAINER_STYLE,
};
use crate::views::hardware_view::HardwareTarget;
#[cfg(feature = "tcp")]
use crate::views::hardware_view::HardwareTarget::Tcp;
use crate::views::version::REPOSITORY;
use crate::Message;
use iced::keyboard::key;
use iced::widget::button::Status::Hovered;
use iced::widget::{button, column, container, text, Row, Space, Text};
use iced::widget::{button, column, container, horizontal_space, text, Row, Space, Text};
use iced::{keyboard, window, Color, Element, Event, Length, Task};
use iced_futures::core::Alignment;
use iced_futures::Subscription;
#[cfg(feature = "tcp")]
use std::net::{IpAddr, Ipv4Addr};

pub struct InfoDialog {
pub show_modal: bool,
is_warning: bool,
modal_type: Option<ModalType>,
target: Option<HardwareTarget>,
}
pub enum ModalType {
Warning {
Expand Down Expand Up @@ -51,6 +57,7 @@
show_modal: false,
is_warning: false,
modal_type: None,
target: None,
}
}

Expand All @@ -75,18 +82,25 @@
}

// Display hardware information
#[allow(unused_variables)]
InfoDialogMessage::HardwareDetailsModal(hardware_details, tcp) => {
self.show_modal = true;
self.is_warning = false;
let body = match tcp {
None => hardware_details.to_string(),
Some(t) => {
format!(
"{}\nIP Address/Port: {}.{}.{}.{}:{}",
hardware_details, t.0[0], t.0[1], t.0[2], t.0[3], t.1
)
}
};
#[allow(unused_mut)]
let mut body = format!("{hardware_details}");

Check warning on line 90 in src/views/info_dialog.rs

View check run for this annotation

Codecov / codecov/patch

src/views/info_dialog.rs#L89-L90

Added lines #L89 - L90 were not covered by tests

#[cfg(feature = "tcp")]
if let Some(t) = tcp {
self.target = Some(Tcp(
IpAddr::V4(Ipv4Addr::new(t.0[0], t.0[1], t.0[2], t.0[3])),
t.1,
));
body.push_str(&format!(
"\nIP Address/Port: {}.{}.{}.{}:{}",
t.0[0], t.0[1], t.0[2], t.0[3], t.1
));
}

Check warning on line 102 in src/views/info_dialog.rs

View check run for this annotation

Codecov / codecov/patch

src/views/info_dialog.rs#L93-L102

Added lines #L93 - L102 were not covered by tests

self.modal_type = Some(ModalType::Info {
title: "Device Details".to_string(),
body,
Expand Down Expand Up @@ -250,6 +264,22 @@
}
}),
);
if let Some(target) = &self.target {
button_row = button_row
.push(horizontal_space())
.push(
button("Connect")
.on_press(Message::ConnectRequest(target.clone()))
.style(move |_theme, status| {
if status == Hovered {
MODAL_CONNECT_BUTTON_HOVER_STYLE

Check warning on line 275 in src/views/info_dialog.rs

View check run for this annotation

Codecov / codecov/patch

src/views/info_dialog.rs#L267-L275

Added lines #L267 - L275 were not covered by tests
} else {
MODAL_CONNECT_BUTTON_STYLE

Check warning on line 277 in src/views/info_dialog.rs

View check run for this annotation

Codecov / codecov/patch

src/views/info_dialog.rs#L277

Added line #L277 was not covered by tests
}
}),
)
.align_y(iced::Alignment::Center);
}

Check warning on line 282 in src/views/info_dialog.rs

View check run for this annotation

Codecov / codecov/patch

src/views/info_dialog.rs#L279-L282

Added lines #L279 - L282 were not covered by tests
}

container(
Expand Down
14 changes: 6 additions & 8 deletions src/views/ssid_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use self::SsidDialogMessage::{
ConnectionError, HideSsidDialog, ModalKeyEvent, NameEntered, PasswordEntered,
SendButtonPressed, ShowSsidDialog,
SendButtonPressed, Show,
};

use crate::widgets::spinner::circular::Circular;
Expand Down Expand Up @@ -48,7 +48,8 @@ pub enum SsidDialogMessage {
ModalKeyEvent(Event),
SendButtonPressed(String, String, String),
HideSsidDialog,
ShowSsidDialog(HardwareDetails, Option<SsidSpec>),
/// Show the dialog to configure Wi-Fi details of a connected device
Show(HardwareDetails, Option<SsidSpec>),
ConnectionError(String),
HidePasswordToggled,
}
Expand Down Expand Up @@ -160,7 +161,7 @@ impl SsidDialog {
}
}

ShowSsidDialog(hardware_details, wifi) => {
Show(hardware_details, wifi) => {
self.hardware_details = hardware_details;
self.ssid_spec = wifi.unwrap_or(SsidSpec::default());
self.show_modal = true;
Expand Down Expand Up @@ -355,10 +356,7 @@ mod tests {
let mut ssid_dialog = SsidDialog::new();
assert!(!ssid_dialog.show_modal);

let _ = ssid_dialog.update(ShowSsidDialog(
HardwareDetails::default(),
Some(SsidSpec::default()),
));
let _ = ssid_dialog.update(Show(HardwareDetails::default(), Some(SsidSpec::default())));
assert!(ssid_dialog.show_modal);
}

Expand All @@ -367,7 +365,7 @@ mod tests {
let mut ssid_dialog = SsidDialog::new();
assert!(!ssid_dialog.show_modal);

let _ = ssid_dialog.update(ShowSsidDialog(HardwareDetails::default(), None));
let _ = ssid_dialog.update(Show(HardwareDetails::default(), None));
assert!(ssid_dialog.show_modal);
}

Expand Down