opt: in-app webview

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-15 12:26:44 +08:00
parent 4b48aba2ae
commit d9611cce80
4 changed files with 41 additions and 6 deletions

View File

@@ -230,9 +230,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
),
),
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<HtmlRenderPage>
),
),
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,

View File

@@ -298,7 +298,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
IconButton(
tooltip: '浏览器打开',
onPressed: () {
Utils.handleWebview(
Utils.inAppWebview(
'https://live.bilibili.com/h5/${_liveRoomController.roomId}',
off: true,
);

View File

@@ -44,9 +44,18 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
final uaType = Get.parameters['uaType'] ?? 'mob';
final _titleStream = StreamController<String?>();
final _progressStream = StreamController<double>();
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<WebviewPageNew> {
}
: 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(),

View File

@@ -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,