mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add airplane mode toggle
This commit is contained in:
@@ -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"
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user