diff --git a/lib/pages/html/view.dart b/lib/pages/html/view.dart index 26675ea7..c16df1fb 100644 --- a/lib/pages/html/view.dart +++ b/lib/pages/html/view.dart @@ -230,9 +230,9 @@ class _HtmlRenderPageState extends State ), ), IconButton( - tooltip: '用内置浏览器打开', + tooltip: '浏览器打开', onPressed: () { - Utils.handleWebview(url.startsWith('http') ? url : 'https:$url'); + Utils.inAppWebview(url.startsWith('http') ? url : 'https:$url'); }, icon: const Icon(Icons.open_in_browser_outlined, size: 19), ), @@ -253,9 +253,9 @@ class _HtmlRenderPageState extends State ), ), PopupMenuItem( - onTap: () => { - Utils.handleWebview( - url.startsWith('http') ? url : 'https:$url') + onTap: () { + Utils.inAppWebview( + url.startsWith('http') ? url : 'https:$url'); }, child: const Row( mainAxisSize: MainAxisSize.min, diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index 5a911d60..4cfe88ce 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -298,7 +298,7 @@ class _LiveRoomPageState extends State IconButton( tooltip: '浏览器打开', onPressed: () { - Utils.handleWebview( + Utils.inAppWebview( 'https://live.bilibili.com/h5/${_liveRoomController.roomId}', off: true, ); diff --git a/lib/pages/webview/webview_page.dart b/lib/pages/webview/webview_page.dart index 3ee50929..d64765f4 100644 --- a/lib/pages/webview/webview_page.dart +++ b/lib/pages/webview/webview_page.dart @@ -44,9 +44,18 @@ class _WebviewPageNewState extends State { final uaType = Get.parameters['uaType'] ?? 'mob'; final _titleStream = StreamController(); final _progressStream = StreamController(); + bool? _inApp; InAppWebViewController? _webViewController; + @override + void initState() { + super.initState(); + if (Get.arguments is Map) { + _inApp = Get.arguments['inApp']; + } + } + @override void dispose() { _titleStream.close(); @@ -235,6 +244,9 @@ class _WebviewPageNewState extends State { } : null, shouldOverrideUrlLoading: (controller, navigationAction) async { + if (_inApp == false) { + return NavigationActionPolicy.ALLOW; + } late String url = navigationAction.request.url.toString(); bool hasMatch = await PiliScheme.routePush( navigationAction.request.url?.uriValue ?? Uri(), diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 61d77d90..bb749ae9 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -420,6 +420,29 @@ class Utils { ); } + static void inAppWebview( + String url, { + bool off = false, + }) { + if (GStorage.openInBrowser) { + launchURL(url); + } else { + if (off) { + Get.offNamed( + '/webview', + parameters: {'url': url}, + arguments: {'inApp': true}, + ); + } else { + Get.toNamed( + '/webview', + parameters: {'url': url}, + arguments: {'inApp': true}, + ); + } + } + } + static void handleWebview( String url, { bool off = false,