Skip to content

Commit

Permalink
fix(vpn): improve support for importing WireGuard configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Oct 23, 2024
1 parent 5ddc651 commit 828f181
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 66 deletions.
20 changes: 12 additions & 8 deletions cosmic-settings/src/pages/networking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod vpn;
pub mod wifi;
pub mod wired;

use std::{ffi::OsStr, io, process::ExitStatus, sync::Arc};
use std::{ffi::OsStr, process::Stdio, sync::Arc};

use anyhow::Context;
use cosmic::{widget, Apply, Command, Element};
Expand Down Expand Up @@ -354,29 +354,33 @@ impl Page {
}
}

async fn nm_add_vpn_file<P: AsRef<OsStr>>(type_: &str, path: P) -> io::Result<ExitStatus> {
async fn nm_add_vpn_file<P: AsRef<OsStr>>(type_: &str, path: P) -> Result<(), String> {
tokio::process::Command::new("nmcli")
.args(["connection", "import", "type", type_, "file"])
.arg(path)
.status()
.stderr(Stdio::piped())
.output()
.await
.apply(crate::utils::map_stderr_output)
}

async fn nm_add_wired() -> io::Result<ExitStatus> {
async fn nm_add_wired() -> Result<(), String> {
nm_connection_editor(&["--type=802-3-ethernet", "-c"]).await
}

async fn nm_add_wifi() -> io::Result<ExitStatus> {
async fn nm_add_wifi() -> Result<(), String> {
nm_connection_editor(&["--type=802-11-wireless", "-c"]).await
}

async fn nm_edit_connection(uuid: &str) -> io::Result<ExitStatus> {
async fn nm_edit_connection(uuid: &str) -> Result<(), String> {
nm_connection_editor(&[&["--edit=", uuid].concat()]).await
}

async fn nm_connection_editor(args: &[&str]) -> io::Result<ExitStatus> {
async fn nm_connection_editor(args: &[&str]) -> Result<(), String> {
tokio::process::Command::new(NM_CONNECTION_EDITOR)
.args(args)
.status()
.stderr(Stdio::piped())
.output()
.await
.apply(crate::utils::map_stderr_output)
}
Loading

0 comments on commit 828f181

Please sign in to comment.