mirror of
https://github.com/zapstore/zapstore.git
synced 2026-10-05 12:38:24 +00:00
Fix deep links
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@ import 'package:zapstore/services/package_manager/package_manager.dart';
|
|||||||
import 'package:zapstore/theme.dart';
|
import 'package:zapstore/theme.dart';
|
||||||
import 'package:zapstore/services/package_manager/android_package_manager.dart';
|
import 'package:zapstore/services/package_manager/android_package_manager.dart';
|
||||||
import 'package:zapstore/services/package_manager/dummy_package_manager.dart';
|
import 'package:zapstore/services/package_manager/dummy_package_manager.dart';
|
||||||
import 'package:zapstore/services/market_intent_service.dart';
|
import 'package:zapstore/services/deep_link_service.dart';
|
||||||
import 'package:zapstore/utils/extensions.dart';
|
import 'package:zapstore/utils/extensions.dart';
|
||||||
import 'package:zapstore/widgets/breathing_logo.dart';
|
import 'package:zapstore/widgets/breathing_logo.dart';
|
||||||
|
|
||||||
@@ -280,7 +280,7 @@ final appInitializationProvider = FutureProvider<void>((ref) async {
|
|||||||
final backgroundService = ref.read(backgroundUpdateServiceProvider);
|
final backgroundService = ref.read(backgroundUpdateServiceProvider);
|
||||||
unawaited(backgroundService.initialize());
|
unawaited(backgroundService.initialize());
|
||||||
|
|
||||||
unawaited(ref.read(marketIntentServiceProvider).initialize());
|
unawaited(ref.read(deepLinkServiceProvider).initialize());
|
||||||
|
|
||||||
await _attemptAutoSignIn(ref);
|
await _attemptAutoSignIn(ref);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,21 +6,17 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:zapstore/router.dart';
|
import 'package:zapstore/router.dart';
|
||||||
|
|
||||||
/// Provider that initializes market:// intent handling
|
final deepLinkServiceProvider = Provider<DeepLinkService>((ref) {
|
||||||
///
|
return DeepLinkService(ref);
|
||||||
/// Listens for incoming market:// URIs (e.g., market://details?id=com.example.app)
|
|
||||||
/// and navigates to the app detail screen.
|
|
||||||
final marketIntentServiceProvider = Provider<MarketIntentService>((ref) {
|
|
||||||
return MarketIntentService(ref);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
class MarketIntentService {
|
class DeepLinkService {
|
||||||
final Ref _ref;
|
final Ref _ref;
|
||||||
final AppLinks _appLinks = AppLinks();
|
final AppLinks _appLinks = AppLinks();
|
||||||
StreamSubscription<Uri>? _subscription;
|
StreamSubscription<Uri>? _subscription;
|
||||||
bool _initialized = false;
|
bool _initialized = false;
|
||||||
|
|
||||||
MarketIntentService(this._ref);
|
DeepLinkService(this._ref);
|
||||||
|
|
||||||
GoRouter get _router => _ref.read(routerProvider);
|
GoRouter get _router => _ref.read(routerProvider);
|
||||||
|
|
||||||
@@ -38,7 +34,23 @@ class MarketIntentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleUri(Uri? uri) {
|
void _handleUri(Uri? uri) {
|
||||||
final packageId = _extractPackageId(uri);
|
if (uri == null) return;
|
||||||
|
|
||||||
|
// https://zapstore.dev/apps/<id>
|
||||||
|
if (uri.scheme == 'https' &&
|
||||||
|
uri.host == 'zapstore.dev' &&
|
||||||
|
uri.pathSegments.length == 2 &&
|
||||||
|
uri.pathSegments[0] == 'apps') {
|
||||||
|
final id = uri.pathSegments[1];
|
||||||
|
if (id.isNotEmpty) {
|
||||||
|
debugPrint('App link: app ID = $id');
|
||||||
|
_router.go('/search/app/$id');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// market://details?id=com.example.app (Google Play-style intents)
|
||||||
|
final packageId = _extractMarketPackageId(uri);
|
||||||
if (packageId != null) {
|
if (packageId != null) {
|
||||||
_router.go('/search/app/$packageId');
|
_router.go('/search/app/$packageId');
|
||||||
}
|
}
|
||||||
@@ -49,17 +61,14 @@ class MarketIntentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract package ID from a URI
|
/// Extract package ID from a market:// URI.
|
||||||
///
|
///
|
||||||
/// Handles:
|
/// Handles:
|
||||||
/// - market://details?id=com.example.app
|
/// - market://details?id=com.example.app
|
||||||
/// - market://search?q=search+query
|
/// - market://search?q=search+query
|
||||||
String? _extractPackageId(Uri? uri) {
|
String? _extractMarketPackageId(Uri uri) {
|
||||||
if (uri == null) return null;
|
|
||||||
|
|
||||||
if (uri.scheme != 'market') return null;
|
if (uri.scheme != 'market') return null;
|
||||||
|
|
||||||
// market://details?id=com.example.app
|
|
||||||
if (uri.host == 'details' || uri.path == '/details') {
|
if (uri.host == 'details' || uri.path == '/details') {
|
||||||
final id = uri.queryParameters['id'];
|
final id = uri.queryParameters['id'];
|
||||||
if (id != null && id.isNotEmpty) {
|
if (id != null && id.isNotEmpty) {
|
||||||
@@ -68,7 +77,6 @@ String? _extractPackageId(Uri? uri) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// market://search?q=query
|
|
||||||
if (uri.host == 'search' || uri.path == '/search') {
|
if (uri.host == 'search' || uri.path == '/search') {
|
||||||
final query = uri.queryParameters['q'];
|
final query = uri.queryParameters['q'];
|
||||||
if (query != null && query.isNotEmpty) {
|
if (query != null && query.isNotEmpty) {
|
||||||
@@ -80,4 +88,3 @@ String? _extractPackageId(Uri? uri) {
|
|||||||
debugPrint('Market intent: unhandled URI = $uri');
|
debugPrint('Market intent: unhandled URI = $uri');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user