mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-03-03 12:16:47 +00:00
fix: add link handler to app links listener
This commit is contained in:
parent
21fbd8a04c
commit
1b819c5b08
2 changed files with 23 additions and 12 deletions
|
|
@ -19,17 +19,17 @@ import 'package:twonly/src/views/components/alert_dialog.dart';
|
||||||
import 'package:twonly/src/views/contact/contact.view.dart';
|
import 'package:twonly/src/views/contact/contact.view.dart';
|
||||||
import 'package:twonly/src/views/public_profile.view.dart';
|
import 'package:twonly/src/views/public_profile.view.dart';
|
||||||
|
|
||||||
Future<void> handleIntentUrl(BuildContext context, Uri uri) async {
|
Future<bool> handleIntentUrl(BuildContext context, Uri uri) async {
|
||||||
if (!uri.scheme.startsWith('http')) return;
|
if (!uri.scheme.startsWith('http')) return false;
|
||||||
if (uri.host != 'me.twonly.eu') return;
|
if (uri.host != 'me.twonly.eu') return false;
|
||||||
if (uri.hasEmptyPath) return;
|
if (uri.hasEmptyPath) return false;
|
||||||
|
|
||||||
final publicKey = uri.hasFragment ? uri.fragment : null;
|
final publicKey = uri.hasFragment ? uri.fragment : null;
|
||||||
final userPaths = uri.path.split('/');
|
final userPaths = uri.path.split('/');
|
||||||
if (userPaths.length != 2) return;
|
if (userPaths.length != 2) return false;
|
||||||
final username = userPaths[1];
|
final username = userPaths[1];
|
||||||
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return false;
|
||||||
|
|
||||||
if (username == gUser.username) {
|
if (username == gUser.username) {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
|
|
@ -40,7 +40,7 @@ Future<void> handleIntentUrl(BuildContext context, Uri uri) async {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info(
|
Log.info(
|
||||||
|
|
@ -48,7 +48,7 @@ Future<void> handleIntentUrl(BuildContext context, Uri uri) async {
|
||||||
);
|
);
|
||||||
final contacts = await twonlyDB.contactsDao.getContactsByUsername(username);
|
final contacts = await twonlyDB.contactsDao.getContactsByUsername(username);
|
||||||
if (contacts.isEmpty) {
|
if (contacts.isEmpty) {
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return true;
|
||||||
Uint8List? publicKeyBytes;
|
Uint8List? publicKeyBytes;
|
||||||
if (publicKey != null) {
|
if (publicKey != null) {
|
||||||
publicKeyBytes = base64Url.decode(publicKey);
|
publicKeyBytes = base64Url.decode(publicKey);
|
||||||
|
|
@ -72,7 +72,7 @@ Future<void> handleIntentUrl(BuildContext context, Uri uri) async {
|
||||||
if (storedPublicKey == null ||
|
if (storedPublicKey == null ||
|
||||||
receivedPublicKey.isEmpty ||
|
receivedPublicKey.isEmpty ||
|
||||||
!context.mounted) {
|
!context.mounted) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
if (storedPublicKey.equals(receivedPublicKey)) {
|
if (storedPublicKey.equals(receivedPublicKey)) {
|
||||||
if (!contact.verified) {
|
if (!contact.verified) {
|
||||||
|
|
@ -112,6 +112,7 @@ Future<void> handleIntentUrl(BuildContext context, Uri uri) async {
|
||||||
Log.warn(e);
|
Log.warn(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> handleIntentMediaFile(
|
Future<void> handleIntentMediaFile(
|
||||||
|
|
@ -160,12 +161,15 @@ Future<void> handleIntentSharedFile(
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.info('got file via intent ${file.type} ${file.value}');
|
|
||||||
|
Log.info('got file via intent ${file.type}');
|
||||||
|
|
||||||
switch (file.type) {
|
switch (file.type) {
|
||||||
case SharedMediaType.URL:
|
case SharedMediaType.URL:
|
||||||
if (file.value?.startsWith('http') ?? false) {
|
if (file.value?.startsWith('http') ?? false) {
|
||||||
onUrlCallBack(Uri.parse(file.value!));
|
final uri = Uri.parse(file.value!);
|
||||||
|
Log.info('Got link via handle intent share file: ${uri.scheme}');
|
||||||
|
onUrlCallBack(uri);
|
||||||
}
|
}
|
||||||
case SharedMediaType.IMAGE:
|
case SharedMediaType.IMAGE:
|
||||||
var type = MediaType.image;
|
var type = MediaType.image;
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,14 @@ class HomeViewState extends State<HomeView> {
|
||||||
|
|
||||||
// Subscribe to all events (initial link and further)
|
// Subscribe to all events (initial link and further)
|
||||||
_deepLinkSub = AppLinks().uriLinkStream.listen((uri) async {
|
_deepLinkSub = AppLinks().uriLinkStream.listen((uri) async {
|
||||||
if (mounted) await handleIntentUrl(context, uri);
|
if (mounted) {
|
||||||
|
Log.info('Got link via app links: ${uri.scheme}');
|
||||||
|
if (!await handleIntentUrl(context, uri)) {
|
||||||
|
if (uri.scheme.startsWith('http')) {
|
||||||
|
_mainCameraController.setSharedLinkForPreview(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_intentStreamSub = FlutterSharingIntent.instance.getMediaStream().listen(
|
_intentStreamSub = FlutterSharingIntent.instance.getMediaStream().listen(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue