mod: scheme match

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-13 17:51:52 +08:00
parent 2b9cb54d91
commit 84cc65489f
2 changed files with 21 additions and 31 deletions

View File

@@ -5,6 +5,7 @@ import 'package:PiliPlus/common/widgets/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/tabs.dart'; import 'package:PiliPlus/common/widgets/tabs.dart';
import 'package:PiliPlus/grpc/grpc_client.dart'; import 'package:PiliPlus/grpc/grpc_client.dart';
import 'package:PiliPlus/pages/mine/controller.dart'; import 'package:PiliPlus/pages/mine/controller.dart';
import 'package:PiliPlus/utils/app_scheme.dart';
import 'package:PiliPlus/utils/utils.dart'; import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@@ -156,6 +157,7 @@ class _MainAppState extends State<MainApp>
await GrpcClient.instance.shutdown(); await GrpcClient.instance.shutdown();
await GStorage.close(); await GStorage.close();
EventBus().off(EventName.loginEvent); EventBus().off(EventName.loginEvent);
PiliScheme.listener?.cancel();
super.dispose(); super.dispose();
} }

View File

@@ -15,12 +15,15 @@ import 'utils.dart';
class PiliScheme { class PiliScheme {
static late AppLinks appLinks; static late AppLinks appLinks;
static StreamSubscription? listener;
static Future<void> init() async { static Future<void> init() async {
// Register our protocol only on Windows platform // Register our protocol only on Windows platform
// registerProtocolHandler('bilibili'); // registerProtocolHandler('bilibili');
appLinks = AppLinks(); appLinks = AppLinks();
appLinks.uriLinkStream.listen((uri) { listener?.cancel();
listener = appLinks.uriLinkStream.listen((uri) {
debugPrint('onAppLink: $uri'); debugPrint('onAppLink: $uri');
routePush(uri); routePush(uri);
}); });
@@ -53,12 +56,6 @@ class PiliScheme {
final String host = uri.host.toLowerCase(); final String host = uri.host.toLowerCase();
final String path = uri.path; final String path = uri.path;
void launchURL() {
if (selfHandle.not) {
Utils.launchURL(uri.toString());
}
}
switch (scheme) { switch (scheme) {
case 'bilibili': case 'bilibili':
switch (host) { switch (host) {
@@ -68,6 +65,18 @@ class PiliScheme {
(Route<dynamic> route) => route.isFirst, (Route<dynamic> route) => route.isFirst,
); );
return true; return true;
case 'pgc':
// bilibili://pgc/season/ep/123456?h5_awaken_params=random
String? id = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
if (id != null) {
bool isEp = path.contains('/ep/');
Utils.viewBangumi(
seasonId: isEp ? null : id,
epId: isEp ? id : null,
);
return true;
}
return false;
case 'space': case 'space':
// bilibili://space/12345678?frommodule=XX&h5awaken=random // bilibili://space/12345678?frommodule=XX&h5awaken=random
String? mid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? mid = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
@@ -75,7 +84,6 @@ class PiliScheme {
Utils.toDupNamed('/member?mid=$mid', off: off); Utils.toDupNamed('/member?mid=$mid', off: off);
return true; return true;
} }
launchURL();
return false; return false;
case 'video': case 'video':
if (uri.queryParameters['comment_root_id'] != null) { if (uri.queryParameters['comment_root_id'] != null) {
@@ -113,7 +121,6 @@ class PiliScheme {
); );
return true; return true;
} }
launchURL();
return false; return false;
} }
@@ -131,7 +138,6 @@ class PiliScheme {
); );
return true; return true;
} }
launchURL();
return false; return false;
case 'live': case 'live':
// bilibili://live/12345678?extra_jump_from=1&from=1&is_room_feed=1&h5awaken=random // bilibili://live/12345678?extra_jump_from=1&from=1&is_room_feed=1&h5awaken=random
@@ -140,10 +146,9 @@ class PiliScheme {
Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off); Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off);
return true; return true;
} }
launchURL();
return false; return false;
case 'bangumi': case 'bangumi':
// to check // bilibili://bangumi/season/12345678?h5_awaken_params=random
if (path.startsWith('/season')) { if (path.startsWith('/season')) {
String? seasonId = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? seasonId = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
if (seasonId != null) { if (seasonId != null) {
@@ -151,18 +156,13 @@ class PiliScheme {
return true; return true;
} }
} }
launchURL();
return false; return false;
case 'opus': case 'opus':
// bilibili://opus/detail/12345678?h5awaken=random // bilibili://opus/detail/12345678?h5awaken=random
if (path.startsWith('/detail')) { if (path.startsWith('/detail')) {
bool hasMatch = await _onPushDynDetail(path, off); bool hasMatch = await _onPushDynDetail(path, off);
if (hasMatch.not) {
launchURL();
}
return hasMatch; return hasMatch;
} }
launchURL();
return false; return false;
case 'search': case 'search':
Utils.toDupNamed( Utils.toDupNamed(
@@ -187,7 +187,6 @@ class PiliScheme {
); );
return true; return true;
} }
launchURL();
return false; return false;
case 'comment': case 'comment':
if (path.startsWith("/detail/")) { if (path.startsWith("/detail/")) {
@@ -229,7 +228,6 @@ class PiliScheme {
); );
return true; return true;
} }
launchURL();
return false; return false;
case 'following': case 'following':
if (path.startsWith("/detail/")) { if (path.startsWith("/detail/")) {
@@ -246,11 +244,8 @@ class PiliScheme {
actions: [ actions: [
IconButton( IconButton(
tooltip: '前往', tooltip: '前往',
onPressed: () async { onPressed: () {
bool hasMatch = await _onPushDynDetail(path, off); _onPushDynDetail(path, off);
if (hasMatch.not) {
launchURL();
}
}, },
icon: const Icon(Icons.open_in_new), icon: const Icon(Icons.open_in_new),
), ),
@@ -268,13 +263,9 @@ class PiliScheme {
return true; return true;
} else { } else {
bool hasMatch = await _onPushDynDetail(path, off); bool hasMatch = await _onPushDynDetail(path, off);
if (hasMatch.not) {
launchURL();
}
return hasMatch; return hasMatch;
} }
} }
launchURL();
return false; return false;
case 'album': case 'album':
String? rid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? rid = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
@@ -297,14 +288,12 @@ class PiliScheme {
} }
return true; return true;
} }
launchURL();
return false; return false;
default: default:
if (selfHandle.not) { if (selfHandle.not) {
debugPrint('$uri'); debugPrint('$uri');
SmartDialog.showToast('未知路径:$uri,请截图反馈给开发者'); SmartDialog.showToast('未知路径:$uri,请截图反馈给开发者');
} }
launchURL();
return false; return false;
} }
case 'http' || 'https': case 'http' || 'https':
@@ -328,7 +317,6 @@ class PiliScheme {
debugPrint('$uri'); debugPrint('$uri');
SmartDialog.showToast('未知路径:$uri,请截图反馈给开发者'); SmartDialog.showToast('未知路径:$uri,请截图反馈给开发者');
} }
launchURL();
return false; return false;
} }
} }