allow UNSET country code for wifi (#2442)

This commit is contained in:
Aiden McClelland
2023-10-05 16:14:51 -06:00
committed by GitHub
parent f12b7f4319
commit 68c29ab99e

View File

@@ -174,7 +174,7 @@ pub async fn delete(#[context] ctx: RpcContext, #[arg] ssid: String) -> Result<(
pub struct WiFiInfo { pub struct WiFiInfo {
ssids: HashMap<Ssid, SignalStrength>, ssids: HashMap<Ssid, SignalStrength>,
connected: Option<Ssid>, connected: Option<Ssid>,
country: CountryCode, country: Option<CountryCode>,
ethernet: bool, ethernet: bool,
available_wifi: Vec<WifiListOut>, available_wifi: Vec<WifiListOut>,
} }
@@ -216,7 +216,7 @@ fn display_wifi_info(info: WiFiInfo, matches: &ArgMatches) {
.as_ref() .as_ref()
.and_then(|x| info.ssids.get(x)) .and_then(|x| info.ssids.get(x))
.map_or("[N/A]".to_owned(), |ss| format!("{}", ss.0)), .map_or("[N/A]".to_owned(), |ss| format!("{}", ss.0)),
&info.country.alpha2(), info.country.as_ref().map(|c| c.alpha2()).unwrap_or("00"),
&format!("{}", info.ethernet) &format!("{}", info.ethernet)
]); ]);
table_global.print_tty(false).unwrap(); table_global.print_tty(false).unwrap();
@@ -517,7 +517,7 @@ impl WpaCli {
Ok(()) Ok(())
} }
pub async fn get_country_low(&self) -> Result<CountryCode, Error> { pub async fn get_country_low(&self) -> Result<Option<CountryCode>, Error> {
let r = Command::new("iw") let r = Command::new("iw")
.arg("reg") .arg("reg")
.arg("get") .arg("get")
@@ -539,12 +539,16 @@ impl WpaCli {
ErrorKind::Wifi, ErrorKind::Wifi,
) )
})?[1]; })?[1];
Ok(CountryCode::for_alpha2(country).map_err(|_| { if country == "00" {
Error::new( Ok(None)
color_eyre::eyre::eyre!("Invalid Country Code: {}", country), } else {
ErrorKind::Wifi, Ok(Some(CountryCode::for_alpha2(country).map_err(|_| {
) Error::new(
})?) color_eyre::eyre::eyre!("Invalid Country Code: {}", country),
ErrorKind::Wifi,
)
})?))
}
} }
pub async fn remove_network_low(&mut self, id: NetworkId) -> Result<(), Error> { pub async fn remove_network_low(&mut self, id: NetworkId) -> Result<(), Error> {
let _ = Command::new("nmcli") let _ = Command::new("nmcli")
@@ -634,7 +638,7 @@ impl WpaCli {
Ok(()) Ok(())
} }
pub async fn save_config(&mut self, db: PatchDb) -> Result<(), Error> { pub async fn save_config(&mut self, db: PatchDb) -> Result<(), Error> {
let new_country = Some(self.get_country_low().await?); let new_country = self.get_country_low().await?;
db.mutate(|d| { db.mutate(|d| {
d.as_server_info_mut() d.as_server_info_mut()
.as_last_wifi_region_mut() .as_last_wifi_region_mut()