Skip to content

Commit

Permalink
🎨 背景置白,识别在初始化进行
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Nov 15, 2024
1 parent 9529b3c commit f4e94ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
29 changes: 21 additions & 8 deletions lib/win/plugins/miyoushe_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -114,11 +121,13 @@ class MysControllerWin extends ChangeNotifier implements MiyousheController {
@override
Future<void> loadUrl(String url) async {
await webview.loadUrl(url);
await webview.setBackgroundColor(Colors.white);
}

Future<void> reload() async {
await webview.reload();
await loadJSBridge();
await webview.setBackgroundColor(Colors.white);
}

@override
Expand All @@ -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),
Expand Down Expand Up @@ -213,13 +233,6 @@ class MysClientWin extends ConsumerStatefulWidget {
return create(context, link, width: width, height: height);
}

static Future<bool> check() async {
if (defaultTargetPlatform == TargetPlatform.windows) {
return await WebviewController.getWebViewVersion() != null;
}
return false;
}

@override
ConsumerState<MysClientWin> createState() => _MysClientWinState();
}
Expand Down
7 changes: 0 additions & 7 deletions lib/win/widgets/app_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,6 @@ class _AppNavWidgetState extends ConsumerState<AppNavWidget>
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);
Expand Down

0 comments on commit f4e94ea

Please sign in to comment.