Refactor(Project): Change Project Structure

This commit is contained in:
Tochukwu Nkemdilim
2018-07-19 16:14:34 +01:00
parent e8b83bf245
commit 65c641670d
17 changed files with 268 additions and 250 deletions
+52 -3
View File
@@ -1,7 +1,56 @@
use std::collections::HashMap;
use platforms::{WifiError, WifiInterface};
use std::process::Command;
#[derive(Debug)]
pub struct Connection {
pub(crate) ssid: String,
}
#[derive(Debug)]
pub struct Osx {
hotspot: Option<HashMap>,
connectivity: Option<HashMap>,
pub(crate) connection: Option<Connection>,
pub(crate) interface: String,
}
impl Osx {
pub fn new(name: &str, config: Option<Config>) -> Self {
Osx {
connection: None,
interface: config.map_or("en0".to_string(), |cfg| {
cfg.interface.unwrap_or("en0").to_string()
}),
}
}
}
impl WifiInterface for Osx {
fn is_wifi_enabled() -> Result<bool, WifiError> {
let output = Command::new("networksetup")
.args(&["radio", "wifi"])
.output()
.map_err(|err| WifiError::IoError(err))?;
Ok(String::from_utf8_lossy(&output.stdout)
.replace(" ", "")
.replace("\n", "")
.contains("enabled"))
}
fn turn_on() -> Result<(), WifiError> {
let output = Command::new("networksetup")
.args(&["-setairportpower", "en0", "on"])
.output()
.map_err(|err| WifiError::IoError(err))?;
Ok(())
}
fn turn_off() -> Result<(), WifiError> {
let output = Command::new("networksetup")
.args(&["-setairportpower", "en0", "off"])
.output()
.map_err(|err| WifiError::IoError(err))?;
Ok(())
}
}