Skip to content

Commit

Permalink
_onTimeoutChange
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtian616 committed Jan 15, 2025
1 parent acf2754 commit 65e2d10
Show file tree
Hide file tree
Showing 2 changed files with 322 additions and 309 deletions.
15 changes: 14 additions & 1 deletion lib/src/service/archive_download_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ArchiveDownloadService extends GetxController with GridBasePageServiceMixi

late Worker isolateCountListener;
late Worker proxyConfigListener;
late Worker timeoutListener;

@override
Future<void> doInitBean() async {
Expand All @@ -82,6 +83,7 @@ class ArchiveDownloadService extends GetxController with GridBasePageServiceMixi

isolateCountListener = ever(downloadSetting.archiveDownloadIsolateCount, (_) => _onIsolateCountChange());
proxyConfigListener = everAll([networkSetting.proxyAddress, networkSetting.proxyUsername, networkSetting.proxyPassword], (_) => _onProxyConfigChange());
timeoutListener = everAll([networkSetting.connectTimeout, networkSetting.receiveTimeout], (_) => _onTimeoutChange());

if (downloadSetting.restoreTasksAutomatically.isTrue) {
await restoreTasks();
Expand All @@ -97,6 +99,7 @@ class ArchiveDownloadService extends GetxController with GridBasePageServiceMixi

isolateCountListener.dispose();
proxyConfigListener.dispose();
timeoutListener.dispose();
}

bool containArchive(int gid) {
Expand All @@ -119,7 +122,6 @@ class ArchiveDownloadService extends GetxController with GridBasePageServiceMixi

log.info('Begin to handle archive: ${archive.title}, original: ${archive.isOriginal}');


/// step 1: request to unlock archive: if we have unlocked before or unlock has completed,
/// we can get [downloadPageUrl] immediately, otherwise we must wait for a second
await _unlock(archive);
Expand Down Expand Up @@ -559,6 +561,8 @@ class ArchiveDownloadService extends GetxController with GridBasePageServiceMixi
isolateCount: downloadSetting.archiveDownloadIsolateCount.value,
deleteWhenUrlMismatch: false,
proxyConfig: ehRequest.currentProxyConfig(),
headConnectionTimeout: Duration(milliseconds: networkSetting.connectTimeout.value),
headReceiveTimeout: Duration(milliseconds: networkSetting.receiveTimeout.value),
onLog: (OutputEvent event) {},
onProgress: (current, total) {
ArchiveDownloadInfo archiveDownloadInfo = archiveDownloadInfos[archive.gid]!;
Expand Down Expand Up @@ -662,6 +666,15 @@ class ArchiveDownloadService extends GetxController with GridBasePageServiceMixi
}
}

void _onTimeoutChange() {
for (ArchiveDownloadInfo archiveDownloadInfo in archiveDownloadInfos.values) {
if (archiveDownloadInfo.archiveStatus.code <= ArchiveStatus.unpacking.code && archiveDownloadInfo.downloadTask != null) {
archiveDownloadInfo.downloadTask!.changeConnectionTimeout(Duration(milliseconds: networkSetting.connectTimeout.value));
archiveDownloadInfo.downloadTask!.changeReceiveTimeout(Duration(milliseconds: networkSetting.receiveTimeout.value));
}
}
}

bool _isTaskInStatus(int gid, List<ArchiveStatus> statuses) {
return archiveDownloadInfos.containsKey(gid) && statuses.contains(archiveDownloadInfos[gid]!.archiveStatus);
}
Expand Down
Loading

0 comments on commit 65e2d10

Please sign in to comment.