mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Fix bug
This commit is contained in:
@@ -24,10 +24,12 @@ class TaskManager {
|
|||||||
late Timer _pingTimer;
|
late Timer _pingTimer;
|
||||||
bool _inited = false;
|
bool _inited = false;
|
||||||
bool get inited => _inited;
|
bool get inited => _inited;
|
||||||
bool _need_closed = false;
|
bool _needClosed = false;
|
||||||
bool _wait_closed = false;
|
bool _waitClosed = false;
|
||||||
|
bool get closed => _closed;
|
||||||
void clear() {
|
void clear() {
|
||||||
tasks.clear();
|
tasks.clear();
|
||||||
|
tasksList.clear();
|
||||||
_channel?.stream.drain();
|
_channel?.stream.drain();
|
||||||
_channel?.sink.close();
|
_channel?.sink.close();
|
||||||
_closed = true;
|
_closed = true;
|
||||||
@@ -193,28 +195,28 @@ class TaskManager {
|
|||||||
}
|
}
|
||||||
}, onError: (e) {
|
}, onError: (e) {
|
||||||
_log.warning("Task websocket error: $e");
|
_log.warning("Task websocket error: $e");
|
||||||
if (_allowReconnect && !_need_closed) {
|
if (_allowReconnect && !_needClosed) {
|
||||||
_log.info("Reconnecting to task server in 5 seconds");
|
_log.info("Reconnecting to task server in 5 seconds");
|
||||||
_reconnectTimer = Timer(const Duration(seconds: 5), () {
|
_reconnectTimer = Timer(const Duration(seconds: 5), () {
|
||||||
_reconnectTimer = null;
|
_reconnectTimer = null;
|
||||||
connect();
|
connect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_wait_closed) {
|
if (_waitClosed) {
|
||||||
_wait_closed = false;
|
_waitClosed = false;
|
||||||
}
|
}
|
||||||
}, onDone: () {
|
}, onDone: () {
|
||||||
_log.warning(
|
_log.warning(
|
||||||
"WenSocket closed: ${_channel?.closeCode} ${_channel?.closeReason}");
|
"WenSocket closed: ${_channel?.closeCode} ${_channel?.closeReason}");
|
||||||
if (_allowReconnect && !_need_closed) {
|
if (_allowReconnect && !_needClosed) {
|
||||||
_log.info("Reconnecting to task server in 5 seconds");
|
_log.info("Reconnecting to task server in 5 seconds");
|
||||||
_reconnectTimer = Timer(const Duration(seconds: 5), () {
|
_reconnectTimer = Timer(const Duration(seconds: 5), () {
|
||||||
_reconnectTimer = null;
|
_reconnectTimer = null;
|
||||||
connect();
|
connect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_wait_closed) {
|
if (_waitClosed) {
|
||||||
_wait_closed = false;
|
_waitClosed = false;
|
||||||
}
|
}
|
||||||
}, cancelOnError: true);
|
}, cancelOnError: true);
|
||||||
await _channel!.ready;
|
await _channel!.ready;
|
||||||
@@ -262,21 +264,21 @@ class TaskManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<bool> _waitClosed() {
|
FutureOr<bool> _waitClose() {
|
||||||
if (!_wait_closed) return true;
|
if (!_waitClosed) return true;
|
||||||
return Future.delayed(const Duration(milliseconds: 10), _waitClosed);
|
return Future.delayed(const Duration(milliseconds: 10), _waitClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> waitClosed() {
|
Future<bool> waitClose() {
|
||||||
return Future.microtask(_waitClosed);
|
return Future.microtask(_waitClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
if (_channel != null) {
|
if (_channel != null) {
|
||||||
_need_closed = true;
|
_needClosed = true;
|
||||||
_wait_closed = true;
|
_waitClosed = true;
|
||||||
_channel!.sink.add("{\"type\":\"close\"}");
|
_channel!.sink.add("{\"type\":\"close\"}");
|
||||||
await waitClosed();
|
await waitClose();
|
||||||
}
|
}
|
||||||
_channel?.sink.close();
|
_channel?.sink.close();
|
||||||
_channel = null;
|
_channel = null;
|
||||||
@@ -286,6 +288,7 @@ class TaskManager {
|
|||||||
_reconnectTimer = null;
|
_reconnectTimer = null;
|
||||||
}
|
}
|
||||||
tasks.clear();
|
tasks.clear();
|
||||||
|
tasksList.clear();
|
||||||
listener.tryEmit("task_list_changed", null);
|
listener.tryEmit("task_list_changed", null);
|
||||||
await connect();
|
await connect();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user