mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: in-app webview
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -230,9 +230,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: '用内置浏览器打开',
|
tooltip: '浏览器打开',
|
||||||
onPressed: () {
|
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),
|
icon: const Icon(Icons.open_in_browser_outlined, size: 19),
|
||||||
),
|
),
|
||||||
@@ -253,9 +253,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
onTap: () => {
|
onTap: () {
|
||||||
Utils.handleWebview(
|
Utils.inAppWebview(
|
||||||
url.startsWith('http') ? url : 'https:$url')
|
url.startsWith('http') ? url : 'https:$url');
|
||||||
},
|
},
|
||||||
child: const Row(
|
child: const Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
|||||||
IconButton(
|
IconButton(
|
||||||
tooltip: '浏览器打开',
|
tooltip: '浏览器打开',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Utils.handleWebview(
|
Utils.inAppWebview(
|
||||||
'https://live.bilibili.com/h5/${_liveRoomController.roomId}',
|
'https://live.bilibili.com/h5/${_liveRoomController.roomId}',
|
||||||
off: true,
|
off: true,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -44,9 +44,18 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
final uaType = Get.parameters['uaType'] ?? 'mob';
|
final uaType = Get.parameters['uaType'] ?? 'mob';
|
||||||
final _titleStream = StreamController<String?>();
|
final _titleStream = StreamController<String?>();
|
||||||
final _progressStream = StreamController<double>();
|
final _progressStream = StreamController<double>();
|
||||||
|
bool? _inApp;
|
||||||
|
|
||||||
InAppWebViewController? _webViewController;
|
InAppWebViewController? _webViewController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (Get.arguments is Map) {
|
||||||
|
_inApp = Get.arguments['inApp'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_titleStream.close();
|
_titleStream.close();
|
||||||
@@ -235,6 +244,9 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
shouldOverrideUrlLoading: (controller, navigationAction) async {
|
||||||
|
if (_inApp == false) {
|
||||||
|
return NavigationActionPolicy.ALLOW;
|
||||||
|
}
|
||||||
late String url = navigationAction.request.url.toString();
|
late String url = navigationAction.request.url.toString();
|
||||||
bool hasMatch = await PiliScheme.routePush(
|
bool hasMatch = await PiliScheme.routePush(
|
||||||
navigationAction.request.url?.uriValue ?? Uri(),
|
navigationAction.request.url?.uriValue ?? Uri(),
|
||||||
|
|||||||
@@ -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(
|
static void handleWebview(
|
||||||
String url, {
|
String url, {
|
||||||
bool off = false,
|
bool off = false,
|
||||||
|
|||||||
Reference in New Issue
Block a user