mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: webview: reset cookie
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -4,7 +4,6 @@ import 'package:PiliPlus/build_config.dart';
|
|||||||
import 'package:PiliPlus/http/constants.dart';
|
import 'package:PiliPlus/http/constants.dart';
|
||||||
import 'package:PiliPlus/services/loggeer.dart';
|
import 'package:PiliPlus/services/loggeer.dart';
|
||||||
import 'package:cookie_jar/cookie_jar.dart';
|
import 'package:cookie_jar/cookie_jar.dart';
|
||||||
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
@@ -13,6 +12,7 @@ import 'package:package_info_plus/package_info_plus.dart';
|
|||||||
import 'package:PiliPlus/models/github/latest.dart';
|
import 'package:PiliPlus/models/github/latest.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
|
import '../../http/init.dart';
|
||||||
import '../../utils/cache_manage.dart';
|
import '../../utils/cache_manage.dart';
|
||||||
|
|
||||||
class AboutPage extends StatefulWidget {
|
class AboutPage extends StatefulWidget {
|
||||||
@@ -223,11 +223,7 @@ Commit Hash: ${BuildConfig.commitHash}''',
|
|||||||
Get.back();
|
Get.back();
|
||||||
dynamic accessKey = GStorage.localCache
|
dynamic accessKey = GStorage.localCache
|
||||||
.get(LocalCacheKey.accessKey, defaultValue: {});
|
.get(LocalCacheKey.accessKey, defaultValue: {});
|
||||||
dynamic cookies = (await CookieManager(PersistCookieJar(
|
dynamic cookies = (await Request.cookieManager.cookieJar
|
||||||
ignoreExpires: true,
|
|
||||||
storage: FileStorage(await Utils.getCookiePath()),
|
|
||||||
))
|
|
||||||
.cookieJar
|
|
||||||
.loadForRequest(Uri.parse(HttpString.baseUrl)))
|
.loadForRequest(Uri.parse(HttpString.baseUrl)))
|
||||||
.map(
|
.map(
|
||||||
(Cookie cookie) => {
|
(Cookie cookie) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:PiliPlus/http/constants.dart';
|
||||||
import 'package:PiliPlus/http/init.dart';
|
import 'package:PiliPlus/http/init.dart';
|
||||||
import 'package:PiliPlus/utils/id_utils.dart';
|
import 'package:PiliPlus/utils/id_utils.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
@@ -7,15 +8,24 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:cookie_jar/cookie_jar.dart' as cookie_jar;
|
||||||
|
|
||||||
enum WebviewMenuItem { refresh, copy, openInBrowser, clearCache, goBack }
|
enum _WebviewMenuItem {
|
||||||
|
refresh,
|
||||||
|
copy,
|
||||||
|
openInBrowser,
|
||||||
|
clearCache,
|
||||||
|
resetCookie,
|
||||||
|
goBack,
|
||||||
|
}
|
||||||
|
|
||||||
extension WebviewMenuItemExt on WebviewMenuItem {
|
extension _WebviewMenuItemExt on _WebviewMenuItem {
|
||||||
String get title => [
|
String get title => [
|
||||||
'刷新',
|
'刷新',
|
||||||
'复制链接',
|
'复制链接',
|
||||||
'浏览器中打开',
|
'浏览器中打开',
|
||||||
'清除缓存',
|
'清除缓存',
|
||||||
|
'重新设置Cookie',
|
||||||
'返回',
|
'返回',
|
||||||
][index];
|
][index];
|
||||||
}
|
}
|
||||||
@@ -72,22 +82,22 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
PopupMenuButton(
|
PopupMenuButton(
|
||||||
onSelected: (item) async {
|
onSelected: (item) async {
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case WebviewMenuItem.refresh:
|
case _WebviewMenuItem.refresh:
|
||||||
_webViewController?.reload();
|
_webViewController?.reload();
|
||||||
break;
|
break;
|
||||||
case WebviewMenuItem.copy:
|
case _WebviewMenuItem.copy:
|
||||||
WebUri? uri = await _webViewController?.getUrl();
|
WebUri? uri = await _webViewController?.getUrl();
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
Utils.copyText(uri.toString());
|
Utils.copyText(uri.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WebviewMenuItem.openInBrowser:
|
case _WebviewMenuItem.openInBrowser:
|
||||||
WebUri? uri = await _webViewController?.getUrl();
|
WebUri? uri = await _webViewController?.getUrl();
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
Utils.launchURL(uri.toString());
|
Utils.launchURL(uri.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WebviewMenuItem.clearCache:
|
case _WebviewMenuItem.clearCache:
|
||||||
try {
|
try {
|
||||||
await InAppWebViewController.clearAllCache();
|
await InAppWebViewController.clearAllCache();
|
||||||
await _webViewController?.clearHistory();
|
await _webViewController?.clearHistory();
|
||||||
@@ -96,23 +106,39 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
SmartDialog.showToast(e.toString());
|
SmartDialog.showToast(e.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WebviewMenuItem.goBack:
|
case _WebviewMenuItem.goBack:
|
||||||
if (await _webViewController?.canGoBack() == true) {
|
if (await _webViewController?.canGoBack() == true) {
|
||||||
_webViewController?.goBack();
|
_webViewController?.goBack();
|
||||||
} else {
|
} else {
|
||||||
Get.back();
|
Get.back();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case _WebviewMenuItem.resetCookie:
|
||||||
|
final List<cookie_jar.Cookie> cookies = await Request
|
||||||
|
.cookieManager.cookieJar
|
||||||
|
.loadForRequest(Uri.parse(HttpString.baseUrl));
|
||||||
|
for (cookie_jar.Cookie item in cookies) {
|
||||||
|
await CookieManager().setCookie(
|
||||||
|
url: WebUri(item.domain ?? ''),
|
||||||
|
name: item.name,
|
||||||
|
value: item.value,
|
||||||
|
path: item.path ?? '',
|
||||||
|
domain: item.domain,
|
||||||
|
isSecure: item.secure,
|
||||||
|
isHttpOnly: item.httpOnly,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
itemBuilder: (context) => <PopupMenuEntry<WebviewMenuItem>>[
|
itemBuilder: (context) => <PopupMenuEntry<_WebviewMenuItem>>[
|
||||||
...WebviewMenuItem.values.sublist(0, 4).map((item) =>
|
..._WebviewMenuItem.values.sublist(0, 4).map((item) =>
|
||||||
PopupMenuItem(value: item, child: Text(item.title))),
|
PopupMenuItem(value: item, child: Text(item.title))),
|
||||||
const PopupMenuDivider(),
|
const PopupMenuDivider(),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: WebviewMenuItem.goBack,
|
value: _WebviewMenuItem.goBack,
|
||||||
child: Text(
|
child: Text(
|
||||||
WebviewMenuItem.goBack.title,
|
_WebviewMenuItem.goBack.title,
|
||||||
style:
|
style:
|
||||||
TextStyle(color: Theme.of(context).colorScheme.error),
|
TextStyle(color: Theme.of(context).colorScheme.error),
|
||||||
)),
|
)),
|
||||||
|
|||||||
Reference in New Issue
Block a user