M5stack, fix in uiviewcontrollers, if password reset required, then disconnect permenantly

This commit is contained in:
Johan Degraeve 2019-10-17 00:58:33 +02:00
parent 8ae5b2479e
commit ac4bee9342
4 changed files with 43 additions and 17 deletions

View File

@ -317,12 +317,18 @@ extension M5StackManager: M5StackManaging {
}
}
/// disconnect from M5Stack
/// disconnect from M5Stack - and don't reconnect - set shouldconnect to false
func disconnect(fromM5stack m5Stack: M5Stack) {
// device should not reconnect after disconnecting
m5Stack.shouldconnect = false
// save in coredata
save()
if let bluetoothTransmitter = m5StacksBlueToothTransmitters[m5Stack] {
if let bluetoothTransmitter = bluetoothTransmitter {
bluetoothTransmitter.disconnect()
bluetoothTransmitter.disconnect(reconnectAfterDisconnect: false)
}
}
}
@ -480,7 +486,7 @@ extension M5StackManager: M5StackBluetoothDelegate {
}
/// did the app successfully authenticate towards M5Stack
/// did the app successfully authenticate towards M5Stack, if no, then disconnect will be done
///
func authentication(success: Bool, forM5Stack m5Stack:M5Stack) {
trace("in authentication with success = %{public}@", log: self.log, type: .info, success.description)
@ -489,28 +495,30 @@ extension M5StackManager: M5StackBluetoothDelegate {
// disconnection is done because maybe another device is trying to connect to the M5Stack, need to make it free
if !success {
// device should not reconnect after disconnecting
m5Stack.shouldconnect = false
// save in coredata
save()
// disconnect
disconnect(fromM5stack: m5Stack)
}
}
/// there's no ble password set, user should set it in the settings
/// there's no ble password set, user should set it in the settings - disconnect will be called
func blePasswordMissing(forM5Stack m5Stack: M5Stack) {
// no further action, This is for UIViewcontroller's that also receive this info, means info can only be shown if this happens while user has one of the UIViewcontrollers open
trace("in blePasswordMissing", log: self.log, type: .info)
// disconnect
disconnect(fromM5stack: m5Stack)
}
/// it's an M5Stack without password configired in the ini file. xdrip app has been requesting temp password to M5Stack but this was already done once. M5Stack needs to be reset
/// it's an M5Stack without password configured in the ini file. xdrip app has been requesting temp password to M5Stack but this was already done once. M5Stack needs to be reset. - disconnect will be called
func m5StackResetRequired(forM5Stack m5Stack:M5Stack) {
// no further action, This is for UIViewcontroller's that also receive this info, means info can only be shown if this happens while user has one of the UIViewcontrollers open
trace("in m5StackResetRequired", log: self.log, type: .info)
// disconnect
disconnect(fromM5stack: m5Stack)
}
/// did disconnect from M5Stack

View File

@ -7,7 +7,7 @@
"donotconnect" = "Don't connect";
"authenticationFailureWarning" = "Authentication to M5Stack Failed, either set the pre-configured password in the Settings, or, if the M5Stack does not have a preconfigured password then reset the M5Stack. M5Stack will disconnect now. You can make a new attempt by clicking ";
"blePasswordMissingWarning" = "You need to set the password in the Settings";
"m5StackResetRequiredWarning" = "M5Stack must be reset in order to generate a new temporary password";
"m5StackResetRequiredWarning" = "M5Stack must be reset in order to generate a new temporary password. When done click ";
"m5StackAlias" = "Alias";
"selectAliasText" = "Choose a name for this M5Stack, the name will be shown in the app and is easier for you to recognize";
"userdefinedNameAlreadyExists" = "There is already an M5Stack with this name";

View File

@ -41,7 +41,7 @@ class Texts_M5StackView {
}()
static let m5StackResetRequiredWarning: String = {
return NSLocalizedString("m5StackResetRequiredWarning", tableName: filename, bundle: Bundle.main, value: "You need to reset the M5Stack in order to get a new temporary password", comment: "in case M5Stack authentication failed, and M5Stack is generating a random password")
return NSLocalizedString("m5StackResetRequiredWarning", tableName: filename, bundle: Bundle.main, value: "You need to reset the M5Stack in order to get a new temporary password. When done click'", comment: "in case M5Stack authentication failed, and M5Stack is generating a random password")
}()
static let m5StackAlias: String = {

View File

@ -606,19 +606,37 @@ extension M5StackViewController: M5StackBluetoothDelegate {
// by the time user clicks 'ok', the M5stack will be disconnected by the M5StackManager (see authentication in M5StackManager)
self.shouldConnectTemporaryValue = m5Stack.shouldconnect
self.setConnectButtonLabelText()
}).presentInOwnWindow(animated: true, completion: nil)
}
}
func blePasswordMissing(forM5Stack m5Stack: M5Stack) {
UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.authenticationFailureWarning, actionHandler: nil).presentInOwnWindow(animated: true, completion: nil)
// show warning, inform that user should set password or reset M5Stack
UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.authenticationFailureWarning + " " + Texts_M5StackView.alwaysConnect, actionHandler: {
// by the time user clicks 'ok', the M5stack will be disconnected by the M5StackManager (see authentication in M5StackManager)
self.shouldConnectTemporaryValue = m5Stack.shouldconnect
self.setConnectButtonLabelText()
}).presentInOwnWindow(animated: true, completion: nil)
}
func m5StackResetRequired(forM5Stack m5Stack: M5Stack) {
UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.m5StackResetRequiredWarning, actionHandler: nil).presentInOwnWindow(animated: true, completion: nil)
// show warning, inform that user should set password or reset M5Stack
UIAlertController(title: Texts_Common.warning, message: Texts_M5StackView.m5StackResetRequiredWarning + " " + Texts_M5StackView.alwaysConnect, actionHandler: {
// by the time user clicks 'ok', the M5stack will be disconnected by the M5StackManager (see authentication in M5StackManager)
self.shouldConnectTemporaryValue = m5Stack.shouldconnect
self.setConnectButtonLabelText()
}).presentInOwnWindow(animated: true, completion: nil)
}