Skip to content

Commit

Permalink
Add xochitl support
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusCDE committed Aug 3, 2020
1 parent a8b6ee0 commit 5e27920
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub struct Context {
pub covered: bool,
pub shared: bool,
pub online: bool,
pub killed_xochitl: bool,
}

impl Context {
Expand All @@ -94,7 +95,7 @@ impl Context {
keyboard_layouts: BTreeMap::new(), input_history: FxHashMap::default(),
battery, frontlight, lightsensor, notification_index: 0,
kb_rect: Rectangle::default(), rng, plugged: false, covered: false,
shared: false, online: false }
shared: false, online: false, killed_xochitl: false }
}

pub fn batch_import(&mut self) {
Expand Down Expand Up @@ -335,6 +336,7 @@ fn set_wifi(enable: bool, context: &mut Context) {

enum ExitStatus {
Quit,
QuitToXochitl,
Reboot,
PowerOff,
}
Expand Down Expand Up @@ -435,6 +437,14 @@ pub fn run() -> Result<(), Error> {
schedule_task(TaskId::CheckBattery, Event::CheckBattery,
BATTERY_REFRESH_INTERVAL, &tx, &mut tasks);

if let Ok(status) = Command::new("pidof").arg("xochitl").status() {
if status.code().unwrap() == 0 {
Command::new("systemctl").arg("stop").arg("xochitl").status().ok();
context.killed_xochitl = true;
println!("Xochitl was found and killed. You may only exit by starting Xochitl again.")
}
}

while let Ok(evt) = rx.recv() {
match evt {
Event::Device(de) => {
Expand Down Expand Up @@ -1047,6 +1057,10 @@ pub fn run() -> Result<(), Error> {
Event::Select(EntryId::Quit) => {
break;
},
Event::Select(EntryId::QuitToXochitl) => {
exit_status = ExitStatus::QuitToXochitl;
break;
},
Event::Select(EntryId::RebootInNickel) => {
fs::remove_file("bootlock").map_err(|e| {
eprintln!("Couldn't remove the bootlock file: {}", e);
Expand Down Expand Up @@ -1101,6 +1115,10 @@ pub fn run() -> Result<(), Error> {
Command::new("sync").status().ok();
Command::new("poweroff").arg("-f").status().ok();
},
ExitStatus::QuitToXochitl => {
Command::new("sync").status().ok();
Command::new("systemctl").arg("start").arg("xochitl").status().ok();
},
_ => (),
}

Expand Down
5 changes: 4 additions & 1 deletion src/view/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ pub fn toggle_main_menu(view: &mut dyn View, rect: Rectangle, enable: Option<boo
entries.push(EntryKind::Command("Reboot".to_string(), EntryId::Reboot));
} else {
entries.push(EntryKind::Command("Reboot".to_string(), EntryId::Reboot));
entries.push(EntryKind::Command("Quit".to_string(), EntryId::Quit));
if ! context.killed_xochitl {
entries.push(EntryKind::Command("Quit".to_string(), EntryId::Quit));
}
entries.push(EntryKind::Command("Quit to Xochitl".to_string(), EntryId::QuitToXochitl));
}

if CURRENT_DEVICE.has_page_turn_buttons() {
Expand Down
1 change: 1 addition & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ pub enum EntryId {
Reboot,
RebootInNickel,
Quit,
QuitToXochitl,
}

impl EntryKind {
Expand Down

0 comments on commit 5e27920

Please sign in to comment.