diff --git a/scripts/essid.sh b/scripts/essid.sh new file mode 100755 index 0000000..71b7763 --- /dev/null +++ b/scripts/essid.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +iwgetid -r diff --git a/scripts/ip.sh b/scripts/ip.sh new file mode 100755 index 0000000..7c80aeb --- /dev/null +++ b/scripts/ip.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +ip route get 1 | awk '{print $NF; exit}' diff --git a/src/app.rs b/src/app.rs index b0dd555..0fde040 100644 --- a/src/app.rs +++ b/src/app.rs @@ -24,6 +24,7 @@ use view::home::Home; use view::reader::Reader; use view::confirmation::Confirmation; use view::intermission::Intermission; +use view::notification::Notification; use device::CURRENT_DEVICE; use font::Fonts; use errors::*; @@ -39,6 +40,7 @@ pub struct Context { pub fonts: Fonts, pub frontlight: Box, pub battery: Box, + pub notification_index: u8, pub inverted: bool, pub monochrome: bool, pub suspended: bool, @@ -50,7 +52,7 @@ impl Context { pub fn new(settings: Settings, metadata: Metadata, fonts: Fonts, frontlight: Box, battery: Box) -> Context { Context { settings, metadata, fonts, frontlight, battery, - inverted: false, monochrome: false, + notification_index: 0, inverted: false, monochrome: false, suspended: false, plugged: false, mounted: false } } @@ -195,6 +197,20 @@ pub fn run() -> Result<()> { view.children_mut().push(Box::new(interm) as Box); } }, + DeviceEvent::NetUp => { + let ip = Command::new("scripts/ip.sh").output() + .map(|o| String::from_utf8_lossy(&o.stdout).trim_right().to_string()) + .unwrap_or_default(); + let essid = Command::new("scripts/essid.sh").output() + .map(|o| String::from_utf8_lossy(&o.stdout).trim_right().to_string()) + .unwrap_or_default(); + let notif = Notification::new(ViewId::NetUpNotif, + format!("Network is up ({}, {}).", ip, essid), + &mut context.notification_index, + &mut context.fonts, + &tx); + view.children_mut().push(Box::new(notif) as Box); + }, DeviceEvent::Plug => { if context.plugged { continue; @@ -411,7 +427,17 @@ pub fn run() -> Result<()> { } }, Event::Select(EntryId::TakeScreenshot) => { - fb.save(&Local::now().format("screenshot-%Y%m%d_%H%M%S.png").to_string())?; + let name = Local::now().format("screenshot-%Y%m%d_%H%M%S.png"); + let msg = match fb.save(&name.to_string()) { + Err(e) => format!("Couldn't take screenshot: {}).", e), + Ok(_) => format!("Saved {}.", name), + }; + let notif = Notification::new(ViewId::TakeScreenshotNotif, + msg, + &mut context.notification_index, + &mut context.fonts, + &tx); + view.children_mut().push(Box::new(notif) as Box); }, Event::Select(EntryId::Reboot) | Event::Select(EntryId::Quit) => { break; diff --git a/src/view/mod.rs b/src/view/mod.rs index 968f05d..a53e0e1 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -19,6 +19,7 @@ pub mod input_field; pub mod page_label; pub mod go_to_page; pub mod confirmation; +pub mod notification; pub mod intermission; pub mod frontlight; pub mod menu; @@ -237,6 +238,8 @@ pub enum ViewId { MarginCropper, TopBottomBars, TableOfContents, + TakeScreenshotNotif, + NetUpNotif, } #[derive(Debug, Copy, Clone, Eq, PartialEq)]