modify wifi on boot to wifi kill switch

This commit is contained in:
bunnie 2022-11-23 06:00:59 +08:00
parent 22ccc5836e
commit 4fdbec310c
4 changed files with 21 additions and 9 deletions

View file

@ -44,7 +44,7 @@ impl From<DecodeError> for Error {
#[derive(prefsgenerator::GetterSetter)]
#[allow(dead_code)] // Allowing dead code here because UserPrefs is used to generate getter/setters.
pub struct UserPrefs {
pub radio_on_on_boot: bool,
pub wifi_kill: bool,
pub connect_known_networks_on_boot: bool,
pub autobacklight_on_boot: bool,
pub autobacklight_timeout: u64,

View file

@ -529,6 +529,13 @@
"ja": "現在の設定",
"zh": "当前设置"
},
"prefs.wifi_kill": {
"en": "WiFi kill switch",
"en-tts": "WiFi kill switch",
"fr": "Coupe-circuit WiFi *MT*",
"ja": "WiFiキルスイッチ",
"zh": "WiFi终止开关"
},
"prefs.yes": {
"en": "Yes",
"en-tts": "Yes",

View file

@ -388,7 +388,7 @@ fn wrapped_main() -> ! {
log::debug!("pddb ready, loading preferences now!");
match all_prefs.radio_on_on_boot {
match all_prefs.wifi_kill {
true => netmgr.connection_manager_wifi_off_and_stop(),
false => netmgr.connection_manager_wifi_on(),
}.unwrap_or_else(|error| {

View file

@ -13,7 +13,7 @@ pub trait PrefHandler {
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive, PartialEq, PartialOrd)]
enum DevicePrefsOp {
RadioOnOnBoot,
WifiKill,
ConnectKnownNetworksOnBoot,
AutobacklightOnBoot,
AutobacklightTimeout,
@ -44,7 +44,7 @@ impl Display for DevicePrefsOp {
Self::AutobacklightOnBoot => write!(f, "{}", t!("prefs.autobacklight_enable", xous::LANG)),
Self::AutobacklightTimeout => write!(f, "{}", t!("prefs.autobacklight_duration", xous::LANG)),
Self::ConnectKnownNetworksOnBoot => write!(f, "{}", t!("prefs.wifi_connect_auto", xous::LANG)),
Self::RadioOnOnBoot => write!(f, "{}", t!("prefs.wifi_kill", xous::LANG)),
Self::WifiKill => write!(f, "{}", t!("prefs.wifi_kill", xous::LANG)),
Self::KeyboardLayout => write!(f, "Keyboard layout"),
Self::WLANMenu => write!(f, "WiFi settings"),
Self::SetTime => write!(f, "{}", t!("mainmenu.set_rtc", xous::LANG)),
@ -181,7 +181,7 @@ impl DevicePrefs {
use DevicePrefsOp::*;
let mut ret = vec![
RadioOnOnBoot,
WifiKill,
ConnectKnownNetworksOnBoot,
AutobacklightOnBoot,
AutobacklightTimeout,
@ -211,7 +211,7 @@ impl DevicePrefs {
let resp = match action {
AutobacklightOnBoot => self.autobacklight_on_boot(),
RadioOnOnBoot => self.radio_on_on_boot(),
WifiKill => self.wifi_kill(),
ConnectKnownNetworksOnBoot => self.connect_known_networks_on_boot(),
AutobacklightTimeout => self.autobacklight_timeout(),
KeyboardLayout => self.keyboard_layout(),
@ -303,8 +303,8 @@ impl DevicePrefs {
Ok(self.up.set_autobacklight_timeout(new_timeout)?)
}
fn radio_on_on_boot(&mut self) -> Result<(), DevicePrefsError> {
let cv = self.up.radio_on_on_boot_or_default()?;
fn wifi_kill(&mut self) -> Result<(), DevicePrefsError> {
let cv = self.up.wifi_kill_or_default()?;
self.modals.add_list(vec![t!("prefs.yes", xous::LANG), t!("prefs.no", xous::LANG)]).unwrap();
@ -315,8 +315,13 @@ impl DevicePrefs {
.unwrap()
.as_str(),
);
if cv {
self.netmgr.connection_manager_wifi_off_and_stop().ok();
} else {
self.netmgr.connection_manager_wifi_on().ok();
}
Ok(self.up.set_radio_on_on_boot(new_result)?)
Ok(self.up.set_wifi_kill(new_result)?)
}
fn connect_known_networks_on_boot(&mut self) -> Result<(), DevicePrefsError> {