Skip to content

Commit

Permalink
Fix web login
Browse files Browse the repository at this point in the history
  • Loading branch information
3003h committed Apr 3, 2024
1 parent 4efc7ad commit 98ea42d
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 213 deletions.
6 changes: 5 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ def _storePassword = System.getenv("KEYSTORE_PASSWORD") ?: keystoreProperties.ge
android {
ndkVersion "25.2.9519653"
compileSdkVersion 34
namespace 'com.honjow.fehviewer'

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

// kotlin {
// jvmToolchain(8)
// }

defaultConfig {
applicationId "com.honjow.fehviewer"
Expand Down Expand Up @@ -100,7 +104,7 @@ android {
shrinkResources true
}
}
namespace 'com.honjow.fehviewer'

lint {
disable 'InvalidPackage'
}
Expand Down
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.4.2" apply false
id "com.android.application" version '7.4.2' apply false
id "org.jetbrains.kotlin.android" version "1.7.20" apply false
id "com.google.gms.google-services" version "4.4.0" apply false
id "com.google.firebase.crashlytics" version "2.9.9" apply false
Expand Down
13 changes: 13 additions & 0 deletions changelog/v1.6.1+541.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

## 🐛 修正

- 修复 Web 登陆页中无法跳转 recapture 的问题 #357

---


## 🐛 Fixes

- Fix the issue of unable to redirect to recapture on the web login page.


2 changes: 1 addition & 1 deletion lib/common/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:io';

import 'package:collection/collection.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:device_info/device_info.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
import 'package:eros_fe/common/service/ehsetting_service.dart';
import 'package:eros_fe/const/storages.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/const/const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class EHConst {

static const int sumCats = 1023;
static const Map<String, int> cats = {
'Misc': 1,
'Doujinshi': 2,
'Manga': 4,
'Artist CG': 8,
Expand All @@ -387,7 +388,6 @@ class EHConst {
'Image Set': 32,
'Cosplay': 64,
'Asian Porn': 128,
'Misc': 1,
};

static List<String> catList = <String>[
Expand Down
2 changes: 1 addition & 1 deletion lib/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extension ExtGalleryProvider on GalleryProvider {
favcat: item.favcat?.oN,
localFav: item.localFav?.oN,
simpleTags: item.simpleTags?.oN,
tagsFromApi: item.tagsFromApi?.toList()?.oN,
tagsFromApi: item.tagsFromApi?.toList().oN,
translated: item.translated?.oN,
tagGroup: item.tagGroup?.oN,
galleryComment: item.galleryComment?.oN,
Expand Down
44 changes: 14 additions & 30 deletions lib/pages/login/view/web_login_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import 'package:eros_fe/utils/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';
import 'package:webview_cookie_manager/webview_cookie_manager.dart';

class WebLoginViewIn extends StatelessWidget {
WebLoginViewIn({
Key? key,
}) : super(key: key);
super.key,
});

final CookieManager _cookieManager = CookieManager.instance();

@override
Widget build(BuildContext context) {
final String title = L10n.of(context).login_web;
InAppWebViewController _controller;
final WebviewCookieManager cookieManager = WebviewCookieManager();

final InAppWebViewSettings settings = InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
Expand All @@ -36,39 +33,26 @@ class WebLoginViewIn extends StatelessWidget {
child: InAppWebView(
initialUrlRequest: URLRequest(url: WebUri(EHConst.URL_SIGN_IN)),
initialSettings: settings,
onWebViewCreated: (InAppWebViewController webViewController) {
_controller = webViewController;
},
onWebViewCreated: (InAppWebViewController webViewController) {},
onPermissionRequest: (controller, permissionRequest) async {
return PermissionResponse(action: PermissionResponseAction.GRANT);
},
// onLoadStart: (InAppWebViewController controller, Uri? url) {
// logger.d('Page started loading: $url');
//
// if (url == null) {
// return;
// }
//
// if (!(url.path == '/uconfig.php') && !(url.path == '/index.php')) {
// logger.d('阻止打开 $url');
// controller.stopLoading();
// }
// },
shouldOverrideUrlLoading: (controller, navigationAction) async {
final uri = navigationAction.request.url!;

final act = uri.queryParameters['act'];
// final act = uri.queryParameters['act'];

logger.d('to $uri');
if (uri.path == '/index.php' && act != null && act != 'Login') {
logger.d('阻止打开 $uri');
return NavigationActionPolicy.CANCEL;
} else if (uri.path == '/uconfig.php' || uri.path == '/index.php') {
return NavigationActionPolicy.ALLOW;
}

logger.d('阻止打开 $uri');
return NavigationActionPolicy.CANCEL;
// if (uri.path == '/index.php' && act != null && act != 'Login') {
// logger.d('阻止打开 $uri');
// return NavigationActionPolicy.CANCEL;
// } else if (uri.path == '/uconfig.php' || uri.path == '/index.php') {
// return NavigationActionPolicy.ALLOW;
// }
//
// logger.d('阻止打开 $uri');
// return NavigationActionPolicy.CANCEL;
return NavigationActionPolicy.ALLOW;
},
onLoadStop: (InAppWebViewController controller, Uri? uri) async {
logger.d('Page Finished loading: $uri');
Expand Down
16 changes: 5 additions & 11 deletions lib/pages/setting/webview/eh_webview.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

final InAppWebViewGroupOptions inAppWebViewOptions = InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),
ios: IOSInAppWebViewOptions(
allowsInlineMediaPlayback: true,
));
final InAppWebViewSettings inAppWebViewSettings = InAppWebViewSettings(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
useHybridComposition: true,
allowsInlineMediaPlayback: true);
28 changes: 4 additions & 24 deletions lib/pages/setting/webview/mytags_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@ import 'package:eros_fe/network/api.dart';
import 'package:eros_fe/pages/setting/controller/web_setting_controller.dart';
import 'package:eros_fe/utils/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart' hide WebView;
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';

import 'eh_webview.dart';

class InWebMyTags extends StatelessWidget {
// final CookieManager _cookieManager = CookieManager.instance();
//
// Future<void> _setCookie() async {
// final List<io.Cookie>? cookies =
// await Global.cookieJar?.loadForRequest(Uri.parse(Api.getBaseUrl()));
//
// for (final io.Cookie cookie in cookies ?? []) {
// _cookieManager.setCookie(
// url: Uri.parse(Api.getBaseUrl()),
// name: cookie.name,
// value: cookie.value);
// }
// }
const InWebMyTags({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -38,7 +26,7 @@ class InWebMyTags extends StatelessWidget {
CupertinoButton(
padding: const EdgeInsets.all(0),
child: const Icon(
FontAwesomeIcons.redoAlt,
FontAwesomeIcons.rotateRight,
size: 22,
),
onPressed: () async {
Expand All @@ -55,15 +43,7 @@ class InWebMyTags extends StatelessWidget {
onWebViewCreated: (InAppWebViewController controller) {
_controller = controller;
},
initialOptions: inAppWebViewOptions,
// onLoadStart: (InAppWebViewController controller, Uri? url) {
// logger.d('Page started loading: $url');
//
// if (!url.toString().endsWith('/mytags')) {
// logger.d('阻止打开 $url');
// controller.stopLoading();
// }
// },
initialSettings: inAppWebViewSettings,
shouldOverrideUrlLoading: (controller, navigationAction) async {
final uri = navigationAction.request.url!;

Expand Down
46 changes: 13 additions & 33 deletions lib/pages/setting/webview/web_mysetting_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import 'package:eros_fe/network/api.dart';
import 'package:eros_fe/pages/setting/controller/web_setting_controller.dart';
import 'package:eros_fe/utils/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart' hide WebView;
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';

import 'eh_webview.dart';

class InWebMySetting extends StatelessWidget {
final CookieManager _cookieManager = CookieManager.instance();
final EhSettingService ehSettingService = Get.find();
const InWebMySetting({super.key});

@override
Widget build(BuildContext context) {
InAppWebViewController? _controller;
final CookieManager cookieManager = CookieManager.instance();
final EhSettingService ehSettingService = Get.find();

InAppWebViewController? controller;

final baseUrl = Api.getBaseUrl();

Expand All @@ -43,7 +45,7 @@ class InWebMySetting extends StatelessWidget {
size: 22,
),
onPressed: () async {
_controller?.reload();
controller?.reload();
},
),
CupertinoButton(
Expand All @@ -54,7 +56,7 @@ class InWebMySetting extends StatelessWidget {
),
onPressed: () async {
// 保存配置
_controller?.evaluateJavascript(
controller?.evaluateJavascript(
source:
'document.querySelector("#apply > input[type=submit]").click();');
},
Expand All @@ -70,18 +72,14 @@ class InWebMySetting extends StatelessWidget {
),
// headers: _httpHeaders,
),
initialOptions: inAppWebViewOptions,
initialSettings: inAppWebViewSettings,
onWebViewCreated: (InAppWebViewController controller) {
_controller = controller;
controller = controller;
},
shouldOverrideUrlLoading: (controller, navigationAction) async {
final uri = navigationAction.request.url!;

logger.d('to $uri');
// if (!(uri.path == '/uconfig.php')) {
// logger.d('阻止打开 $uri');
// return NavigationActionPolicy.CANCEL;
// }
if (uri.host != Api.getBaseHost()) {
logger.d('阻止打开 $uri');
return NavigationActionPolicy.CANCEL;
Expand All @@ -96,10 +94,10 @@ class InWebMySetting extends StatelessWidget {
}

// 写入cookie到dio
final _cookies =
await _cookieManager.getCookies(url: WebUri.uri(url));
final cookies =
await cookieManager.getCookies(url: WebUri.uri(url));

final ioCookies = _cookies
final ioCookies = cookies
.map((e) => io.Cookie(e.name, e.value as String)
..domain = e.domain
..path = e.path
Expand All @@ -114,24 +112,6 @@ class InWebMySetting extends StatelessWidget {
.firstWhereOrNull((element) => element.name == 'sp')
?.value ??
'';

// _cookieManager.getCookies(url: url).then((value) {
// final List<io.Cookie> _cookies = value
// .map((Cookie e) =>
// io.Cookie(e.name, e.value as String)..domain = e.domain)
// .toList();
//
// logger.d('${_cookies.map((e) => e.toString()).join('\n')} ');
//
// Global.cookieJar.delete(Uri.parse(Api.getBaseUrl()), true);
// Global.cookieJar
// .saveFromResponse(Uri.parse(Api.getBaseUrl()), _cookies);
//
// ehSettingService.selectProfile = _cookies
// .firstWhereOrNull((element) => element.name == 'sp')
// ?.value ??
// '';
// });
},
),
),
Expand Down
Loading

0 comments on commit 98ea42d

Please sign in to comment.