mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 21:07:24 +00:00
deep link for android
This commit is contained in:
@@ -5,7 +5,9 @@ import 'package:pixes/foundation/app.dart';
|
||||
import 'package:pixes/foundation/log.dart';
|
||||
import 'package:pixes/pages/illust_page.dart';
|
||||
import 'package:pixes/pages/novel_page.dart';
|
||||
import 'package:pixes/pages/search_page.dart';
|
||||
import 'package:pixes/pages/user_info_page.dart';
|
||||
import 'package:pixes/utils/ext.dart';
|
||||
import 'package:win32_registry/win32_registry.dart';
|
||||
|
||||
Future<void> _register(String scheme) async {
|
||||
@@ -31,11 +33,17 @@ Future<void> _register(String scheme) async {
|
||||
|
||||
bool Function(Uri uri)? onLink;
|
||||
|
||||
bool _firstLink = true;
|
||||
|
||||
void handleLinks() async {
|
||||
if (App.isWindows) {
|
||||
await _register("pixiv");
|
||||
}
|
||||
AppLinks().uriLinkStream.listen((uri) {
|
||||
AppLinks().uriLinkStream.listen((uri) async {
|
||||
if (_firstLink) {
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
}
|
||||
_firstLink = false;
|
||||
Log.info("App Link", uri.toString());
|
||||
if (onLink?.call(uri) == true) {
|
||||
return;
|
||||
@@ -70,6 +78,33 @@ bool handleLink(Uri uri) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else if (uri.scheme == "https") {
|
||||
var path = uri.toString().split("/").sublist(3);
|
||||
switch (path[0]) {
|
||||
case "users":
|
||||
if (path.length >= 2) {
|
||||
App.mainNavigatorKey?.currentContext?.to(() => UserInfoPage(path[1]));
|
||||
return true;
|
||||
}
|
||||
case "novel":
|
||||
if (path.length == 2) {
|
||||
App.mainNavigatorKey?.currentContext
|
||||
?.to(() => NovelPageWithId(path[1].nums));
|
||||
return true;
|
||||
}
|
||||
case "artworks":
|
||||
if (path.length == 2) {
|
||||
App.mainNavigatorKey?.currentContext
|
||||
?.to(() => IllustPageWithId(path[1]));
|
||||
return true;
|
||||
}
|
||||
case "tags":
|
||||
if (path.length == 2) {
|
||||
App.mainNavigatorKey?.currentContext
|
||||
?.to(() => SearchResultPage(path[1]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user