fix: Crash on logout

This commit is contained in:
Krille Fear 2021-10-27 11:14:27 +02:00
parent 6b68020857
commit 288160d852
2 changed files with 10 additions and 7 deletions

View File

@ -37,6 +37,7 @@ void main() async {
Zone.current.handleUncaughtError(details.exception, details.stack);
final clients = await ClientManager.getClients();
Logs().level = kDebugMode ? Level.debug : Level.warning;
if (PlatformInfos.isMobile) {
BackgroundPush.clientOnly(clients.first);

View File

@ -136,17 +136,19 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
Client _loginClientCandidate;
Client getLoginClient() {
final multiAccount = client.isLogged();
if (!multiAccount) return client;
if (widget.clients.isNotEmpty && !client.isLogged()) {
return client;
}
_loginClientCandidate ??= ClientManager.createClient(
// we use the first clients here, else we can easily end up with super long client names.
widget.clients.first.generateUniqueTransactionId())
'${AppConfig.applicationName}-${DateTime.now().millisecondsSinceEpoch}')
..onLoginStateChanged
.stream
.where((l) => l == LoginState.loggedIn)
.first
.then((_) {
if (!widget.clients.contains(_loginClientCandidate)) {
widget.clients.add(_loginClientCandidate);
}
ClientManager.addClientNameToStore(_loginClientCandidate.clientName);
_registerSubs(_loginClientCandidate.clientName);
_loginClientCandidate = null;
@ -207,12 +209,12 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
String get cachedPassword => _cachedPassword;
set cachedPassword(String p) {
Logs().v('Password cached');
Logs().d('Password cached');
_cachedPasswordClearTimer?.cancel();
_cachedPassword = p;
_cachedPasswordClearTimer = Timer(const Duration(minutes: 10), () {
_cachedPassword = null;
Logs().v('Cached Password cleared');
Logs().d('Cached Password cleared');
});
}