Add singbox deeplink
This commit is contained in:
@@ -44,9 +44,15 @@
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="clash" />
|
||||
<data android:scheme="clashmeta" />
|
||||
<data android:host="install-config"/>
|
||||
<data
|
||||
android:host="import-remote-profile"
|
||||
android:scheme="sing-box" />
|
||||
<data
|
||||
android:host="install-config"
|
||||
android:scheme="clash" />
|
||||
<data
|
||||
android:host="install-config"
|
||||
android:scheme="clashmeta" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
|
||||
@@ -15,7 +15,7 @@ class DeepLinkService extends _$DeepLinkService
|
||||
Future<NewProfileLink?> build() async {
|
||||
if (Platform.isLinux) return null;
|
||||
loggy.debug("initializing");
|
||||
for (final protocol in _protocols) {
|
||||
for (final protocol in LinkParser.protocols) {
|
||||
await protocolHandler.register(protocol);
|
||||
}
|
||||
protocolHandler.addListener(this);
|
||||
@@ -32,8 +32,6 @@ class DeepLinkService extends _$DeepLinkService
|
||||
return null;
|
||||
}
|
||||
|
||||
static const _protocols = ['clash', 'clashmeta'];
|
||||
|
||||
@override
|
||||
void onProtocolUrlReceived(String url) {
|
||||
super.onProtocolUrlReceived(url);
|
||||
|
||||
@@ -5,7 +5,7 @@ typedef ProfileLink = ({String url, String name});
|
||||
|
||||
// TODO: test and improve
|
||||
abstract class LinkParser {
|
||||
static const protocols = ['clash', 'clashmeta'];
|
||||
static const protocols = ['clash', 'clashmeta', 'sing-box'];
|
||||
|
||||
static ProfileLink? simple(String link) {
|
||||
if (!isUrl(link)) return null;
|
||||
@@ -23,11 +23,20 @@ abstract class LinkParser {
|
||||
}
|
||||
|
||||
static ProfileLink? deep(String link) {
|
||||
final uri = Uri.parse(link.trim());
|
||||
if (protocols.none((e) => uri.scheme == e)) return null;
|
||||
if (uri.authority != 'install-config') return null;
|
||||
final params = uri.queryParameters;
|
||||
if (params['url'] == null) return null;
|
||||
return (url: params['url']!, name: params['name'] ?? '');
|
||||
final uri = Uri.tryParse(link.trim());
|
||||
if (uri == null || !uri.hasScheme || !uri.hasAuthority) return null;
|
||||
final queryParams = uri.queryParameters;
|
||||
switch (uri.scheme) {
|
||||
case 'clash' || 'clashmeta':
|
||||
if (uri.authority != 'install-config' ||
|
||||
!queryParams.containsKey('url')) return null;
|
||||
return (url: queryParams['url']!, name: queryParams['name'] ?? '');
|
||||
case 'sing-box':
|
||||
if (uri.authority != 'import-remote-profile' ||
|
||||
!queryParams.containsKey('url')) return null;
|
||||
return (url: queryParams['url']!, name: queryParams['name'] ?? '');
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user