This commit is contained in:
otsmr 2025-04-08 17:30:37 +02:00
parent d25f4cb36d
commit 8b998914e3

View file

@ -6,6 +6,7 @@ import 'dart:math';
import 'package:fixnum/fixnum.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
import 'package:mutex/mutex.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:twonly/globals.dart';
import 'package:twonly/src/app.dart';
@ -26,6 +27,8 @@ import 'package:web_socket_channel/io.dart';
import 'package:libsignal_protocol_dart/src/ecc/ed25519.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
final lockConnecting = Mutex();
/// The ApiProvider is responsible for communicating with the server.
/// It handles errors and does automatically tries to reconnect on
/// errors or network changes.
@ -95,6 +98,7 @@ class ApiProvider {
}
Future<bool> connect() async {
return lockConnecting.protect<bool>(() async {
if (_channel != null) {
return true;
}
@ -118,6 +122,7 @@ class ApiProvider {
}
}
return false;
});
}
bool get isConnected => _channel != null && _channel!.closeCode != null;