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:
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -6,6 +6,15 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.5.1"
|
||||
@@ -125,6 +134,12 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||
|
||||
[[package]]
|
||||
name = "numtoa"
|
||||
version = "0.2.3"
|
||||
@@ -182,6 +197,7 @@ dependencies = [
|
||||
name = "rog-lib"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"gumdrop",
|
||||
"rusb",
|
||||
"serde",
|
||||
|
||||
@@ -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