Skip to content

Disconnect#23

Merged
vimlinuz merged 8 commits intomainfrom
disconnect
Dec 31, 2025
Merged

Disconnect#23
vimlinuz merged 8 commits intomainfrom
disconnect

Conversation

@vimlinuz
Copy link
Copy Markdown
Owner

@vimlinuz vimlinuz commented Dec 31, 2025

Summary by CodeRabbit

  • New Features
    • Press 'x' to disconnect the currently active Wi‑Fi connection.
    • Shows a status popup with success/failure details after a disconnect attempt.
    • Automatically rescans available networks after attempting to disconnect.
    • Provides clear feedback when no active connection is found or when the disconnect command fails.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 31, 2025

Warning

Rate limit exceeded

@santoshxshrestha has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2e84ecb and 792e6ad.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/apps/core.rs
  • src/apps/core/event_handlers.rs
  • src/utils/disconnect_connection.rs
📝 Walkthrough

Walkthrough

Pressing 'x' triggers a disconnect flow: the event handler calls disconnect_connected_network(...), which locks the mutex-protected WiFi list, locates an active network, runs nmcli to bring the connection down, and returns a Status; the handler shows a status popup and rescans networks.

Changes

Cohort / File(s) Summary
WiFi Disconnect Feature
src/apps/core/event_handlers.rs, src/utils.rs, src/utils/disconnect_connection.rs
Adds KeyCode::Char('x') handling that calls disconnect_connected_network(self.wifi_list.clone()), sets wifi_credentials.status and wifi_credentials.flags.show_status_popup = true, and calls scan_networks(...). Introduces pub fn disconnect_connected_network(Arc<Mutex<Vec<WifiNetwork>>>) -> Status which locks the WiFi list, finds an active network, executes nmcli to disconnect, and returns a Status with stdout/stderr and exit status or a "No connection found" message.

Sequence Diagram

sequenceDiagram
    autonumber
    participant User
    participant EventHandler as Event Handler
    participant Utils as disconnect_connected_network()
    participant WifiList as WiFi List\n(Arc<Mutex<Vec<WifiNetwork>>>)
    participant Nmcli as nmcli (system)
    participant Status as Status

    User->>EventHandler: press 'x'
    EventHandler->>Utils: disconnect_connected_network(wifi_list.clone())
    Utils->>WifiList: lock & iterate networks
    alt active network found
        Utils->>Nmcli: execute disconnect command
        Nmcli-->>Utils: exit code + stdout/stderr
        Utils->>Status: build Status (stdout/stderr + exit status)
    else no active network
        Utils->>Status: build Status("No connection found")
    end
    Utils-->>EventHandler: return Status
    EventHandler->>EventHandler: set wifi_credentials.status, show_status_popup = true
    EventHandler->>EventHandler: scan_networks(wifi_list.clone())
    EventHandler-->>User: display status popup
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I tapped the key and nudged the net,

Clutched mutex threads in a tiny fret,
I whispered to nmcli, "let go, be free",
Returned a status — quiet as tea,
Now scans resume — hop, hop, glee.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Disconnect' is vague and generic, failing to convey specific details about what is being disconnected or the nature of the implementation. Consider a more descriptive title such as 'Add WiFi network disconnect functionality' or 'Implement disconnect_connected_network function' to clarify the scope and intent.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6e0d51 and db184cb.

📒 Files selected for processing (3)
  • src/apps/core/event_handlers.rs
  • src/utils.rs
  • src/utils/disconnect_connection.rs
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: santoshxshrestha
Repo: santoshxshrestha/nmtui PR: 0
File: :0-0
Timestamp: 2025-12-29T17:44:05.883Z
Learning: In the santoshxshrestha/nmtui project, input field handlers (SSID and password handlers in src/apps/handlers/ssid_handler.rs and src/apps/handlers/password_handler.rs) intentionally do not include Ctrl+C or global help handlers to avoid the performance overhead of sharing app state and additional polling that would make the program laggy.
📚 Learning: 2025-12-29T17:44:05.883Z
Learnt from: santoshxshrestha
Repo: santoshxshrestha/nmtui PR: 0
File: :0-0
Timestamp: 2025-12-29T17:44:05.883Z
Learning: In the santoshxshrestha/nmtui project, input field handlers (SSID and password handlers in src/apps/handlers/ssid_handler.rs and src/apps/handlers/password_handler.rs) intentionally do not include Ctrl+C or global help handlers to avoid the performance overhead of sharing app state and additional polling that would make the program laggy.

