diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index c85115b2b..3a5101a9f 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -8269,6 +8269,15 @@ "audioInfoLocationLocal": "Device storage", "audioInfoLocationShared": "Shared folder", "audioInfoLocationNetwork": "Network storage", + "audioInfoLocationLink": "{device} via Mornye Link", + "@audioInfoLocationLink": { + "description": "Audio info location of a song played from a paired computer or phone over Mornye Link; device is that device's name", + "placeholders": { + "device": { + "type": "String" + } + } + }, "audioInfoPcmRate": "Uncompressed data rate", "audioInfoFrequencyRange": "Frequency range", "audioInfoFrequencyRangeValue": "Up to {frequency} (Nyquist)", diff --git a/lib/screens/network_storage_screen.dart b/lib/screens/network_storage_screen.dart index 706804ddf..dcaececc5 100644 --- a/lib/screens/network_storage_screen.dart +++ b/lib/screens/network_storage_screen.dart @@ -5,6 +5,7 @@ import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/providers/music_player_provider.dart'; import 'package:mornye/providers/local_library_provider.dart'; import 'package:mornye/providers/settings_provider.dart'; +import 'package:mornye/services/link/link_source_names.dart'; import 'package:mornye/services/music_player_service.dart'; import 'package:mornye/services/network_storage_service.dart'; import 'package:mornye/services/network_storage_error.dart'; @@ -301,6 +302,9 @@ class _NetworkStorageScreenState extends ConsumerState { ? connection.name : widget.displayName ?? widget.path.split('/').where((p) => p.isNotEmpty).last; + // Paired computers are served over Subsonic but are Mornye Link, which + // manages them, so they show as that and are not edited here. + final links = ref.watch(linkSourceNamesProvider); final visible = _entries.where((e) => e.directory || e.audio).toList(); return Scaffold( body: CustomScrollView( @@ -453,24 +457,30 @@ class _NetworkStorageScreenState extends ConsumerState { itemCount: _connections.length, itemBuilder: (context, index) { final c = _connections[index]; + final link = links.containsKey(c.id); return SettingsGroup( children: [ SettingsItem( - icon: context.isMornye - ? CupertinoIcons.cloud - : Icons.dns_outlined, + icon: switch ((link, context.isMornye)) { + (true, true) => CupertinoIcons.desktopcomputer, + (true, false) => Icons.computer, + (false, true) => CupertinoIcons.cloud, + (false, false) => Icons.dns_outlined, + }, showIconInMornye: true, title: c.name, subtitle: - '${_protocolLabel(c.protocol)} · ${c.root.host}', + '${_kindLabel(c, links)} · ${c.root.host}', onTap: () => _open(c), showDivider: false, - trailing: _NetworkIconAction( - tooltip: context.l10n.networkEditConnection, - onPressed: () => _edit(c), - icon: Icons.edit_outlined, - cupertinoIcon: CupertinoIcons.pencil, - ), + trailing: link + ? null + : _NetworkIconAction( + tooltip: context.l10n.networkEditConnection, + onPressed: () => _edit(c), + icon: Icons.edit_outlined, + cupertinoIcon: CupertinoIcons.pencil, + ), ), ], ); @@ -482,7 +492,7 @@ class _NetworkStorageScreenState extends ConsumerState { child: Padding( padding: const EdgeInsets.fromLTRB(24, 4, 24, 20), child: Text( - '${_protocolLabel(connection.protocol)} · ${connection.root.host}' + '${_kindLabel(connection, links)} · ${connection.root.host}' '${_subsonic ? '' : '\n/${widget.path}'}', style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.onSurfaceVariant, @@ -1011,6 +1021,13 @@ String _protocolLabel(NetworkProtocol protocol) => switch (protocol) { NetworkProtocol.subsonic => 'Subsonic', }; +/// What [connection] is: Mornye Link for a paired computer ([links]), else +/// its protocol. +String _kindLabel(NetworkConnection connection, Map links) => + links.containsKey(connection.id) + ? 'Mornye Link' + : _protocolLabel(connection.protocol); + String _networkErrorMessage(BuildContext context, NetworkStorageError error) => switch (error) { NetworkStorageError.unreachable => context.l10n.networkErrorUnreachable, diff --git a/lib/screens/settings/library_settings_page.dart b/lib/screens/settings/library_settings_page.dart index f023e98f0..e6c1f18fd 100644 --- a/lib/screens/settings/library_settings_page.dart +++ b/lib/screens/settings/library_settings_page.dart @@ -13,6 +13,7 @@ import 'package:mornye/providers/settings_provider.dart'; import 'package:mornye/providers/download_history_provider.dart'; import 'package:mornye/providers/local_library_provider.dart'; import 'package:mornye/services/library_database.dart'; +import 'package:mornye/services/link/link_source_names.dart'; import 'package:mornye/services/platform_bridge.dart'; import 'package:mornye/utils/adaptive_layout.dart'; import 'package:mornye/utils/nav_bar_inset.dart'; @@ -559,6 +560,12 @@ class _LibrarySettingsPageState extends ConsumerState { ); return _LibrarySourceSettingsItem( source: source, + link: + linkSourceName( + ref.watch(linkSourceNamesProvider), + source.path, + ) != + null, failures: scan.failures, isScanning: scan.active, isFinalizing: scan.finalizing, diff --git a/lib/screens/settings/library_settings_page_widgets.dart b/lib/screens/settings/library_settings_page_widgets.dart index 9e1da8179..feea79ff0 100644 --- a/lib/screens/settings/library_settings_page_widgets.dart +++ b/lib/screens/settings/library_settings_page_widgets.dart @@ -3,6 +3,9 @@ part of 'library_settings_page.dart'; class _LibrarySourceSettingsItem extends StatelessWidget { final LocalLibrarySource source; + /// Whether [source] is a paired computer or phone over Mornye Link. + final bool link; + /// Files the last finished scan of [source] could not read. final LibraryScanFailures? failures; final bool isScanning; @@ -19,6 +22,7 @@ class _LibrarySourceSettingsItem extends StatelessWidget { const _LibrarySourceSettingsItem({ required this.source, + this.link = false, required this.failures, required this.isScanning, required this.isFinalizing, @@ -192,7 +196,9 @@ class _LibrarySourceSettingsItem extends StatelessWidget { return Opacity( opacity: enabled ? 1 : 0.5, child: SettingsItem( - icon: source.path.startsWith('network://') + icon: link + ? Icons.computer + : source.path.startsWith('network://') ? Icons.dns_outlined : source.isRemovable ? Icons.usb_rounded diff --git a/lib/services/link/link_source_names.dart b/lib/services/link/link_source_names.dart new file mode 100644 index 000000000..f35de0964 --- /dev/null +++ b/lib/services/link/link_source_names.dart @@ -0,0 +1,30 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:mornye/services/link/client/link_client_controller.dart'; +import 'package:mornye/services/link/desktop/link_desktop_host.dart'; +import 'package:mornye/services/link/link_protocol.dart'; +import 'package:mornye/utils/desktop_platform.dart'; + +/// The Mornye Link devices behind network sources, by source id (the host +/// of a `network://` song): on a phone, its paired computers' connections; +/// on the desktop, the song sources of its paired phones. Such a source is +/// a whole Mornye on another device, not a plain file server. +final linkSourceNamesProvider = Provider>((ref) { + if (isDesktopPlatform) { + final devices = ref.watch(linkDesktopHostProvider.select((s) => s.devices)); + return { + for (final device in devices) + linkPhoneSourceId(device.deviceId): device.name, + }; + } + if (!ref.watch(linkClientSupportedProvider)) return const {}; + final servers = ref.watch( + linkClientControllerProvider.select((s) => s.servers), + ); + return {for (final server in servers) server.connectionId: server.name}; +}); + +/// The Mornye Link device that serves the `network://` [source], if any. +String? linkSourceName(Map names, String? source) { + if (source == null || !source.startsWith('network://')) return null; + return names[Uri.tryParse(source)?.host]; +} diff --git a/lib/widgets/audio_info_sheet.dart b/lib/widgets/audio_info_sheet.dart index 1788fa7db..4e3d871e2 100644 --- a/lib/widgets/audio_info_sheet.dart +++ b/lib/widgets/audio_info_sheet.dart @@ -9,6 +9,7 @@ import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/models/equalizer_settings.dart'; import 'package:mornye/models/settings.dart'; import 'package:mornye/services/audio_route_info.dart'; +import 'package:mornye/services/link/link_source_names.dart'; import 'package:mornye/services/music_playback_deck.dart'; import 'package:mornye/services/playback_deck.dart'; import 'package:mornye/services/music_player_service.dart'; @@ -26,23 +27,33 @@ import 'package:mornye/widgets/hires_check_card.dart'; import 'package:mornye/widgets/settings_group.dart'; /// Technical details of the playing track, from the file through the -/// processing chain to the output device. +/// processing chain to the output device. [linkSources] names the Mornye +/// Link devices behind network sources (`linkSourceNamesProvider`). Future showAudioInfoSheet( BuildContext context, { required PlayerMetadataController metadata, + Map linkSources = const {}, }) => showAppScrollableBottomSheet( context: context, title: context.l10n.audioInfoTitle, subtitle: metadata.qualityLabel, - builder: (context, controller) => - _AudioInfoSheet(metadata: metadata, controller: controller), + builder: (context, controller) => _AudioInfoSheet( + metadata: metadata, + controller: controller, + linkSources: linkSources, + ), ); class _AudioInfoSheet extends StatefulWidget { - const _AudioInfoSheet({required this.metadata, required this.controller}); + const _AudioInfoSheet({ + required this.metadata, + required this.controller, + required this.linkSources, + }); final PlayerMetadataController metadata; final ScrollController controller; + final Map linkSources; @override State<_AudioInfoSheet> createState() => _AudioInfoSheetState(); @@ -120,6 +131,10 @@ class _AudioInfoSheetState extends State<_AudioInfoSheet> { equalizer: playbackEqualizer.value, processing: musicPlayerRuntime.handler?.processing, settings: musicPlayerRuntime.settings, + linkDevice: linkSourceName( + widget.linkSources, + widget.metadata.filePath, + ), ); final sections = facts.sections(); final path = widget.metadata.filePath; @@ -336,6 +351,7 @@ class _AudioFacts { required this.equalizer, required this.processing, required this.settings, + this.linkDevice, }); final AppLocalizations l10n; @@ -348,6 +364,9 @@ class _AudioFacts { final PlaybackProcessing? processing; final AppSettings settings; + /// The paired computer or phone the network song plays from. + final String? linkDevice; + late final String format = (metadata['format'] ?? '').toString().trim(); late final String codec = (metadata['audio_codec'] ?? '').toString().trim(); late final int? sampleRate = @@ -430,7 +449,12 @@ class _AudioFacts { String? get _location { final path = this.path; if (path == null || path.isEmpty) return null; - if (path.startsWith('network://')) return l10n.audioInfoLocationNetwork; + if (path.startsWith('network://')) { + final device = linkDevice; + return device == null + ? l10n.audioInfoLocationNetwork + : l10n.audioInfoLocationLink(device); + } if (path.startsWith('content://')) return l10n.audioInfoLocationShared; if (path.startsWith('/')) return l10n.audioInfoLocationLocal; return null; diff --git a/lib/widgets/player_playback_controls.dart b/lib/widgets/player_playback_controls.dart index e85b25cf9..d7ec97829 100644 --- a/lib/widgets/player_playback_controls.dart +++ b/lib/widgets/player_playback_controls.dart @@ -7,6 +7,7 @@ import 'package:mornye/controllers/player_metadata_controller.dart'; import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/providers/music_player_provider.dart'; import 'package:mornye/providers/settings_provider.dart'; +import 'package:mornye/services/link/link_source_names.dart'; import 'package:mornye/theme/app_motion.dart'; import 'package:mornye/theme/app_tokens.dart'; import 'package:mornye/theme/material_expressive.dart'; @@ -620,7 +621,14 @@ class _QualityBadge extends StatelessWidget { type: MaterialType.transparency, child: InkWell( borderRadius: radius, - onTap: () => showAudioInfoSheet(context, metadata: metadata), + onTap: () => showAudioInfoSheet( + context, + metadata: metadata, + linkSources: ProviderScope.containerOf( + context, + listen: false, + ).read(linkSourceNamesProvider), + ), child: badge, ), ), diff --git a/test/audio_info_sheet_test.dart b/test/audio_info_sheet_test.dart index efb3c3dfd..b2adb1e7e 100644 --- a/test/audio_info_sheet_test.dart +++ b/test/audio_info_sheet_test.dart @@ -101,6 +101,46 @@ void main() { expect(find.text('2.0 ms · 96 frames'), findsOneWidget); }); + testWidgets('a song from a paired device shows where it plays from', ( + tester, + ) async { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(_route, (call) async => null); + final metadata = PlayerMetadataController( + readMetadata: (_) async => const {'format': 'flac', 'bit_depth': 16}, + ); + addTearDown(metadata.dispose); + await metadata.load( + const MediaItem( + id: 'track', + title: 'Track', + extras: {'source': 'network://desk/Album/Song.flac'}, + ), + ); + + await tester.pumpWidget( + MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: Builder( + builder: (context) => TextButton( + onPressed: () => showAudioInfoSheet( + context, + metadata: metadata, + linkSources: const {'desk': 'Studio Mac'}, + ), + child: const Text('open'), + ), + ), + ), + ); + await tester.tap(find.text('open')); + await tester.pumpAndSettle(); + + expect(find.text('Studio Mac via Mornye Link'), findsOneWidget); + expect(find.text('Network storage'), findsNothing); + }); + testWidgets('late route replies cannot replace the latest track snapshot', ( tester, ) async { diff --git a/test/network_storage_screen_test.dart b/test/network_storage_screen_test.dart index 0da3cd420..727f7f728 100644 --- a/test/network_storage_screen_test.dart +++ b/test/network_storage_screen_test.dart @@ -7,6 +7,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/screens/network_storage_screen.dart'; +import 'package:mornye/services/link/link_source_names.dart'; import 'package:mornye/services/local_network_access.dart'; import 'package:mornye/services/network_certificate.dart'; import 'package:mornye/services/network_storage_service.dart'; @@ -253,6 +254,50 @@ void main() { expect(tester.takeException(), isNull); }, ); + testWidgets('a paired computer shows as Mornye Link (Mornye: $mornye)', ( + tester, + ) async { + final service = _NetworkFixture(); + await service.save( + const NetworkConnection( + id: 'desk', + name: 'Studio Mac', + protocol: NetworkProtocol.subsonic, + address: 'https://192.168.1.20:4533/', + ), + ); + await service.save( + const NetworkConnection( + id: 'nas', + name: 'My NAS', + protocol: NetworkProtocol.subsonic, + address: 'https://nas.test/', + ), + ); + await tester.pumpWidget( + ProviderScope( + overrides: [ + linkSourceNamesProvider.overrideWithValue(const { + 'desk': 'Studio Mac', + }), + ], + child: MaterialApp( + theme: mornye + ? MornyeTheme.build(Brightness.dark) + : ThemeData(useMaterial3: true), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: NetworkStorageScreen(service: service), + ), + ), + ); + await tester.pumpAndSettle(); + expect(find.text('Mornye Link · 192.168.1.20'), findsOneWidget); + expect(find.text('Subsonic · nas.test'), findsOneWidget); + // Link manages the computer, so only the NAS can be edited here. + expect(find.byTooltip('Edit connection'), findsOneWidget); + expect(tester.takeException(), isNull); + }); testWidgets( 'connection form saves in the selected theme (Mornye: $mornye)', (tester) async {