Skip to content

Commit

Permalink
增加刷新和退出过盾按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
xioxin authored and honjow committed Feb 21, 2023
1 parent 1b3d4c2 commit 0b311fe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
27 changes: 24 additions & 3 deletions lib/component/widget/broken_shield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:dio/dio.dart';
import 'package:eros_n/component/widget/web_view.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../common/const/const.dart';
import '../../common/global.dart';
Expand Down Expand Up @@ -77,7 +76,7 @@ class _BrokenShieldState extends State<BrokenShield> {
}
return Padding(
padding: EdgeInsets.only(
top: Platform.isWindows ? appWindow.titleBarHeight : 0),
top: (Platform.isWindows && showWebView) ? appWindow.titleBarHeight : 0),
child: Container(
color: Colors.black54,
child: Stack(
Expand Down Expand Up @@ -153,10 +152,32 @@ class _BrokenShieldState extends State<BrokenShield> {
}
}

GlobalKey<GetCookieWebViewState> webViewState = GlobalKey();

Widget webView() {
return Scaffold(
appBar: AppBar(title: Text("安全挑战")),
appBar: AppBar(
leading: IconButton(
icon: BackButtonIcon(),
onPressed: () {
pendingConnections.clear();
pendingConnectionsChangeCtrl.sink.add(null);
entry?.remove();
entry = null;
if (completer != null && completer!.isCompleted == false) {
completer?.completeError(Exception('用户终止了挑战'));
}
},
),
title: Text("安全挑战"),
actions: [
IconButton(icon: const Icon(Icons.refresh), onPressed: () {
webViewState.currentState?.reload();
})
],
),
body: GetCookieWebView(
key: webViewState,
callback: injectionCookieAndUA,
url: NHConst.baseUrl,
),
Expand Down
34 changes: 29 additions & 5 deletions lib/component/widget/web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class _MobileWebViewState extends State<MobileWebView> {

InAppWebViewController? _controller;

Future reload() async {
await _controller?.reload();
}

@override
Widget build(BuildContext context) {
if (initOk) {
Expand Down Expand Up @@ -174,6 +178,10 @@ class _WindowsWebViewState extends State<WindowsWebView> {

Timer? anomalyTimer;

Future reload() {
return _controller.reload();
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -317,7 +325,7 @@ class _WindowsWebViewState extends State<WindowsWebView> {
}
}

class GetCookieWebView extends StatelessWidget {
class GetCookieWebView extends StatefulWidget {
const GetCookieWebView({
required this.url,
this.callback,
Expand All @@ -329,18 +337,34 @@ class GetCookieWebView extends StatelessWidget {
final WebViewCallback? callback;
final bool deletedCookie;

@override
State<GetCookieWebView> createState() => GetCookieWebViewState();
}

class GetCookieWebViewState extends State<GetCookieWebView> {


GlobalKey<_MobileWebViewState> mobileState = GlobalKey();
GlobalKey<_WindowsWebViewState> windowsState = GlobalKey();

Future reload() async {
await mobileState.currentState?.reload();
await windowsState.currentState?.reload();
}

@override
Widget build(BuildContext context) {
switch (Platform.operatingSystem) {
case 'ios':
case 'android':
return MobileWebView(
url: url,
callback: callback,
deletedCookie: deletedCookie,
key: mobileState,
url: widget.url,
callback: widget.callback,
deletedCookie: widget.deletedCookie,
);
case 'windows':
return WindowsWebView(url: url, callback: callback);
return WindowsWebView(key: windowsState, url: widget.url, callback: widget.callback);
default:
throw UnimplementedError();
}
Expand Down

0 comments on commit 0b311fe

Please sign in to comment.