Applied to files:

  • src/apps/core/event_handlers.rs
🧬 Code graph analysis (2)
src/utils/disconnect_connection.rs (1)
src/apps/handlers/status.rs (1)
  • new (23-28)
src/apps/core/event_handlers.rs (1)
src/utils/disconnect_connection.rs (1)
  • disconnect_connected_network (7-37)
🪛 GitHub Actions: Rust
src/utils/disconnect_connection.rs

[error] 36-36: unneeded return statement. Replace with Status::new(format!("No connection found"), ExitStatus::default())


[error] 36-36: useless use of format!. Consider using .to_string() instead: Status::new("No connection found".to_string(), ExitStatus::default())

🔇 Additional comments (3)
src/utils.rs (1)

3-3: LGTM!

The module declaration follows the existing pattern and integrates cleanly with the other utility modules.

src/apps/core/event_handlers.rs (1)

2-2: LGTM!

The import is correctly structured and follows Rust conventions.

src/utils/disconnect_connection.rs (1)

1-5: LGTM!

All imports are necessary and correctly structured.

Comment on lines +7 to +8
pub fn disconnect_connected_network(wifi_list: Arc<Mutex<Vec<WifiNetwork>>>) -> Status {
let list = wifi_list.lock().unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle potential mutex poisoning error.

Using .unwrap() on lock() will panic if the mutex is poisoned (i.e., a thread panicked while holding the lock). This can cause unexpected crashes.

🔎 Suggested fix to handle poisoned mutex
 pub fn disconnect_connected_network(wifi_list: Arc<Mutex<Vec<WifiNetwork>>>) -> Status {
-    let list = wifi_list.lock().unwrap();
+    let list = match wifi_list.lock() {
+        Ok(guard) => guard,
+        Err(poisoned) => poisoned.into_inner(), // or return an error Status
+    };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn disconnect_connected_network(wifi_list: Arc<Mutex<Vec<WifiNetwork>>>) -> Status {
let list = wifi_list.lock().unwrap();
pub fn disconnect_connected_network(wifi_list: Arc<Mutex<Vec<WifiNetwork>>>) -> Status {
let list = match wifi_list.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner(), // or return an error Status
};
🤖 Prompt for AI Agents
In src/utils/disconnect_connection.rs around lines 7-8, avoid calling .unwrap()
on wifi_list.lock() which will panic on a poisoned mutex; instead handle the
Result from lock(): either recover the inner data with
lock().unwrap_or_else(|poisoned| poisoned.into_inner()) if safe to continue, or
match on Err and return a proper Status::internal with a clear message (and
optional logging) so the function returns an error instead of panicking.

Comment on lines +10 to +33
for network in list.iter() {
if network.in_use {
let ssid = &network.ssid;
let output = Command::new("nmtui")
.args(["connection", "down", ssid])
.output();
match output {
Ok(output) => {
let status = output.status;
if status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
return Status::new(stdout.into(), status);
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
return Status::new(stderr.into(), status);
}
}
Err(e) => {
return Status::new(
format!("Failed to execute nmcli: {}", e),
ExitStatus::default(),
);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Use nmcli instead of nmtui and fix the inconsistent error message.

There are two critical issues:

  1. Wrong command tool: Line 13 uses nmtui (NetworkManager Text User Interface), which is an interactive TUI tool not designed for programmatic use. The correct tool for scripting is nmcli (NetworkManager Command Line Interface).

  2. Inconsistent error message: Line 29 mentions "nmcli" in the error message, but the actual command being executed is "nmtui". This is confusing.

🔎 Proposed fix to use the correct command and fix error message
     for network in list.iter() {
         if network.in_use {
             let ssid = &network.ssid;
-            let output = Command::new("nmtui")
+            let output = Command::new("nmcli")
                 .args(["connection", "down", ssid])
                 .output();
             match output {
                 Ok(output) => {
                     let status = output.status;
                     if status.success() {
                         let stdout = String::from_utf8_lossy(&output.stdout);
                         return Status::new(stdout.into(), status);
                     } else {
                         let stderr = String::from_utf8_lossy(&output.stderr);
                         return Status::new(stderr.into(), status);
                     }
                 }
                 Err(e) => {
                     return Status::new(
                         format!("Failed to execute nmcli: {}", e),
                         ExitStatus::default(),
                     );
                 }
             }
         }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for network in list.iter() {
if network.in_use {
let ssid = &network.ssid;
let output = Command::new("nmtui")
.args(["connection", "down", ssid])
.output();
match output {
Ok(output) => {
let status = output.status;
if status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
return Status::new(stdout.into(), status);
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
return Status::new(stderr.into(), status);
}
}
Err(e) => {
return Status::new(
format!("Failed to execute nmcli: {}", e),
ExitStatus::default(),
);
}
}
for network in list.iter() {
if network.in_use {
let ssid = &network.ssid;
let output = Command::new("nmcli")
.args(["connection", "down", ssid])
.output();
match output {
Ok(output) => {
let status = output.status;
if status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
return Status::new(stdout.into(), status);
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
return Status::new(stderr.into(), status);
}
}
Err(e) => {
return Status::new(
format!("Failed to execute nmcli: {}", e),
ExitStatus::default(),
);
}
}
}
}
🤖 Prompt for AI Agents
In src/utils/disconnect_connection.rs around lines 10 to 33, the code invokes
the interactive tool "nmtui" instead of the programmatic "nmcli" and the error
message incorrectly mentions "nmcli" while executing "nmtui"; change
Command::new("nmtui") to Command::new("nmcli") so the script uses the proper
CLI, and update the Err branch error message to accurately reflect the executed
command (include "nmcli" and the SSID/connection name in the formatted error) so
logging consistently matches the actual command run.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db184cb and fd862d8.

📒 Files selected for processing (2)
  • src/apps/core/event_handlers.rs
  • src/utils/disconnect_connection.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils/disconnect_connection.rs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-29T17:44:05.883Z
Learnt from: santoshxshrestha
Repo: santoshxshrestha/nmtui PR: 0
File: :0-0
Timestamp: 2025-12-29T17:44:05.883Z
Learning: In the santoshxshrestha/nmtui project, input field handlers (SSID and password handlers in src/apps/handlers/ssid_handler.rs and src/apps/handlers/password_handler.rs) intentionally do not include Ctrl+C or global help handlers to avoid the performance overhead of sharing app state and additional polling that would make the program laggy.

Applied to files:

  • src/apps/core/event_handlers.rs
🧬 Code graph analysis (1)
src/apps/core/event_handlers.rs (1)
src/utils/disconnect_connection.rs (1)
  • disconnect_connected_network (7-37)
🔇 Additional comments (2)
src/apps/core/event_handlers.rs (2)

2-2: LGTM: Import is correctly added.

The import statement is properly formatted and necessary for the new disconnect functionality.


109-117: Good implementation of status capture and user feedback.

The handler correctly captures the Status return value and displays it via popup, addressing the previous review concern. The implementation follows the same pattern as other key handlers in the file.

@vimlinuz vimlinuz merged commit 9abf617 into main Dec 31, 2025
3 checks passed
@vimlinuz vimlinuz deleted the disconnect branch December 31, 2025 18:15
@coderabbitai coderabbitai bot mentioned this pull request Jan 3, 2026
@coderabbitai coderabbitai bot mentioned this pull request Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant