spotube/lib/hooks/configurators/use_deep_linking.dart
Alessio fece073def This pull request primarily involves the removal of several configuration files and assets, as well as minor updates to documentation. The most significant changes are the deletion of various .vscode configuration files and the removal of unused assets from the project.
Configuration File Removals:

    .vscode/c_cpp_properties.json: Removed the entire configuration for C/C++ properties.
    .vscode/launch.json: Removed the Dart launch configurations for different environments and modes.
    .vscode/settings.json: Removed settings related to CMake, spell checking, file nesting, and Dart Flutter SDK path.
    .vscode/snippets.code-snippets: Removed code snippets for Dart, including PaginatedState and PaginatedNotifier templates.
    .vscode/tasks.json: Removed the tasks configuration file.

Documentation Updates:

    CONTRIBUTION.md: Removed heart emoji from the introductory text.
    README.md: Updated the logo image and made minor text adjustments, including removing emojis and updating section titles. [1] [2] [3] [4] [5]

Asset Removals:

    lib/collections/assets.gen.dart: Removed multiple unused asset references, including images related to Spotube logos and banners. [1] [2] [3]

Minor Code Cleanups:

    cli/commands/build/linux.dart, cli/commands/build/windows.dart, cli/commands/translated.dart, cli/commands/untranslated.dart: Adjusted import statements for consistency. [1] [2] [3] [4]
    integration_test/app_test.dart: Removed an unnecessary blank line.
    lib/collections/routes.dart: Commented out the TrackRoute configuration.
2025-04-13 18:40:37 +02:00

107 lines
3.4 KiB
Dart

import 'dart:async';
import 'package:app_links/app_links.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_sharing_intent/flutter_sharing_intent.dart';
import 'package:flutter_sharing_intent/model/sharing_file.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:spotube/collections/routes.dart';
import 'package:spotube/collections/routes.gr.dart';
import 'package:spotube/provider/spotify/spotify.dart';
import 'package:spotube/services/logger/logger.dart';
import 'package:spotube/utils/platform.dart';
final appLinks = AppLinks();
final linkStream = appLinks.stringLinkStream.asBroadcastStream();
void useDeepLinking(WidgetRef ref, AppRouter router) {
// single instance no worries
final spotify = ref.watch(spotifyProvider);
useEffect(() {
void uriListener(List<SharedFile> files) async {
for (final file in files) {
if (file.type != SharedMediaType.URL) continue;
final url = Uri.parse(file.value!);
if (url.pathSegments.length != 2) continue;
switch (url.pathSegments.first) {
case "album":
final album = await spotify.invoke((api) {
return api.albums.get(url.pathSegments.last);
});
router.navigate(
AlbumRoute(id: album.id!, album: album),
);
break;
case "artist":
router.navigate(ArtistRoute(artistId: url.pathSegments.last));
break;
case "playlist":
final playlist = await spotify.invoke((api) {
return api.playlists.get(url.pathSegments.last);
});
router
.navigate(PlaylistRoute(id: playlist.id!, playlist: playlist));
break;
case "track":
router.navigate(TrackRoute(trackId: url.pathSegments.last));
break;
default:
break;
}
}
}
StreamSubscription? mediaStream;
if (kIsMobile) {
FlutterSharingIntent.instance.getInitialSharing().then(uriListener);
mediaStream =
FlutterSharingIntent.instance.getMediaStream().listen(uriListener);
}
final subscription = linkStream.listen((uri) async {
try {
final startSegment = uri.split(":").take(2).join(":");
final endSegment = uri.split(":").last;
switch (startSegment) {
case "spotify:album":
final album = await spotify.invoke((api) {
return api.albums.get(endSegment);
});
await router.navigate(
AlbumRoute(id: album.id!, album: album),
);
break;
case "spotify:artist":
await router.navigate(ArtistRoute(artistId: endSegment));
break;
case "spotify:track":
await router.navigate(TrackRoute(trackId: endSegment));
break;
case "spotify:playlist":
final playlist = await spotify.invoke((api) {
return api.playlists.get(endSegment);
});
await router.navigate(
PlaylistRoute(id: playlist.id!, playlist: playlist),
);
break;
default:
break;
}
} catch (e, stack) {
AppLogger.reportError(e, stack);
}
});
return () {
mediaStream?.cancel();
subscription.cancel();
};
}, [spotify]);
}