diff --git a/lib/http/user.dart b/lib/http/user.dart index ad3777235..716b294bc 100644 --- a/lib/http/user.dart +++ b/lib/http/user.dart @@ -44,13 +44,12 @@ abstract final class UserHttp { } } - static Future userStatOwner() async { + static Future> userStatOwner() async { final res = await Request().get(Api.userStatOwner); if (res.data['code'] == 0) { - UserStat data = UserStat.fromJson(res.data['data']); - return {'status': true, 'data': data}; + return Success(UserStat.fromJson(res.data['data'])); } else { - return {'status': false, 'msg': res.data['message']}; + return Error(res.data['message']); } } diff --git a/lib/models_new/download/bili_download_entry_info.dart b/lib/models_new/download/bili_download_entry_info.dart index e103de0b0..7de508775 100644 --- a/lib/models_new/download/bili_download_entry_info.dart +++ b/lib/models_new/download/bili_download_entry_info.dart @@ -36,7 +36,7 @@ class BiliDownloadEntryInfo with MultiSelectData { late String pageDirPath; late String entryDirPath; - DownloadStatus? status; + DownloadStatus status = .wait; int get cid => source?.cid ?? pageData!.cid; @@ -398,4 +398,6 @@ enum DownloadStatus { final String message; const DownloadStatus(this.message); + + bool get isDownloading => index <= 3; } diff --git a/lib/pages/download/detail/widgets/item.dart b/lib/pages/download/detail/widgets/item.dart index 2bf3c0ba2..70fe0c815 100644 --- a/lib/pages/download/detail/widgets/item.dart +++ b/lib/pages/download/detail/widgets/item.dart @@ -145,7 +145,7 @@ class DetailItem extends StatelessWidget { final curDownload = downloadService.curDownload.value; if (curDownload != null && curDownload.cid == cid && - curDownload.status!.index <= 3) { + curDownload.status.isDownloading) { downloadService.cancelDownload( isDelete: false, downloadNext: false, @@ -352,7 +352,7 @@ class DetailItem extends StatelessWidget { ? theme.colorScheme.primary : theme.colorScheme.outline; return progressWidget( - statusMsg: status!.message, + statusMsg: status.message, progressStr: status == DownloadStatus @@ -385,7 +385,7 @@ class DetailItem extends StatelessWidget { } Widget entryProgress(ThemeData theme) => progressWidget( - statusMsg: entry.status?.message ?? '暂停中', + statusMsg: entry.status.message, progressStr: entry.totalBytes == 0 ? '' : '${CacheManager.formatSize(entry.downloadedBytes)}/${CacheManager.formatSize(entry.totalBytes)}', diff --git a/lib/pages/mine/controller.dart b/lib/pages/mine/controller.dart index 0bc75092e..c4bdf6f7b 100644 --- a/lib/pages/mine/controller.dart +++ b/lib/pages/mine/controller.dart @@ -126,8 +126,8 @@ class MineController extends CommonDataController Future queryUserStatOwner() async { final res = await UserHttp.userStatOwner(); - if (res['status']) { - userStat.value = res['data']; + if (res case Success(:final response)) { + userStat.value = response; } } diff --git a/lib/pages/video/view.dart b/lib/pages/video/view.dart index 278d5bede..c156984f5 100644 --- a/lib/pages/video/view.dart +++ b/lib/pages/video/view.dart @@ -402,7 +402,7 @@ class _VideoDetailPageVState extends State @override // 返回当前页面时 - Future didPopNext() async { + void didPopNext() { if (videoDetailController.imageview) { videoDetailController.imageview = false; return; @@ -442,20 +442,24 @@ class _VideoDetailPageVState extends State ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness(); } } - super.didPopNext(); - if (videoDetailController.autoPlay.value) { - await videoDetailController.playerInit( - autoplay: videoDetailController.playerStatus == PlayerStatus.playing, - ); - } else if (videoDetailController.plPlayerController.preInitPlayer && - !videoDetailController.isQuerying && - videoDetailController.videoState.value is! Error) { - await videoDetailController.playerInit(); - } - plPlayerController - ?..addStatusLister(playerListener) - ..addPositionListener(positionListener); + () async { + if (videoDetailController.autoPlay.value) { + await videoDetailController.playerInit( + autoplay: videoDetailController.playerStatus == PlayerStatus.playing, + ); + } else if (videoDetailController.plPlayerController.preInitPlayer && + !videoDetailController.isQuerying && + videoDetailController.videoState.value is! Error) { + await videoDetailController.playerInit(); + } + + plPlayerController + ?..addStatusLister(playerListener) + ..addPositionListener(positionListener); + }(); + + super.didPopNext(); } @override diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 263167f4d..cb89f11c2 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -497,13 +497,13 @@ class PlPlayerController { return _instance != null; } - static void setPlayCallBack(Function? playCallBack) { + static void setPlayCallBack(VoidCallback? playCallBack) { _playCallBack = playCallBack; } - static Function? _playCallBack; + static VoidCallback? _playCallBack; - static void playIfExists({bool repeat = false, bool hideControls = true}) { + static void playIfExists() { // await _instance?.play(repeat: repeat, hideControls: hideControls); _playCallBack?.call(); } diff --git a/lib/services/download/download_service.dart b/lib/services/download/download_service.dart index 1b3c37062..c44a859b8 100644 --- a/lib/services/download/download_service.dart +++ b/lib/services/download/download_service.dart @@ -246,8 +246,7 @@ class DownloadService extends GetxService { ..entryDirPath = entryDir.path ..status = DownloadStatus.wait; waitDownloadQueue.add(entry); - final currStatus = curDownload.value?.status?.index; - if (currStatus == null || currStatus > 3) { + if (curDownload.value?.status.isDownloading != true) { startDownload(entry); } } @@ -285,9 +284,10 @@ class DownloadService extends GetxService { await _audioDownloadManager?.cancel(isDelete: false); _downloadManager = null; _audioDownloadManager = null; - final prevStatus = curDownload.value?.status?.index; - if (prevStatus != null && prevStatus <= 3) { - curDownload.value?.status = DownloadStatus.pause; + if (curDownload.value case final curEntry?) { + if (curEntry.status.isDownloading) { + curEntry.status = DownloadStatus.pause; + } } _curCid = entry.cid; @@ -372,13 +372,12 @@ class DownloadService extends GetxService { _updateCurStatus(DownloadStatus.getPlayUrl); - final BiliDownloadMediaInfo mediaFileInfo = - await DownloadHttp.getVideoUrl( - entry: entry, - ep: entry.ep, - source: entry.source, - pageData: entry.pageData, - ); + final mediaFileInfo = await DownloadHttp.getVideoUrl( + entry: entry, + ep: entry.ep, + source: entry.source, + pageData: entry.pageData, + ); final videoDir = Directory(path.join(entry.entryDirPath, entry.typeTag)); if (!videoDir.existsSync()) { diff --git a/lib/utils/wbi_sign.dart b/lib/utils/wbi_sign.dart index adf41316b..644d83952 100644 --- a/lib/utils/wbi_sign.dart +++ b/lib/utils/wbi_sign.dart @@ -2,6 +2,7 @@ // https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/misc/sign/wbi.md // import md5 from 'md5' // import axios from 'axios' +import 'dart:async'; import 'dart:convert'; import 'package:PiliPlus/http/api.dart'; @@ -74,7 +75,7 @@ abstract final class WbiSign { .toString(); // 计算 w_rid } - static Future _getWbiKeys(DateTime nowDate) async { + static Future _getWbiKeys() async { final resp = await Request().get(Api.userInfo); try { final wbiUrls = resp.data['data']['wbi_img']; @@ -84,9 +85,7 @@ abstract final class WbiSign { Utils.getFileName(wbiUrls['sub_url'], fileExt: false), ); - _localCache - ..put(LocalCacheKey.mixinKey, mixinKey) - ..put(LocalCacheKey.timeStamp, nowDate.millisecondsSinceEpoch); + _localCache.put(LocalCacheKey.mixinKey, mixinKey); return mixinKey; } catch (_) { @@ -94,17 +93,19 @@ abstract final class WbiSign { } } - static Future getWbiKeys() async { - final DateTime nowDate = DateTime.now(); + static FutureOr getWbiKeys() { + final nowDate = DateTime.now(); if (DateTime.fromMillisecondsSinceEpoch( _localCache.get(LocalCacheKey.timeStamp, defaultValue: 0) as int, ).day == nowDate.day) { final String? mixinKey = _localCache.get(LocalCacheKey.mixinKey); if (mixinKey != null) return mixinKey; - return _future ??= _getWbiKeys(nowDate); + return _future ??= _getWbiKeys(); } else { - return _future = _getWbiKeys(nowDate); + return _future = _localCache + .put(LocalCacheKey.timeStamp, nowDate.millisecondsSinceEpoch) + .then((_) => _getWbiKeys()); } }