Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, dev ]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -241,4 +241,4 @@ jobs:
~/.cargo/git
key: ${{ runner.os }}-audit-${{ hashFiles('**/Cargo.lock') }}
- run: cargo install cargo-audit
- run: cargo audit
- run: cargo audit
2 changes: 1 addition & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request:
branches: [ master ]
push:
branches: [ master ]
branches: [ master, dev ]

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ nmrs/*.tar.gz.*
RELEASE_NOTES.md
__pycache__/
*.pyc
vendor/

121 changes: 121 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 41 additions & 41 deletions nmrs-core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,13 @@ pub(crate) async fn connect(conn: &Connection, ssid: &str, creds: WifiSecurity)

if use_saved_connection {
if let Some(active) = current_ssid(conn).await {
eprintln!("Disconnecting from {active}.");
eprintln!("Disconnecting from {active}");
if let Ok(conns) = nm.active_connections().await {
for conn_path in conns {
eprintln!("Deactivating connection: {conn_path}");
let _ = nm.deactivate_connection(conn_path).await;
}
}

for i in 0..retries::DISCONNECT_MAX_RETRIES {
let d = NMDeviceProxy::builder(conn)
.path(wifi_device.clone())?
.build()
.await?;
let state = DeviceState::from(d.state().await?);
eprintln!("Loop {i}: Device state = {state:?}");

if state == DeviceState::Disconnected || state == DeviceState::Unavailable {
eprintln!("Device disconnected");
break;
}

Delay::new(timeouts::disconnect_poll_interval()).await;
}

Delay::new(timeouts::disconnect_final_delay()).await;
eprintln!("Disconnect complete");
disconnect_wifi_device(conn, &wifi_device).await?
}

let conn_path = saved_conn_path.unwrap();
Expand Down Expand Up @@ -253,29 +234,10 @@ pub(crate) async fn connect(conn: &Connection, ssid: &str, creds: WifiSecurity)
eprintln!("Disconnecting from {active}.");
if let Ok(conns) = nm.active_connections().await {
for conn_path in conns {
eprintln!("Deactivating connection: {conn_path}");
let _ = nm.deactivate_connection(conn_path).await;
}
}

for i in 0..retries::DISCONNECT_MAX_RETRIES {
let d = NMDeviceProxy::builder(conn)
.path(wifi_device.clone())?
.build()
.await?;
let state = DeviceState::from(d.state().await?);
eprintln!("Loop {i}: Device state = {state:?}");

if state == DeviceState::Disconnected || state == DeviceState::Unavailable {
eprintln!("Device disconnected");
break;
}

Delay::new(timeouts::disconnect_poll_interval()).await;
}

Delay::new(timeouts::disconnect_final_delay()).await;
eprintln!("Disconnect complete");
disconnect_wifi_device(conn, &wifi_device).await?;
}

match nm
Expand Down Expand Up @@ -580,3 +542,41 @@ pub(crate) async fn forget(conn: &Connection, ssid: &str) -> zbus::Result<()> {
)))
}
}

pub(crate) async fn disconnect_wifi_device(
conn: &Connection,
dev_path: &OwnedObjectPath,
) -> Result<()> {
let dev = NMDeviceProxy::builder(conn)
.path(dev_path.clone())?
.build()
.await?;

let raw: zbus::proxy::Proxy = zbus::proxy::Builder::new(conn)
.destination("org.freedesktop.NetworkManager")?
.path(dev_path.clone())?
.interface("org.freedesktop.NetworkManager.Device")?
.build()
.await?;

let _ = raw.call_method("Disconnect", &()).await;

for _ in 0..retries::DISCONNECT_MAX_RETRIES {
Delay::new(timeouts::disconnect_poll_interval()).await;
match dev.state().await {
Ok(s) if s == device_state::DISCONNECTED || s == device_state::UNAVAILABLE => {
break;
}
Ok(_) => continue,
Err(e) => return Err(e),
}
}

Delay::new(timeouts::disconnect_final_delay()).await;

match dev.state().await {
Ok(s) if s == device_state::DISCONNECTED || s == device_state::UNAVAILABLE => Ok(()),
Ok(s) => Err(zbus::Error::Failure(format!("device stuck in state {s}"))),
Err(e) => Err(e),
}
}
3 changes: 2 additions & 1 deletion nmrs-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ gtk = { version = "0.10.1", package = "gtk4" }
glib = "0.21.3"
dirs = "6.0.0"
fs2 = "0.4.3"
anyhow = "1.0.100"
anyhow = "1.0.100"
clap = { version = "4.5.53", features = ["derive"] }
19 changes: 19 additions & 0 deletions nmrs-ui/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::process::Command;

fn main() {
let output = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output();

let hash = match output {
Ok(output) if output.status.success() => {
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
_ => {
println!("cargo:warning=Unable to determine git hash, using 'unknown'");
String::from("unknown")
}
};

println!("cargo:rustc-env=GIT_HASH={}", hash);
}
22 changes: 22 additions & 0 deletions nmrs-ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
pub mod file_lock;
pub mod objects;
pub mod style;
pub mod theme_config;
pub mod ui;

use clap::{ArgAction, Parser};
use gtk::Application;
use gtk::prelude::*;

use crate::file_lock::acquire_app_lock;
use crate::style::load_css;
use crate::ui::build_ui;

#[derive(Parser, Debug)]
#[command(name = "nmrs")]
#[command(disable_version_flag = true)]
#[command(version)]
struct Args {
#[arg(short = 'V', long = "version", action = ArgAction::SetTrue)]
version: bool,
}

pub fn run() -> anyhow::Result<()> {
let args = Args::parse();

if let Args { version: true } = args {
println!(
"nmrs {}-beta ({})",
env!("CARGO_PKG_VERSION"),
env!("GIT_HASH")
);
return Ok(());
}

let app = Application::builder()
.application_id("org.netrs.ui")
.build();
Expand Down
1 change: 1 addition & 0 deletions nmrs-ui/src/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod theme;
Loading
Loading