Skip to content

Commit

Permalink
mod: scheme match
Browse files Browse the repository at this point in the history
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
  • Loading branch information
bggRGjQaUbCoE committed Feb 13, 2025
1 parent 2b9cb54 commit 84cc654
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
2 changes: 2 additions & 0 deletions lib/pages/main/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:PiliPlus/common/widgets/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/tabs.dart';
import 'package:PiliPlus/grpc/grpc_client.dart';
import 'package:PiliPlus/pages/mine/controller.dart';
import 'package:PiliPlus/utils/app_scheme.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -156,6 +157,7 @@ class _MainAppState extends State<MainApp>
await GrpcClient.instance.shutdown();
await GStorage.close();
EventBus().off(EventName.loginEvent);
PiliScheme.listener?.cancel();
super.dispose();
}

Expand Down
50 changes: 19 additions & 31 deletions lib/utils/app_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import 'utils.dart';

class PiliScheme {
static late AppLinks appLinks;
static StreamSubscription? listener;

static Future<void> init() async {
// Register our protocol only on Windows platform
// registerProtocolHandler('bilibili');
appLinks = AppLinks();

appLinks.uriLinkStream.listen((uri) {
listener?.cancel();
listener = appLinks.uriLinkStream.listen((uri) {
debugPrint('onAppLink: $uri');
routePush(uri);
});
Expand Down Expand Up @@ -53,12 +56,6 @@ class PiliScheme {
final String host = uri.host.toLowerCase();
final String path = uri.path;

void launchURL() {
if (selfHandle.not) {
Utils.launchURL(uri.toString());
}
}

switch (scheme) {
case 'bilibili':
switch (host) {
Expand All @@ -68,14 +65,25 @@ class PiliScheme {
(Route<dynamic> route) => route.isFirst,
);
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':
// bilibili://space/12345678?frommodule=XX&h5awaken=random
String? mid = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
if (mid != null) {
Utils.toDupNamed('/member?mid=$mid', off: off);
return true;
}
launchURL();
return false;
case 'video':
if (uri.queryParameters['comment_root_id'] != null) {
Expand Down Expand Up @@ -113,7 +121,6 @@ class PiliScheme {
);
return true;
}
launchURL();
return false;
}

Expand All @@ -131,7 +138,6 @@ class PiliScheme {
);
return true;
}
launchURL();
return false;
case 'live':
// bilibili://live/12345678?extra_jump_from=1&from=1&is_room_feed=1&h5awaken=random
Expand All @@ -140,29 +146,23 @@ class PiliScheme {
Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off);
return true;
}
launchURL();
return false;
case 'bangumi':
// to check
// bilibili://bangumi/season/12345678?h5_awaken_params=random
if (path.startsWith('/season')) {
String? seasonId = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
if (seasonId != null) {
Utils.viewBangumi(seasonId: seasonId, epId: null);
return true;
}
}
launchURL();
return false;
case 'opus':
// bilibili://opus/detail/12345678?h5awaken=random
if (path.startsWith('/detail')) {
bool hasMatch = await _onPushDynDetail(path, off);
if (hasMatch.not) {
launchURL();
}
return hasMatch;
}
launchURL();
return false;
case 'search':
Utils.toDupNamed(
Expand All @@ -187,7 +187,6 @@ class PiliScheme {
);
return true;
}
launchURL();
return false;
case 'comment':
if (path.startsWith("/detail/")) {
Expand Down Expand Up @@ -229,7 +228,6 @@ class PiliScheme {
);
return true;
}
launchURL();
return false;
case 'following':
if (path.startsWith("/detail/")) {
Expand All @@ -246,11 +244,8 @@ class PiliScheme {
actions: [
IconButton(
tooltip: '前往',
onPressed: () async {
bool hasMatch = await _onPushDynDetail(path, off);
if (hasMatch.not) {
launchURL();
}
onPressed: () {
_onPushDynDetail(path, off);
},
icon: const Icon(Icons.open_in_new),
),
Expand All @@ -268,13 +263,9 @@ class PiliScheme {
return true;
} else {
bool hasMatch = await _onPushDynDetail(path, off);
if (hasMatch.not) {
launchURL();
}
return hasMatch;
}
}
launchURL();
return false;
case 'album':
String? rid = RegExp(r'/(\d+)').firstMatch(path)?.group(1);
Expand All @@ -297,14 +288,12 @@ class PiliScheme {
}
return true;
}
launchURL();
return false;
default:
if (selfHandle.not) {
debugPrint('$uri');
SmartDialog.showToast('未知路径:$uri,请截图反馈给开发者');
}
launchURL();
return false;
}
case 'http' || 'https':
Expand All @@ -328,7 +317,6 @@ class PiliScheme {
debugPrint('$uri');
SmartDialog.showToast('未知路径:$uri,请截图反馈给开发者');
}
launchURL();
return false;
}
}
Expand Down

0 comments on commit 84cc654

Please sign in to comment.