Skip to content

Commit

Permalink
升级flutter版本和部分依赖
Browse files Browse the repository at this point in the history
修复恢复下载记录后已完成下载的画廊显示状态错误的bug

Update Flutter and some dependencies
Fix bug with wrong status of gallery after restoring download task
  • Loading branch information
jiangtian616 committed Jul 7, 2022
1 parent 4181b0d commit 573e63d
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 99 deletions.
1 change: 1 addition & 0 deletions lib/src/l18n/en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class en_US {
'downloadFailed': 'DownloadFailed',
'unpacking': 'Unpacking',
'completed': 'Completed',
'downloadHelpInfo': 'If you can\'t download and find errors like table doesn\'t exist in logs, please uninstall current app and re-install.',

/// search dialog
'searchConfig': 'Search Config',
Expand Down
1 change: 1 addition & 0 deletions lib/src/l18n/zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class zh_CN {
'downloadFailed': '下载失败',
'unpacking': '解压中',
'completed': '已完成',
'downloadHelpInfo': '如果发现无法下载,在日志中发现了数据库表不存在等问题,卸载当前app重装即可。',

/// search dialog
'searchConfig': '搜索配置',
Expand Down
13 changes: 11 additions & 2 deletions lib/src/pages/home/tab_view/download/download_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jhentai/src/pages/home/tab_view/download/archive_download_body.dart';
import 'package:jhentai/src/pages/home/tab_view/download/gallery_download_body.dart';
import 'package:jhentai/src/utils/toast_util.dart';

import '../../../../service/gallery_download_service.dart';

Expand All @@ -25,13 +26,17 @@ class _DownloadViewState extends State<DownloadView> {
centerTitle: true,
title: _showArchiveBody ? Text('archive'.tr) : Text('download'.tr),
elevation: 1,
leading: IconButton(
onPressed: _showHelpInfo,
icon: const Icon(Icons.help, size: 22),
),
actions: [
if (downloadService.gallerys.isNotEmpty && !_showArchiveBody)
if (!_showArchiveBody)
IconButton(
onPressed: downloadService.resumeAllDownloadGallery,
icon: Icon(Icons.play_arrow, size: 26, color: Get.theme.primaryColor),
),
if (downloadService.gallerys.isNotEmpty && !_showArchiveBody)
if (!_showArchiveBody)
IconButton(
onPressed: downloadService.pauseAllDownloadGallery,
icon: Icon(Icons.pause, size: 26, color: Get.theme.primaryColorLight),
Expand Down Expand Up @@ -60,4 +65,8 @@ class _DownloadViewState extends State<DownloadView> {
),
);
}

void _showHelpInfo() {
toast('downloadHelpInfo'.tr, isCenter: false, isShort: false);
}
}
8 changes: 4 additions & 4 deletions lib/src/pages/webview/webview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class WebviewPage extends StatefulWidget {
class _WebviewPageState extends State<WebviewPage> {
late String initialUrl;
late List<WebViewCookie> initialCookies;
PageStartedCallback? onPageStarted;
Function? pageStartedCallback;
late PageStartedCallback onPageStarted;

late WebViewController controller;

Expand All @@ -32,10 +33,9 @@ class _WebviewPageState extends State<WebviewPage> {
),
)
.toList();
pageStartedCallback = Get.arguments['onPageStarted'];
onPageStarted = (url) {
if (Get.arguments['onPageStarted'] != null) {
Get.arguments['onPageStarted'].call(url, controller);
}
pageStartedCallback?.call(url, controller);
};
}

Expand Down
15 changes: 14 additions & 1 deletion lib/src/service/gallery_download_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ class GalleryDownloadService extends GetxController {
images[serialNo]!.path = newPath;
}

/// For some reason, downloadStatusIndex is not updated correctly.
if (gallery.downloadStatusIndex != DownloadStatus.downloaded.index) {
int downloadedImageCount = images.fold(
0,
(previousValue, element) => previousValue + (element?.downloadStatus == DownloadStatus.downloaded ? 1 : 0),
);
if (downloadedImageCount == gallery.pageCount) {
gallery = gallery.copyWith(downloadStatusIndex: DownloadStatus.downloaded.index);
}
}

int success = await _restoreDownloadInfoDatabase(gallery, images);
if (success < 0) {
Log.error('restore download failed. Gallery: ${gallery.title}');
Expand Down Expand Up @@ -711,6 +722,9 @@ class GalleryDownloadService extends GetxController {
await _updateGalleryDownloadStatusInDatabase(gallery.gid, DownloadStatus.values[gallery.downloadStatusIndex]);
gallerys[gallerys.indexWhere((e) => e.gid == gallery.gid)] = gallery;
gid2DownloadProgress[gallery.gid]!.downloadStatus = DownloadStatus.values[gallery.downloadStatusIndex];
if (DownloadSetting.enableStoreMetadataForRestore.isTrue) {
_saveGalleryDownloadInfoInDisk(gallery);
}
update(['$galleryDownloadProgressId::${gallery.gid}']);
}

Expand Down Expand Up @@ -745,7 +759,6 @@ class GalleryDownloadService extends GetxController {
downloadProgress.downloadStatus = DownloadStatus.downloaded;
await _updateGalleryDownloadStatus(
gallerys.firstWhere((e) => e.gid == gid).copyWith(downloadStatusIndex: DownloadStatus.downloaded.index));
_saveGalleryDownloadInfoInDisk(gallerys.firstWhere((e) => e.gid == gid));
gid2SpeedComputer[gid]!.dispose();
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/setting/eh_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class EHSetting {
return;
}

Log.info('refresh EHSetting', false);
refreshState.value = LoadingState.loading;
Map<String, int> map = {};
try {
Expand Down
1 change: 1 addition & 0 deletions lib/src/setting/favorite_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class FavoriteSetting {
return;
}

Log.info('refresh FavoriteSetting', false);
try {
await retry(
() async {
Expand Down
1 change: 1 addition & 0 deletions lib/src/setting/site_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SiteSetting {
return;
}

Log.info('refresh SiteSetting', false);
try {
await retry(
() async {
Expand Down
8 changes: 8 additions & 0 deletions lib/src/utils/log.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:io' as io;
import 'dart:io';
import 'dart:typed_data';

import 'package:dio/dio.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:jhentai/src/setting/advanced_setting.dart';
Expand Down Expand Up @@ -162,6 +164,12 @@ class Log {
if (throwable is StateError && throwable.message.contains('User cancel request')) {
return true;
}
if (throwable is DioError && throwable.message.contains('Http status error')) {
return true;
}
if (throwable is HttpException && throwable.message.contains('Connection closed while receiving data')) {
return true;
}
return false;
}

Expand Down

0 comments on commit 573e63d

Please sign in to comment.