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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
|
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]]
|
[[package]]
|
||||||
name = "bit-set"
|
name = "bit-set"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -125,6 +134,12 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "numtoa"
|
name = "numtoa"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@@ -182,6 +197,7 @@ dependencies = [
|
|||||||
name = "rog-lib"
|
name = "rog-lib"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
"gumdrop",
|
"gumdrop",
|
||||||
"rusb",
|
"rusb",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ serde = "1.0"
|
|||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
toml = "0.5"
|
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 crate::{aura::BuiltInModeByte, config::Config, error::AuraError, laptops::*};
|
||||||
|
use aho_corasick::AhoCorasick;
|
||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use rusb::{DeviceHandle, Error};
|
use rusb::{DeviceHandle, Error};
|
||||||
use std::cell::{Ref, RefCell};
|
use std::cell::{Ref, RefCell};
|
||||||
|
use std::process::Command;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use sysfs_class::Brightness;
|
use sysfs_class::Brightness;
|
||||||
@@ -184,6 +186,27 @@ impl RogCore {
|
|||||||
}
|
}
|
||||||
Ok(None)
|
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 {
|
pub struct Backlight {
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ impl Laptop for LaptopGX502GW {
|
|||||||
self.backlight.step_down();
|
self.backlight.step_down();
|
||||||
}
|
}
|
||||||
GX502GWKeys::Sleep => {
|
GX502GWKeys::Sleep => {
|
||||||
std::process::Command::new("systemctl")
|
rogcore.suspend();
|
||||||
.arg("suspend")
|
}
|
||||||
.spawn()
|
GX502GWKeys::AirplaneMode => {
|
||||||
.expect("failed to suspend");
|
rogcore.toggle_airplane_mode();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if key_byte != 0 {
|
if key_byte != 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user