forge
Explore
Log in

Don't you dare go Hollow

wifi_lab

Clone
★ 0

0 watching0 forksRust2.1 MiBb265998Tahinli1 month ago27 commits

mod.rs108 lines, 3.8 KiBHistoryRawDownload
1//! GPUI + gpuikit shell for wifi_lab.
2//!
3//! `run_app` opens the window and wires the service event channel: the mock
4//! generator in [`mock`] (mock mode) or the privileged-service reader thread
5//! feed the `Sender` side; the UI itself never needs root.
6
7mod app;
8mod attacks;
9mod cracker;
10mod log;
11pub(crate) mod mock;
12mod networks;
13pub mod state;
14
15use std::sync::Arc;
16
17use gpui::{
18 App, AppContext, Application, Bounds, TitlebarOptions, WindowBounds, WindowOptions, px, size,
19};
20use gpuikit::theme::{GlobalTheme, Theme};
21
22/// Launch the UI. Blocks until the window closes.
23///
24/// `mock_flag` is the CLI `--mock` switch; combined with the legacy
25/// `WIFI_LAB_MOCK` env var. The REAL service is the default: the
26/// [`crate::service::ServiceClient`] spawns lazily on the first
27/// "Start capture" click (polkit-elevated child process).
28pub fn run_app(iface: Option<String>, mock_flag: bool) {
29 let (tx, rx) = crossbeam_channel::unbounded();
30
31 // Mock mode: `--mock` flag or WIFI_LAB_MOCK=1 (any value except 0/false
32 // counts as 1 when set). Default (neither set) is real mode.
33 let env_mock = match std::env::var_os("WIFI_LAB_MOCK") {
34 None => false,
35 Some(v) => v != "0" && v != "false",
36 };
37 let is_mock = mock_flag || env_mock;
38 if is_mock {
39 mock::spawn_mock(tx.clone());
40 }
41
42 // Interface picker choices: every wireless interface present, with the
43 // CLI/default choice first (also the fallback when detection fails).
44 let mut ifaces: Vec<String> = crate::iface::list_wifi_ifaces();
45 if ifaces.is_empty() {
46 ifaces.push("wlp14s0".to_string());
47 }
48 let selected = match iface {
49 Some(cli) => {
50 if !ifaces.contains(&cli) {
51 ifaces.insert(0, cli.clone());
52 }
53 cli
54 }
55 None => ifaces[0].clone(),
56 };
57 if is_mock && !ifaces.iter().any(|i| i == mock::MOCK_IFACE) {
58 ifaces.push(mock::MOCK_IFACE.to_string());
59 }
60
61 Application::with_platform(gpui_platform::current_platform(false))
62 .with_assets(gpuikit::assets())
63 .run(move |cx: &mut App| {
64 gpuikit::init(cx);
65 cx.set_global(GlobalTheme(Arc::new(Theme::gruvbox_dark())));
66 // Window-level shortcuts: ctrl-q quit, ctrl-1..4 page switch.
67 app::bind_app_keys(cx);
68
69 let window = cx
70 .open_window(
71 WindowOptions {
72 titlebar: Some(TitlebarOptions {
73 title: Some("wifi_lab".into()),
74 ..Default::default()
75 }),
76 window_bounds: Some(WindowBounds::Windowed(Bounds {
77 origin: Default::default(),
78 size: size(px(1280.0), px(760.0)),
79 })),
80 ..Default::default()
81 },
82 {
83 let tx = tx.clone();
84 let mut rx = Some(rx);
85 move |window, cx| {
86 cx.new(|cx| {
87 app::AppRoot::new(
88 window,
89 cx,
90 tx,
91 rx.take().expect("single window"),
92 is_mock,
93 ifaces.clone(),
94 selected.clone(),
95 )
96 })
97 }
98 },
99 )
100 .expect("open main window");
101
102 window
103 .update(cx, |_app, _window, cx| {
104 cx.activate(true);
105 })
106 .expect("activate main window");
107 });
108}