Skip to content

Commit

Permalink
Merge pull request #170 from swetar-mecha/settings-app/ui-improvements
Browse files Browse the repository at this point in the history
fix(settings-app): add network use cases handle
  • Loading branch information
akshayr-mecha authored Jan 6, 2025
2 parents 288ac2c + 1f61327 commit 3097254
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 47 deletions.
2 changes: 1 addition & 1 deletion apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
default-members = ["settings-app", "camera", "files"]

[workspace.package]
version = "0.1.13"
version = "0.1.14"
authors = [
"Sweta <[email protected]>",
"Naman <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions apps/settings-app/settings.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ modules:
footer:
back_icon: /usr/share/mechanix/apps/settings/assets/icons/back_icon.png
confirm_icon: /usr/share/mechanix/apps/settings/assets/icons/confirm_icon.png
enable_confirm_icon: /usr/share/mechanix/apps/settings/assets/icons/enable_confirm_icon.svg
disable_confirm_icon: /usr/share/mechanix/apps/settings/assets/icons/disable_confirm_icon.svg
delete_icon: /usr/share/mechanix/apps/settings/assets/icons/delete_icon.png
add_icon: /usr/share/mechanix/apps/settings/assets/icons/add_icon.png
not_found:
Expand Down
10 changes: 10 additions & 0 deletions apps/settings-app/src/assets/icons/disable_confirm_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions apps/settings-app/src/assets/icons/enable_confirm_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions apps/settings-app/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ macro_rules! header_node {
result_node
}};

