Skip to content

Commit

Permalink
支持windows
Browse files Browse the repository at this point in the history
修复cookie登录的bug
修复阅读页面电池电量不更新的bug
修复阅读页面切换左右阅读方向时的bug

Support windows
Fix the bug of cookie login
Fix the bug of battery power not updating in read page
Fix the bug for switching reading direction
  • Loading branch information
jiangtian616 committed Jul 8, 2022
1 parent 573e63d commit b28d90b
Show file tree
Hide file tree
Showing 38 changed files with 569 additions and 308 deletions.
5 changes: 5 additions & 0 deletions lib/src/l18n/en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class en_US {
'userNameOrPasswordMismatch': 'Username or password mismatch',
'copyCookies': 'Copy Cookies',
'tap2Copy': 'Tap to Copy',
'webLoginIsDisabled': 'Web login is disabled on desktop',

/// request
'sadPanda': 'Sad Panda: No Data',
Expand Down Expand Up @@ -139,6 +140,10 @@ class en_US {
'loading': "Loading",
'paused': 'Paused',
'exceedImageLimits': "Exceed Image Limits",
'toNext': 'To next',
'toPrev': 'To prev',
'back': 'Back',
'toggleMenu': 'Toggle menu',

/// setting page
'account': 'Account',
Expand Down
5 changes: 5 additions & 0 deletions lib/src/l18n/zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class zh_CN {
'userNameOrPasswordMismatch': '用户名或密码错误',
'copyCookies': '复制Cookies',
'tap2Copy': '点击复制',
'webLoginIsDisabled': '桌面端无法使用Web登录',

/// request
'sadPanda': 'Sad Panda: 无响应数据',
Expand Down Expand Up @@ -139,6 +140,10 @@ class zh_CN {
'loading': "加载中",
'paused': '已暂停',
'exceedImageLimits': "超出图片配额限制",
'toNext': '下一页',
'toPrev': '上一页',
'back': '返回',
'toggleMenu': '展示/隐藏菜单',

/// setting page
'account': '账户',
Expand Down
9 changes: 9 additions & 0 deletions lib/src/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -43,6 +44,7 @@ void main() async {
runZonedGuarded(() async {
await init();
runApp(const MyApp());
_doForWindows();
}, (Object error, StackTrace stack) {
if (error is UploadException) {
return;
Expand Down Expand Up @@ -127,3 +129,10 @@ Future<void> onReady() async {

ReadSetting.init();
}

void _doForWindows() {
doWhenWindowReady(() {
appWindow.title = 'JHenTai';
appWindow.show();
});
}
32 changes: 12 additions & 20 deletions lib/src/network/eh_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'dart:async';
import 'dart:io';
import 'package:dio/adapter.dart';
import 'package:dio/dio.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_instance/src/extension_instance.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:get/get_utils/src/extensions/internacionalization.dart';
import 'package:get/get_utils/src/platform/platform.dart';
import 'package:jhentai/src/consts/eh_consts.dart';
import 'package:jhentai/src/exception/eh_exception.dart';
import 'package:jhentai/src/model/search_config.dart';
Expand Down Expand Up @@ -69,8 +69,7 @@ class EHRequest {
handler.next(e);
return;
}
if (!EHConsts.host2Ip.containsKey(e.requestOptions.uri.host) &&
!EHConsts.host2Ip.containsValue(e.requestOptions.uri.host)) {
if (!EHConsts.host2Ip.containsKey(e.requestOptions.uri.host) && !EHConsts.host2Ip.containsValue(e.requestOptions.uri.host)) {
handler.next(e);
return;
}
Expand Down Expand Up @@ -137,7 +136,9 @@ class EHRequest {
static Future<void> requestLogout() async {
cookieManager.removeAllCookies();
UserSetting.clear();
CookieManager().clearCookies();
if (!GetPlatform.isDesktop) {
CookieManager().clearCookies();
}
}

static Future<T> requestHomePage<T>({EHHtmlParser<T>? parser}) async {
Expand Down Expand Up @@ -184,9 +185,7 @@ class EHRequest {
EHSetting.site.value == 'EH' ? galleryUrl : galleryUrl.replaceFirst(EHConsts.EHIndex, EHConsts.EXIndex),
queryParameters: {'p': thumbnailsPageNo},
cancelToken: cancelToken,
options: useCacheIfAvailable
? EHCacheInterceptor.cacheOption.toOptions()
: EHCacheInterceptor.refreshCacheOption.toOptions(),
options: useCacheIfAvailable ? EHCacheInterceptor.cacheOption.toOptions() : EHCacheInterceptor.refreshCacheOption.toOptions(),
);
return callWithParamsUploadIfErrorOccurs(() => parser(response), params: response);
}
Expand All @@ -196,8 +195,7 @@ class EHRequest {
return callWithParamsUploadIfErrorOccurs(() => parser(response), params: response);
}

static Future<T> requestSubmitRating<T>(int gid, String token, int apiuid, String apikey, int rating,
{EHHtmlParser<T>? parser}) async {
static Future<T> requestSubmitRating<T>(int gid, String token, int apiuid, String apikey, int rating, {EHHtmlParser<T>? parser}) async {
Response<String> response = await _dio.post(
EHConsts.EApi,
data: {
Expand Down Expand Up @@ -247,7 +245,7 @@ class EHRequest {
data: {
'favcat': favcat,
'favnote': '',
'apply': 'Apply Changes',
'apply': 'Add to Favorites',
'update': 1,
},
);
Expand Down Expand Up @@ -285,9 +283,7 @@ class EHRequest {
Response<String> response = await _dio.get(
href,
cancelToken: cancelToken,
options: useCacheIfAvailable
? EHCacheInterceptor.cacheOption.toOptions()
: EHCacheInterceptor.refreshCacheOption.toOptions(),
options: useCacheIfAvailable ? EHCacheInterceptor.cacheOption.toOptions() : EHCacheInterceptor.refreshCacheOption.toOptions(),
);
return parser(response);
}
Expand Down Expand Up @@ -444,8 +440,7 @@ class EHRequest {
return parser(response);
}

static Future<T> voteTag<T>(
int gid, String token, int apiuid, String apikey, String namespace, String tagName, bool isVotingUp,
static Future<T> voteTag<T>(int gid, String token, int apiuid, String apikey, String namespace, String tagName, bool isVotingUp,
{EHHtmlParser<T>? parser}) async {
Response<String> response = await _dio.post(
EHConsts.EApi,
Expand All @@ -463,8 +458,7 @@ class EHRequest {
return callWithParamsUploadIfErrorOccurs(() => parser!(response), params: response);
}

static Future<T> voteComment<T>(int gid, String token, int apiuid, String apikey, int commentId, bool isVotingUp,
{EHHtmlParser<T>? parser}) async {
static Future<T> voteComment<T>(int gid, String token, int apiuid, String apikey, int commentId, bool isVotingUp, {EHHtmlParser<T>? parser}) async {
Response<String> response = await _dio.post(
EHConsts.EApi,
data: {
Expand Down Expand Up @@ -571,9 +565,7 @@ class EHRequest {
}) async {
Response? response = await _dio.get(
url,
options: useCacheIfAvailable
? EHCacheInterceptor.cacheOption.toOptions()
: EHCacheInterceptor.refreshCacheOption.toOptions(),
options: useCacheIfAvailable ? EHCacheInterceptor.cacheOption.toOptions() : EHCacheInterceptor.refreshCacheOption.toOptions(),
cancelToken: cancelToken,
);
parser ??= noOpParser;
Expand Down
64 changes: 29 additions & 35 deletions lib/src/pages/details/details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:jhentai/src/service/tag_translation_service.dart';
import 'package:jhentai/src/setting/user_setting.dart';
import 'package:jhentai/src/pages/details/widget/eh_comment.dart';
import 'package:jhentai/src/widget/eh_image.dart';
import 'package:jhentai/src/widget/eh_keyboard_listener.dart';
import 'package:jhentai/src/widget/eh_tag.dart';
import 'package:jhentai/src/widget/eh_thumbnail.dart';
import 'package:jhentai/src/widget/icon_text_button.dart';
Expand All @@ -38,7 +39,7 @@ import 'details_page_logic.dart';
import 'details_page_state.dart';

class DetailsPage extends StatelessWidget {
String tag = UniqueKey().toString();
final String tag = UniqueKey().toString();

late final DetailsPageLogic detailsPageLogic;
late final DetailsPageState detailsPageState;
Expand All @@ -54,7 +55,9 @@ class DetailsPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return GetBuilder<DetailsPageLogic>(
return EHKeyboardListener(
handleEsc: () => back(currentRoute: Routes.details),
child: GetBuilder<DetailsPageLogic>(
id: bodyId,
tag: tag,
builder: (logic) {
Expand Down Expand Up @@ -97,34 +100,34 @@ class DetailsPage extends StatelessWidget {
if (detailsPageState.galleryDetails?.newVersionGalleryUrl != null)
_buildNewVersionHint(detailsPageState.galleryDetails!.newVersionGalleryUrl!),
_buildActions(gallery, detailsPageState.galleryDetails, context),
if (detailsPageState.galleryDetails?.fullTags.isNotEmpty ?? false)
_buildTags(detailsPageState.galleryDetails!.fullTags),
if (detailsPageState.galleryDetails?.fullTags.isNotEmpty ?? false) _buildTags(detailsPageState.galleryDetails!.fullTags),
_buildLoadingDetailsIndicator(),
if (detailsPageState.galleryDetails != null)
_buildCommentsIndicator(detailsPageState.galleryDetails!),
if (detailsPageState.galleryDetails?.comments.isNotEmpty ?? false)
_buildComments(detailsPageState.galleryDetails!),
if (detailsPageState.galleryDetails != null) _buildCommentsIndicator(detailsPageState.galleryDetails!),
if (detailsPageState.galleryDetails?.comments.isNotEmpty ?? false) _buildComments(detailsPageState.galleryDetails!),
if (detailsPageState.galleryDetails != null) _buildThumbnails(detailsPageState.galleryDetails!),
if (detailsPageState.galleryDetails != null) _buildLoadingThumbnailIndicator(),
],
).paddingOnly(top: 10, left: 15, right: 15),
);
}(),
);
});
},
),
);
}

Widget _buildLoadingPageIndicator() {
return GetBuilder<DetailsPageLogic>(
id: loadingStateId,
tag: tag,
builder: (logic) {
return LoadingStateIndicator(
indicatorRadius: 18,
loadingState: detailsPageState.loadingPageState,
errorTapCallback: detailsPageLogic.getFullPage,
);
});
id: loadingStateId,
tag: tag,
builder: (logic) {
return LoadingStateIndicator(
indicatorRadius: 18,
loadingState: detailsPageState.loadingPageState,
errorTapCallback: detailsPageLogic.getFullPage,
);
},
);
}

Widget _buildHeader(Gallery gallery, GalleryDetail? galleryDetails, BuildContext context) {
Expand Down Expand Up @@ -339,8 +342,7 @@ class DetailsPage extends StatelessWidget {
IconTextButton(
iconData: Icons.download,
iconSize: 30,
onPressed:
detailsPageState.gallery?.pageCount == null ? null : () => detailsPageLogic.handleTapDownload(),
onPressed: detailsPageState.gallery?.pageCount == null ? null : () => detailsPageLogic.handleTapDownload(),
text: GetBuilder<GalleryDownloadService>(
id: '$galleryDownloadProgressId::${gallery.gid}',
builder: (_) {
Expand Down Expand Up @@ -368,9 +370,7 @@ class DetailsPage extends StatelessWidget {
width: max(77, (screenWidth - 15 * 2) / 7),
loadingState: detailsPageState.favoriteState,
idleWidget: IconTextButton(
iconData: gallery.isFavorite && detailsPageState.galleryDetails != null
? Icons.favorite
: Icons.favorite_border,
iconData: gallery.isFavorite && detailsPageState.galleryDetails != null ? Icons.favorite : Icons.favorite_border,
iconSize: 26,
iconColor: gallery.isFavorite && detailsPageState.galleryDetails != null
? ColorConsts.favoriteTagColor[gallery.favoriteTagIndex!]
Expand Down Expand Up @@ -401,10 +401,8 @@ class DetailsPage extends StatelessWidget {
width: max(77, (screenWidth - 15 * 2) / 7),
loadingState: detailsPageState.ratingState,
idleWidget: IconTextButton(
iconData:
gallery.hasRated && detailsPageState.galleryDetails != null ? Icons.star : Icons.star_border,
iconColor:
gallery.hasRated && detailsPageState.galleryDetails != null ? Colors.red.shade700 : null,
iconData: gallery.hasRated && detailsPageState.galleryDetails != null ? Icons.star : Icons.star_border,
iconColor: gallery.hasRated && detailsPageState.galleryDetails != null ? Colors.red.shade700 : null,
iconSize: 28,
text: Text(
gallery.hasRated ? gallery.rating.toString() : 'rating'.tr,
Expand Down Expand Up @@ -482,9 +480,7 @@ class DetailsPage extends StatelessWidget {
tagData: TagData(
namespace: 'rows',
key: entry.key,
tagName: StyleSetting.enableTagZHTranslation.isTrue
? LocaleConsts.tagNamespace[entry.key]
: null,
tagName: StyleSetting.enableTagZHTranslation.isTrue ? LocaleConsts.tagNamespace[entry.key] : null,
),
),
addNameSpaceColor: true,
Expand Down Expand Up @@ -563,8 +559,7 @@ class DetailsPage extends StatelessWidget {
child: EHComment(
comment: comment,
maxLines: 4,
showVotingButtons:
galleryDetails.comments.every((comment) => comment.userName != UserSetting.userName.value),
showVotingButtons: galleryDetails.comments.every((comment) => comment.userName != UserSetting.userName.value),
),
).marginOnly(right: 10),
)
Expand Down Expand Up @@ -602,14 +597,13 @@ class DetailsPage extends StatelessWidget {
return SliverGrid(
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == galleryDetails.thumbnails.length - 1 &&
detailsPageState.loadingThumbnailsState == LoadingState.idle) {
if (index == galleryDetails.thumbnails.length - 1 && detailsPageState.loadingThumbnailsState == LoadingState.idle) {
/// 1. shouldn't call directly, because SliverGrid is building, if we call [setState] here will cause a exception
/// that hints circular build.
/// 2. when callback is called, the SliverGrid's state will call [setState], it'll rebuild all child by index, it means
/// that this callback will be added again and again! so add a condition to check loadingState so that make sure
/// the callback is added once.
SchedulerBinding.instance?.addPostFrameCallback((timeStamp) {
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
detailsPageLogic.loadMoreThumbnails();
});
}
Expand Down
9 changes: 7 additions & 2 deletions lib/src/pages/details/widget/stat_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class _StatDialogState extends State<StatDialog> {
noDataWidget: Text('invisible2UserWithoutDonation'.tr),
noDataTapCallback: _getGalleryStats,
),
if (loadingState == LoadingState.success && graphType == 'allTime')
FadeIn(key: const Key('1'), child: _allTimeGraph()).marginOnly(top: 24),
if (loadingState == LoadingState.success && graphType == 'allTime') FadeIn(key: const Key('1'), child: _allTimeGraph()).marginOnly(top: 24),
if (loadingState == LoadingState.success && graphType == 'year')
FadeIn(key: const Key('2'), child: _lineGraph(galleryStats.yearlyStats)).marginOnly(top: 24),
if (loadingState == LoadingState.success && graphType == 'month')
Expand All @@ -85,6 +84,9 @@ class _StatDialogState extends State<StatDialog> {
parser: EHSpiderParser.statPage2GalleryStats,
);
} on DioError catch (e) {
if (!mounted) {
return;
}
if (e.response?.statusCode == 404) {
Log.info('invisible2UserWithoutDonation'.tr, false);
setState(() {
Expand All @@ -100,6 +102,9 @@ class _StatDialogState extends State<StatDialog> {
return;
}

if (!mounted) {
return;
}
setState(() {
loadingState = LoadingState.success;
});
Expand Down
4 changes: 4 additions & 0 deletions lib/src/pages/home/home_page_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class HomePageLogic extends GetxController {
if (AdvancedSetting.enableCheckUpdate.isFalse) {
return;
}
/// todo: https://github.com/fluttercommunity/plus_plugins/issues/929
if (GetPlatform.isWindows) {
return;
}

String url = 'https://api.github.com/repos/jiangtian616/JHenTai/releases';
String latestVersion;
Expand Down

0 comments on commit b28d90b

Please sign in to comment.