Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into windows
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/component/widget/broken_shield.dart
  • Loading branch information
xioxin committed Oct 17, 2022
2 parents f068004 + c9a359e commit 1ae3795
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 80 deletions.
3 changes: 2 additions & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
- [ ] 更多设置

## Windows 平台需求
- [WebView2 Runtime](https://developer.microsoft.com/en-us/microsoft-edge/webview2/)
- [WebView2 运行时](https://developer.microsoft.com/zh-CN/microsoft-edge/webview2/)
- [Microsoft Visual C++ 可再发行程序包](https://learn.microsoft.com/zh-CN/cpp/windows/latest-supported-vc-redist?view=msvc-170)
- Windows 10 1809+

## 截图
Expand Down
1 change: 1 addition & 0 deletions lib/network/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Future<GallerySet> getGalleryList({
if (httpResponse.ok && httpResponse.data is GallerySet) {
GallerySet data = httpResponse.data as GallerySet;
if (statusCode == 304) {
logger.d('fromCache');
data = data.copyWith(fromCache: true);
}
return data;
Expand Down
33 changes: 8 additions & 25 deletions lib/pages/nav/favorite/favorite_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class FavoriteNotifier extends StateNotifier<FrontState> {
bool prev = false,
bool first = false,
}) async {
if (state.isLoading || state.isLoadMore || state.isGetToken) {
if (state.isLoading) {
return false;
}

if (next && state.isLoadMore) {
return false;
}

Expand Down Expand Up @@ -75,32 +79,11 @@ class FavoriteNotifier extends StateNotifier<FrontState> {
);

return gallerySet.fromCache ?? false;
} on HttpException catch (e) {
} on Exception catch (e) {
logger.d('state.status ${state.status}');
if (showWebViewDialogOnFail &&
(e.code == 403 || e.code == 503) &&
state.status != LoadStatus.getToken) {
logger.e('code ${e.code}');
if (!mounted) {
return false;
}
state = state.copyWith(status: LoadStatus.getToken);
await showInAppWebViewDialog(
statusCode: e.code,
onComplete: () async => await getGalleryData(
refresh: refresh,
showWebViewDialogOnFail: false,
next: next,
prev: prev,
),
);
state = state.copyWith(status: LoadStatus.none);
} else {
state = state.copyWith(status: LoadStatus.error);
rethrow;
}
state = state.copyWith(status: LoadStatus.error);
rethrow;
}
return false;
}

Future<void> loadData() async {
Expand Down
41 changes: 14 additions & 27 deletions lib/pages/nav/front/front_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ class FrontNotifier extends StateNotifier<FrontState> {
bool prev = false,
bool first = false,
}) async {
if (state.isLoading || state.isLoadMore || state.isGetToken) {
if (state.isLoading) {
return false;
}

if (next && state.isLoadMore) {
return false;
}

logger.d('page: $page, next: $next, prev: $prev, first: $first');

final rCookies =
await Global.cookieJar.loadForRequest(Uri.parse(NHConst.baseUrl));
logger.v('bf rCookies \n${rCookies.map((e) => e.toString()).join('\n')}');
Expand All @@ -81,6 +87,7 @@ class FrontNotifier extends StateNotifier<FrontState> {

final toPage =
page ?? (next ? state.curPage + 1 : (prev ? state.curPage - 1 : 1));
logger.d('toPage: $toPage');

try {
final gallerySet = await getGalleryList(
Expand Down Expand Up @@ -109,39 +116,18 @@ class FrontNotifier extends StateNotifier<FrontState> {
);

return gallerySet.fromCache ?? false;
} on HttpException catch (e) {
logger.d('state.status ${state.status}');
if (showWebViewDialogOnFail &&
(e.code == 403 || e.code == 503) &&
state.status != LoadStatus.getToken) {
logger.e('code ${e.code}');
// if (!mounted) {
// return false;
// }
state = state.copyWith(status: LoadStatus.getToken);
await showInAppWebViewDialog(
statusCode: e.code,
onComplete: () async => await getGalleryData(
refresh: refresh,
showWebViewDialogOnFail: false,
next: next,
prev: prev,
),
);
state = state.copyWith(status: LoadStatus.none);
} else {
state = state.copyWith(status: LoadStatus.error);
rethrow;
}
} on Exception catch (e) {
state = state.copyWith(status: LoadStatus.error);
rethrow;
}
return false;
}

Future<void> loadData() async {
final fromCache = await getGalleryData(first: true);
if (fromCache) {
logger.d('fromCache');
await 1.seconds.delay();
await getGalleryData(refresh: true);
await reloadData();
}
}

Expand All @@ -150,6 +136,7 @@ class FrontNotifier extends StateNotifier<FrontState> {
}

Future<void> loadNextPage() async {
// await 100.milliseconds.delay();
await getGalleryData(next: true);
}

Expand Down
4 changes: 1 addition & 3 deletions lib/pages/nav/front/front_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class FrontState {
final int curPage;
final int maxPage;



FrontState copyWith({
LoadStatus? status,
int? curPage,
Expand All @@ -33,5 +31,5 @@ class FrontState {
bool get isLoadEmpty => status == LoadStatus.empty;
bool get isLoadError => status == LoadStatus.error;
bool get isLoadSuccess => status == LoadStatus.success;
bool get isGetToken => status == LoadStatus.getToken;
// bool get isGetToken => status == LoadStatus.getToken;
}
32 changes: 8 additions & 24 deletions lib/pages/nav/search/search_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class SearchNotifier extends StateNotifier<FrontState> {
bool prev = false,
bool first = false,
}) async {
if (state.isLoading || state.isLoadMore || state.isGetToken) {
if (state.isLoading) {
return;
}

if (next && state.isLoadMore) {
return;
}

Expand Down Expand Up @@ -83,30 +87,10 @@ class SearchNotifier extends StateNotifier<FrontState> {
status: LoadStatus.success,
curPage: toPage,
);
} on HttpException catch (e) {
} on Exception catch (e) {
logger.d('state.status ${state.status}');
if (showWebViewDialogOnFail &&
(e.code == 403 || e.code == 503) &&
state.status != LoadStatus.getToken) {
logger.e('code ${e.code}');
// if (!mounted) {
// return false;
// }
state = state.copyWith(status: LoadStatus.getToken);
await showInAppWebViewDialog(
statusCode: e.code,
onComplete: () async => await getGalleryData(
refresh: refresh,
showWebViewDialogOnFail: false,
next: next,
prev: prev,
),
);
state = state.copyWith(status: LoadStatus.none);
} else {
state = state.copyWith(status: LoadStatus.error);
rethrow;
}
state = state.copyWith(status: LoadStatus.error);
rethrow;
}
}

Expand Down

0 comments on commit 1ae3795

Please sign in to comment.