File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,5 @@ pub mod adapter;
29
29
pub mod access_point;
30
30
31
31
pub mod cli;
32
+
33
+ pub mod rfkill;
Original file line number Diff line number Diff line change 1
1
use impala:: app:: { App , AppResult } ;
2
- use impala:: cli;
3
2
use impala:: config:: Config ;
4
3
use impala:: event:: { Event , EventHandler } ;
5
4
use impala:: handler:: handle_key_events;
6
5
use impala:: help:: Help ;
7
6
use impala:: tui:: Tui ;
7
+ use impala:: { cli, rfkill} ;
8
8
use iwdrs:: modes:: Mode ;
9
9
use ratatui:: backend:: CrosstermBackend ;
10
10
use ratatui:: Terminal ;
@@ -15,6 +15,8 @@ use std::sync::Arc;
15
15
async fn main ( ) -> AppResult < ( ) > {
16
16
let args = cli:: cli ( ) . get_matches ( ) ;
17
17
18
+ rfkill:: check ( ) ?;
19
+
18
20
let config = Arc :: new ( Config :: new ( ) ) ;
19
21
20
22
let help = Help :: new ( config. clone ( ) ) ;
Original file line number Diff line number Diff line change
1
+ use std:: fs;
2
+
3
+ use crate :: app:: AppResult ;
4
+
5
+ pub fn check ( ) -> AppResult < ( ) > {
6
+ let entries = fs:: read_dir ( "/sys/class/rfkill/" ) ?;
7
+
8
+ for entry in entries {
9
+ let entry = entry?;
10
+ let entry_path = entry. path ( ) ;
11
+
12
+ if let Some ( _file_name) = entry_path. file_name ( ) {
13
+ let name = fs:: read_to_string ( entry_path. join ( "type" ) ) ?;
14
+
15
+ if name. trim ( ) == "wlan" {
16
+ let state_path = entry_path. join ( "state" ) ;
17
+ let state = fs:: read_to_string ( state_path) ?. trim ( ) . parse :: < u8 > ( ) ?;
18
+
19
+ // https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-rfkill
20
+ match state {
21
+ 0 => {
22
+ eprintln ! (
23
+ r#"
24
+ The wifi device is soft blocked
25
+ Run the following command to unblock it
26
+ $ sudo rfkill unblock wlan
27
+ "#
28
+ ) ;
29
+ std:: process:: exit ( 1 ) ;
30
+ }
31
+ 2 => {
32
+ eprintln ! ( "The wifi device is hard blocked" ) ;
33
+ std:: process:: exit ( 1 ) ;
34
+ }
35
+ _ => { }
36
+ }
37
+ break ;
38
+ }
39
+ }
40
+ }
41
+ Ok ( ( ) )
42
+ }
You can’t perform that action at this time.
0 commit comments