This commit is contained in:
lollipopkit
2023-08-09 23:58:38 +08:00
parent 58fbd62779
commit c512a6a274
36 changed files with 243 additions and 160 deletions

View File

@@ -12,11 +12,22 @@ class Server {
}
enum ServerState {
failed,
disconnected,
connecting,
connected,
failed;
bool get shouldConnect =>
this == ServerState.disconnected || this == ServerState.failed;
/// Connected to server
connected,
/// Status parsing
loading,
/// Status parsing finished
finished;
bool get shouldConnect => this < ServerState.connecting;
bool get canViewDetails => this == ServerState.finished;
operator <(ServerState other) => index < other.index;
}

View File

@@ -4,7 +4,7 @@ import '../../store/setting.dart';
class TryLimiter {
final Map<String, int> _triedTimes = {};
bool shouldTry(String id) {
bool canTry(String id) {
final maxCount = locator<SettingStore>().maxRetryCount.fetch()!;
if (maxCount <= 0) {
return true;
@@ -13,10 +13,13 @@ class TryLimiter {
if (times >= maxCount) {
return false;
}
_triedTimes[id] = times + 1;
return true;
}
void inc(String sid) {
_triedTimes[sid] = (_triedTimes[sid] ?? 0) + 1;
}
void reset(String id) {
_triedTimes[id] = 0;
}