From f4e94ea9701fe8ba91e91b195859f0d20d01bbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Fri, 15 Nov 2024 09:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E8=83=8C=E6=99=AF=E7=BD=AE?= =?UTF-8?q?=E7=99=BD=EF=BC=8C=E8=AF=86=E5=88=AB=E5=9C=A8=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E8=BF=9B=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/win/plugins/miyoushe_webview.dart | 29 +++++++++++++++++++-------- lib/win/widgets/app_nav.dart | 7 ------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/win/plugins/miyoushe_webview.dart b/lib/win/plugins/miyoushe_webview.dart index 463190e..565f344 100644 --- a/lib/win/plugins/miyoushe_webview.dart +++ b/lib/win/plugins/miyoushe_webview.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart' show Icons; // Package imports: import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:url_launcher/url_launcher_string.dart'; import 'package:webview_windows/webview_windows.dart'; // Project imports: @@ -17,6 +18,7 @@ import '../../models/bbs/bridge/bbs_bridge_model.dart'; import '../../plugins/Miyoushe/bridge_handler.dart'; import '../../plugins/Miyoushe/miyoushe_webview.dart'; import '../../shared/tools/log_tool.dart'; +import '../ui/sp_infobar.dart'; class MysControllerWin extends ChangeNotifier implements MiyousheController { @override @@ -53,6 +55,11 @@ class MysControllerWin extends ChangeNotifier implements MiyousheController { double? height, String? userAgent, }) async { + // 检测是否支持 + if (await WebviewController.getWebViewVersion() == null) { + if (context.mounted) await SpInfobar.error(context, '未检测到 WebView2运行时'); + return; + } this.url = url; this.width = width ?? 400; this.height = height ?? 600; @@ -65,7 +72,7 @@ class MysControllerWin extends ChangeNotifier implements MiyousheController { await webview.setUserAgent(this.userAgent); await webview.loadUrl(url); await loadJSBridge(); - await webview.setBackgroundColor(Colors.transparent); + await webview.setBackgroundColor(Colors.white); await webview.setPopupWindowPolicy(WebviewPopupWindowPolicy.deny); notifyListeners(); } @@ -114,11 +121,13 @@ class MysControllerWin extends ChangeNotifier implements MiyousheController { @override Future loadUrl(String url) async { await webview.loadUrl(url); + await webview.setBackgroundColor(Colors.white); } Future reload() async { await webview.reload(); await loadJSBridge(); + await webview.setBackgroundColor(Colors.white); } @override @@ -141,6 +150,17 @@ class MysControllerWin extends ChangeNotifier implements MiyousheController { icon: const Icon(Icons.developer_mode), onPressed: webview.openDevTools, ), + IconButton( + icon: const Icon(FluentIcons.edge_logo), + onPressed: () async { + var urlCur = routeStack.last; + if (await canLaunchUrlString(urlCur)) { + await launchUrlString(urlCur); + return; + } + if (context.mounted) await SpInfobar.error(context, '无法打开链接'); + }, + ), IconButton( icon: const Icon(FluentIcons.chrome_close), onPressed: () => Navigator.pop(context), @@ -213,13 +233,6 @@ class MysClientWin extends ConsumerStatefulWidget { return create(context, link, width: width, height: height); } - static Future check() async { - if (defaultTargetPlatform == TargetPlatform.windows) { - return await WebviewController.getWebViewVersion() != null; - } - return false; - } - @override ConsumerState createState() => _MysClientWinState(); } diff --git a/lib/win/widgets/app_nav.dart b/lib/win/widgets/app_nav.dart index 9a0d2d2..d36f127 100644 --- a/lib/win/widgets/app_nav.dart +++ b/lib/win/widgets/app_nav.dart @@ -179,13 +179,6 @@ class _AppNavWidgetState extends ConsumerState leading: SPIcon(FluentIcons.giftbox), text: const Text('签到'), onPressed: () async { - var check = await MysClientWin.check(); - if (!check) { - if (mounted) { - await SpInfobar.error(context, '未检测到webview2Runtime'); - } - return; - } if (mounted) { controller = await MysClientWin.createSign(context); if (mounted) await controller.show(context);