Add airplane mode toggle

This commit is contained in:
Luke
2020-04-18 14:12:53 +12:00
parent fb02604dc6
commit ed74ca3d58
4 changed files with 45 additions and 5 deletions

View File

@@ -10,4 +10,5 @@ gumdrop = "0.8"
serde = "1.0"
serde_derive = "1.0"
toml = "0.5"
sysfs-class = "0.1.2"
sysfs-class = "0.1.2"
aho-corasick = "0.7"

View File

@@ -1,7 +1,9 @@
use crate::{aura::BuiltInModeByte, config::Config, error::AuraError, laptops::*};
use aho_corasick::AhoCorasick;
use gumdrop::Options;
use rusb::{DeviceHandle, Error};
use std::cell::{Ref, RefCell};
use std::process::Command;
use std::str::FromStr;
use std::time::Duration;
use sysfs_class::Brightness;
@@ -184,6 +186,27 @@ impl RogCore {
}
Ok(None)
}
pub fn suspend(&self) {
std::process::Command::new("systemctl")
.arg("suspend")
.spawn()
.expect("failed to suspend");
}
pub fn toggle_airplane_mode(&self) {
if let Ok(output) = Command::new("rfkill").arg("list").output() {
if output.status.success() {
let patterns = &["yes"];
let ac = AhoCorasick::new(patterns);
if ac.earliest_find(output.stdout).is_some() {
Command::new("rfkill").arg("unblock").arg("all").spawn();
} else {
Command::new("rfkill").arg("block").arg("all").spawn();
}
}
}
}
}
pub struct Backlight {

View File

@@ -115,10 +115,10 @@ impl Laptop for LaptopGX502GW {
self.backlight.step_down();
}
GX502GWKeys::Sleep => {
std::process::Command::new("systemctl")
.arg("suspend")
.spawn()
.expect("failed to suspend");
rogcore.suspend();
}
GX502GWKeys::AirplaneMode => {
rogcore.toggle_airplane_mode();
}
_ => {
if key_byte != 0 {