mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: use canvas_danmaku
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/init.dart';
|
||||
import 'package:PiliPalaX/utils/event_bus.dart';
|
||||
import 'package:PiliPalaX/utils/id_utils.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class WebviewController extends GetxController {
|
||||
String url = '';
|
||||
RxString type = ''.obs;
|
||||
RxString pageTitle = ''.obs;
|
||||
String uaType = '';
|
||||
final WebViewController controller = WebViewController();
|
||||
RxInt loadProgress = 0.obs;
|
||||
RxBool loadShow = true.obs;
|
||||
EventBus eventBus = EventBus();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
url = Get.parameters['url'] ?? '';
|
||||
type.value = Get.parameters['type'] ?? '';
|
||||
pageTitle.value = Get.parameters['pageTitle'] ?? '';
|
||||
uaType = Get.parameters['uaType'] ?? 'mob';
|
||||
|
||||
webviewInit(uaType: uaType);
|
||||
}
|
||||
|
||||
webviewInit({String uaType = 'mob'}) {
|
||||
controller
|
||||
..setUserAgent(Request().headerUa(type: uaType))
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..enableZoom(true)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
// 页面加载
|
||||
onProgress: (int progress) {
|
||||
// Update loading bar.
|
||||
loadProgress.value = progress;
|
||||
},
|
||||
onPageStarted: (String url) {
|
||||
final parseUrl = Uri.parse(url);
|
||||
if (parseUrl.pathSegments.isEmpty) return;
|
||||
final String str = parseUrl.pathSegments[0];
|
||||
final Map matchRes = IdUtils.matchAvorBv(input: str);
|
||||
final List matchKeys = matchRes.keys.toList();
|
||||
if (matchKeys.isNotEmpty) {
|
||||
if (matchKeys.first == 'BV') {
|
||||
Get.offAndToNamed(
|
||||
'/searchResult',
|
||||
parameters: {'keyword': matchRes['BV']},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
onPageFinished: (String url) async {
|
||||
if (type.value == 'liveRoom') {
|
||||
//注入js
|
||||
controller.runJavaScriptReturningResult('''
|
||||
document.styleSheets[0].insertRule('div.open-app-btn.bili-btn-warp {display:none;}', 0);
|
||||
document.styleSheets[0].insertRule('#app__display-area > div.control-panel {display:none;}', 0);
|
||||
''').then((value) => debugPrint(value.toString()));
|
||||
} else if (type.value == 'whisper') {
|
||||
controller.runJavaScriptReturningResult('''
|
||||
document.querySelector('#internationalHeader').remove();
|
||||
document.querySelector('#message-navbar').remove();
|
||||
''').then((value) => debugPrint(value.toString()));
|
||||
}
|
||||
pageTitle.value = await controller.getTitle() ?? '';
|
||||
},
|
||||
// 加载完成
|
||||
onUrlChange: (UrlChange urlChange) async {
|
||||
loadShow.value = false;
|
||||
// String url = urlChange.url ?? '';
|
||||
},
|
||||
onWebResourceError: (WebResourceError error) {},
|
||||
onNavigationRequest: (NavigationRequest request) {
|
||||
if (request.url.startsWith('bilibili://')) {
|
||||
if (request.url.startsWith('bilibili://video/')) {
|
||||
String str = Uri.parse(request.url).pathSegments[0];
|
||||
Get.offAndToNamed(
|
||||
'/searchResult',
|
||||
parameters: {'keyword': str},
|
||||
);
|
||||
}
|
||||
return NavigationDecision.prevent;
|
||||
}
|
||||
return NavigationDecision.navigate;
|
||||
},
|
||||
),
|
||||
)
|
||||
..loadRequest(Uri.parse(url));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
library webview;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
@@ -1,110 +0,0 @@
|
||||
import 'package:PiliPalaX/utils/utils.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'controller.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class WebviewPage extends StatefulWidget {
|
||||
const WebviewPage({super.key});
|
||||
|
||||
@override
|
||||
State<WebviewPage> createState() => _WebviewPageState();
|
||||
}
|
||||
|
||||
class _WebviewPageState extends State<WebviewPage> {
|
||||
final WebviewController _webviewController = Get.put(WebviewController());
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Get.delete<WebviewController>();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Obx(
|
||||
() => Text(_webviewController.pageTitle.value),
|
||||
),
|
||||
actions: [
|
||||
const SizedBox(width: 4),
|
||||
IconButton(
|
||||
tooltip: '刷新网页',
|
||||
onPressed: () {
|
||||
_webviewController.controller.reload();
|
||||
},
|
||||
icon: Icon(Icons.refresh_outlined,
|
||||
color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '用外部浏览器打开',
|
||||
onPressed: () {
|
||||
Utils.launchURL(_webviewController.url);
|
||||
},
|
||||
icon: Icon(Icons.open_in_browser_outlined,
|
||||
color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
const SizedBox(width: 12)
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Obx(
|
||||
() => AnimatedContainer(
|
||||
curve: Curves.easeInOut,
|
||||
duration: const Duration(milliseconds: 350),
|
||||
height: _webviewController.loadShow.value ? 4 : 0,
|
||||
child: LinearProgressIndicator(
|
||||
key: ValueKey(_webviewController.loadProgress),
|
||||
value: _webviewController.loadProgress / 100,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_webviewController.type.value == 'login') ...<Widget>[
|
||||
Container(
|
||||
width: double.infinity,
|
||||
color: Theme.of(context).colorScheme.onInverseSurface,
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12, right: 12, top: 6, bottom: 6),
|
||||
child: const Text('登录成功未自动跳转? 请点击右上角「刷新登录态」'),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
color: Theme.of(context).colorScheme.onInverseSurface,
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12, right: 12, top: 6, bottom: 6),
|
||||
child: const Text(
|
||||
'如需二维码登录,请点击「电脑版」,放大左侧二维码,截图后官方app或另一设备扫码,授权后点击「刷新登录态」'),
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: SafeArea(
|
||||
child: WebViewWidget(
|
||||
controller: _webviewController.controller,
|
||||
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
|
||||
Factory<VerticalDragGestureRecognizer>(
|
||||
() => VerticalDragGestureRecognizer(),
|
||||
),
|
||||
Factory<PanGestureRecognizer>(
|
||||
() => PanGestureRecognizer(),
|
||||
),
|
||||
Factory<ForcePressGestureRecognizer>(
|
||||
() => ForcePressGestureRecognizer(),
|
||||
),
|
||||
Factory<EagerGestureRecognizer>(
|
||||
() => EagerGestureRecognizer(),
|
||||
),
|
||||
Factory<HorizontalDragGestureRecognizer>(
|
||||
() => HorizontalDragGestureRecognizer(),
|
||||
),
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user