-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add deep link support * feat(android): add intent share support * chore: untranslated msg for it locale
- Loading branch information
Showing
19 changed files
with
273 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'dart:io'; | ||
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart'; | ||
import 'package:win32_registry/win32_registry.dart'; | ||
|
||
Future<void> registerWindowsScheme(String scheme) async { | ||
if (!DesktopTools.platform.isWindows) return; | ||
String appPath = Platform.resolvedExecutable; | ||
|
||
String protocolRegKey = 'Software\\Classes\\$scheme'; | ||
RegistryValue protocolRegValue = const RegistryValue( | ||
'URL Protocol', | ||
RegistryValueType.string, | ||
'', | ||
); | ||
String protocolCmdRegKey = 'shell\\open\\command'; | ||
RegistryValue protocolCmdRegValue = RegistryValue( | ||
'', | ||
RegistryValueType.string, | ||
'"$appPath" "%1"', | ||
); | ||
|
||
final regKey = Registry.currentUser.createKey(protocolRegKey); | ||
regKey.createValue(protocolRegValue); | ||
regKey.createKey(protocolCmdRegKey).createValue(protocolCmdRegValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import 'package:app_links/app_links.dart'; | ||
import 'package:fl_query_hooks/fl_query_hooks.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:spotify/spotify.dart'; | ||
import 'package:spotube/collections/routes.dart'; | ||
import 'package:spotube/provider/spotify_provider.dart'; | ||
import 'package:flutter_sharing_intent/flutter_sharing_intent.dart'; | ||
import 'package:flutter_sharing_intent/model/sharing_file.dart'; | ||
|
||
void useDeepLinking(WidgetRef ref) { | ||
// single instance no worries | ||
final appLinks = AppLinks(); | ||
final spotify = ref.watch(spotifyProvider); | ||
final queryClient = useQueryClient(); | ||
|
||
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": | ||
router.push( | ||
"/album/${url.pathSegments.last}", | ||
extra: await queryClient.fetchQuery<Album, dynamic>( | ||
"album/${url.pathSegments.last}", | ||
() => spotify.albums.get(url.pathSegments.last), | ||
), | ||
); | ||
break; | ||
case "artist": | ||
router.push("/artist/${url.pathSegments.last}"); | ||
break; | ||
case "playlist": | ||
router.push( | ||
"/playlist/${url.pathSegments.last}", | ||
extra: await queryClient.fetchQuery<Playlist, dynamic>( | ||
"playlist/${url.pathSegments.last}", | ||
() => spotify.playlists.get(url.pathSegments.last), | ||
), | ||
); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
FlutterSharingIntent.instance.getInitialSharing().then(uriListener); | ||
|
||
final mediaStream = | ||
FlutterSharingIntent.instance.getMediaStream().listen(uriListener); | ||
|
||
final subscription = appLinks.allStringLinkStream.listen((uri) async { | ||
final startSegment = uri.split(":").take(2).join(":"); | ||
final endSegment = uri.split(":").last; | ||
|
||
switch (startSegment) { | ||
case "spotify:album": | ||
await router.push( | ||
"/album/$endSegment", | ||
extra: await queryClient.fetchQuery<Album, dynamic>( | ||
"album/$endSegment", | ||
() => spotify.albums.get(endSegment), | ||
), | ||
); | ||
break; | ||
case "spotify:artist": | ||
await router.push("/artist/$endSegment"); | ||
break; | ||
case "spotify:playlist": | ||
await router.push( | ||
"/playlist/$endSegment", | ||
extra: await queryClient.fetchQuery<Playlist, dynamic>( | ||
"playlist/$endSegment", | ||
() => spotify.playlists.get(endSegment), | ||
), | ||
); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
|
||
return () { | ||
mediaStream.cancel(); | ||
subscription.cancel(); | ||
}; | ||
}, [spotify, queryClient]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,6 @@ categories: | |
- Music | ||
|
||
startup_notify: true | ||
|
||
supported_mime_type: | ||
- x-scheme-handler/spotify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.