($title:expr, $back_on_click:expr, $right_icon_1:expr, $right_icon_1_on_click:expr) => {{
($title:expr, $back_on_click:expr, $right_icon_1:expr, $right_icon_1_type: expr , $right_icon_1_on_click:expr) => {{

let text_node = node!(
Text::new(txt!($title))
Expand Down Expand Up @@ -213,7 +213,7 @@ macro_rules! header_node {
.push(node!(
IconButton::new($right_icon_1)
.on_click($right_icon_1_on_click)
.icon_type(IconType::Png)
.icon_type($right_icon_1_type)
.with_class(" border-0 p-0")
.style(
"size",
Expand Down
2 changes: 2 additions & 0 deletions apps/settings-app/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub const BACK_ICON: &str = concatcp!(ASSET_PATH, "back_icon.png");
pub const ADD_ICON: &str = concatcp!(ASSET_PATH, "add_icon.png");
pub const DELETE_ICON: &str = concatcp!(ASSET_PATH, "delete_icon.png");
pub const CONFIRM_ICON: &str = concatcp!(ASSET_PATH, "confirm_icon.png");
pub const ENABLE_CONFIRM_ICON: &str = concatcp!(ASSET_PATH, "enable_confirm_icon.svg");
pub const DISABLE_CONFIRM_ICON: &str = concatcp!(ASSET_PATH, "disable_confirm_icon.svg");

// about
pub const ABOUT_ICON: &str = concatcp!(ASSET_PATH, "about_icon.png");
Expand Down
8 changes: 8 additions & 0 deletions apps/settings-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ async fn main() -> anyhow::Result<()> {
AssetParams::new(modules.footer.confirm_icon),
);

if let icon = modules.footer.enable_confirm_icon {
svgs.insert("enable_confirm_icon".to_string(), icon);
}

if let icon = modules.footer.disable_confirm_icon {
svgs.insert("disable_confirm_icon".to_string(), icon);
}

assets.insert(
"delete_icon".to_string(),
AssetParams::new(modules.footer.delete_icon),
Expand Down
44 changes: 26 additions & 18 deletions apps/settings-app/src/screens/network/add_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,40 @@ impl Debug for Form {

#[derive(Debug)]
pub struct NetworkScreenState {
pub name: String,
form: &'static Form,
}

#[derive(Debug)]
#[component(State = "NetworkScreenState")]
pub struct AddNetwork {
form: &'static Form,
name: String,
// form: &'static Form,
pub ssid: String,
}

impl AddNetwork {
pub fn new(name: String) -> Self {
pub fn new(ssid: String) -> Self {
Self {
state: Some(NetworkScreenState { name: name.clone() }),
state: Some(NetworkScreenState { form: &FORM }),
dirty: false,
form: &FORM,
name,
ssid,
}
}
}

impl Component for AddNetwork {
fn init(&mut self) {
FORM.ssid.set(self.name.clone());
FORM.ssid.set(self.ssid.clone());
FORM.password.set("".to_string());
}

fn view(&self) -> Option<Node> {
let network_name: String = self.state_ref().name.clone();
let network_name: String = self.ssid.clone();

let header_text = if network_name.clone().len() == 0 {
"Add Network"
} else {
&truncate(network_name.clone(), 20).to_string()
};

let mut base: Node = node!(
Div::new(),
Expand Down Expand Up @@ -131,7 +137,7 @@ impl Component for AddNetwork {
]
)
.push(node!(
VDivider {
VDivider {
size: 0.8,
color: Color::rgba(83., 83., 83., 1.),
},
Expand All @@ -158,7 +164,7 @@ impl Component for AddNetwork {
.style("cursor_color", Color::WHITE)
.style("placeholder_color", Color::rgb(107., 107., 107.))
.on_change(Box::new(|s| {
FORM.password.set(s.to_string());
FORM.ssid.set(s.to_string());
msg!(())
}))
.placeholder("Enter SSID"),
Expand Down Expand Up @@ -244,11 +250,12 @@ impl Component for AddNetwork {
)),
);

let header_text = if FORM.ssid.get().clone().len() == 0 {
"Add Network"
} else {
&truncate(network_name.clone(), 20).to_string()
};
let confirm_icon =
if FORM.password.get().clone().len() == 0 || FORM.ssid.get().clone().len() == 0 {
"disable_confirm_icon"
} else {
"enable_confirm_icon"
};

base = base.push(header_node!(
header_text,
Expand All @@ -259,7 +266,8 @@ impl Component for AddNetwork {
}
})
}),
"confirm_icon",
confirm_icon,
IconType::Svg,
Box::new(|| {
if !FORM.password.get().clone().is_empty() {
WirelessModel::connect_to_network(
Expand All @@ -278,7 +286,7 @@ impl Component for AddNetwork {
})
));

if FORM.ssid.get().clone().len() == 0 {
if self.ssid.clone().len() == 0 {
content_node = content_node.push(name_row_node);
content_node = content_node.push(node!(HDivider {
size: 0.8,
Expand Down
1 change: 1 addition & 0 deletions apps/settings-app/src/screens/network/network_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ impl Component for NetworkDetails {
}
})),
"delete_icon",
IconType::Png,
Box::new(move || {
// WirelessModel::disconnect();
WirelessModel::forget_saved_network(connected_network.clone().name.to_string());
Expand Down
42 changes: 22 additions & 20 deletions apps/settings-app/src/screens/network/networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,28 @@ impl Component for NetworkingScreen {
let mut is_known = false;
let mut is_current = false;
let mut network_id = "".to_string();
for known_network in known_networks.iter() {
if known_network.ssid == network.name {
if known_network.flags.contains("[CURRENT]") {
is_current = true;
if !network.name.is_empty() {
for known_network in known_networks.iter() {
if known_network.ssid == network.name {
if known_network.flags.contains("[CURRENT]") {
is_current = true;
}
network_id = known_network.network_id.clone();
is_known = true;
break;
}
network_id = known_network.network_id.clone();
is_known = true;
break;
}
}
if connected_network_name.clone() == network.name {
is_current = true;
}
if is_current {
continue;
}
if is_known {
saved_available_networks.push((network, network_id));
} else {
unsaved_available_networks.push(network);
if connected_network_name.clone() == network.name {
is_current = true;
}
if is_current {
continue;
}
if is_known {
saved_available_networks.push((network, network_id));
} else {
unsaved_available_networks.push(network);
}
}
}

Expand Down Expand Up @@ -399,7 +401,7 @@ impl Component for NetworkingScreen {
]
)
.push(node!(
Text::new(txt!(truncate(network.name.clone(), 30)))
Text::new(txt!(truncate(network.name.clone(), 22)))
.style("color", Color::WHITE)
.style("font", "Inter")
.with_class("text-2xl leading-7 font-normal"),
Expand Down Expand Up @@ -513,7 +515,7 @@ impl Component for NetworkingScreen {
]
)
.push(node!(
Text::new(txt!(truncate(network.name.clone(), 28)))
Text::new(txt!(truncate(network.name.clone(), 22)))
.style("color", Color::WHITE)
.style("font", "Inter")
.with_class("text-2xl leading-7 font-normal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ impl Component for SavedNetworkDetails {
})
}),
"delete_icon",
IconType::Png,
Box::new(move || {
WirelessModel::forget_saved_network(full_network_name.to_string());
msg!(Message::ChangeRoute {
Expand Down
25 changes: 25 additions & 0 deletions apps/settings-app/src/screens/network/wireless_model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,30 @@ impl WirelessModel {
});
}

fn stream_device_state() {
RUNTIME.spawn(async {
let connection = zbus::Connection::system().await.unwrap();
let device = Self::get_wifi_device_path().await;

let device_proxy = device::DeviceProxy::new(&connection, device.clone())
.await
.unwrap();
let mut stream = device_proxy.receive_state_changed().await;
while let Some(state_changed) = stream.next().await {
if let Ok(state) = state_changed.get().await {
// the device failed to connect to the requested network and is cleaning up the connection request
if state == 120 {
if Self::get().connected_network.get().is_some() {
Self::forget_saved_network(
(*Self::get().connected_network.get()).clone().unwrap().name,
)
}
}
}
}
});
}

pub fn start_streaming() {
if *WirelessModel::get().is_streaming.get() {
return;
Expand All @@ -560,6 +584,7 @@ impl WirelessModel {
Self::stream_wireless_enabled_status();
Self::stream_connection();
Self::stream_wifi_status();
Self::stream_device_state();
Self::stream_scan_result();
Self::stream_known_networks();
}
Expand Down
16 changes: 10 additions & 6 deletions apps/settings-app/src/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::constants::{
ABOUT_ICON, ADD_ICON, APPEARANCE_ICON, BACKGROUND_IMAGE, BACK_ICON, BASE_SETTINGS_PATH,
BATTERY_ICON, BLUETOOTH_ICON, CONFIRM_ICON, CONNECTED_ICON, DATE_TIME_ICON, DELETE_ICON,
DEVICE_ICON, DISPLAY_ICON, GREY_RIGHT_ARROW, HOME_DIR_CONFIG_PATH, INFO_ICON, LANGUAGE_ICON,
LOCK_ICON, SECURED_WIRELESS_ERROR, SECURED_WIRELESS_LOW, SECURED_WIRELESS_OFF,
SECURED_WIRELESS_ON, SECURED_WIRELESS_STRONG, SECURED_WIRELESS_WEAK, SOUND_ICON, UPDATE_ICON,
USR_SHARE_PATH, WHITE_RIGHT_ARROW, WIRELESS_ERROR, WIRELESS_GOOD, WIRELESS_LOW,
WIRELESS_NOT_FOUND, WIRELESS_OFF, WIRELESS_ON, WIRELESS_SETTIGNS, WIRELESS_STRONG,
WIRELESS_WEAK,
DEVICE_ICON, DISABLE_CONFIRM_ICON, DISPLAY_ICON, ENABLE_CONFIRM_ICON, GREY_RIGHT_ARROW,
HOME_DIR_CONFIG_PATH, INFO_ICON, LANGUAGE_ICON, LOCK_ICON, SECURED_WIRELESS_ERROR,
SECURED_WIRELESS_LOW, SECURED_WIRELESS_OFF, SECURED_WIRELESS_ON, SECURED_WIRELESS_STRONG,
SECURED_WIRELESS_WEAK, SOUND_ICON, UPDATE_ICON, USR_SHARE_PATH, WHITE_RIGHT_ARROW,
WIRELESS_ERROR, WIRELESS_GOOD, WIRELESS_LOW, WIRELESS_NOT_FOUND, WIRELESS_OFF, WIRELESS_ON,
WIRELESS_SETTIGNS, WIRELESS_STRONG, WIRELESS_WEAK,
};
use crate::errors::{SettingsAppError, SettingsAppErrorCodes};
use anyhow::bail;
Expand Down Expand Up @@ -455,6 +455,8 @@ impl Default for SeeOptions {
pub struct Footer {
pub back_icon: String,
pub confirm_icon: String,
pub enable_confirm_icon: String,
pub disable_confirm_icon: String,
pub delete_icon: String,
pub add_icon: String,
}
Expand All @@ -463,6 +465,8 @@ impl Default for Footer {
Footer {
back_icon: BACK_ICON.to_owned(),
confirm_icon: CONFIRM_ICON.to_owned(),
enable_confirm_icon: ENABLE_CONFIRM_ICON.to_owned(),
disable_confirm_icon: DISABLE_CONFIRM_ICON.to_owned(),
delete_icon: ADD_ICON.to_owned(),
add_icon: DELETE_ICON.to_owned(),
}
Expand Down

0 comments on commit 3097254

Please sign in to comment.