mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
feat(whats-new): give Nearby devices its own page
People often skipped past the Allow button on the Mornye Link page. On Android 17 without the permission, the tour now adds a Nearby devices page right after Mornye Link that explains what it is for: finding the computer, network storage, and that it stays on the local network. Until Android answers, that page ends the tour: Skip is hidden, the main button asks instead of continuing, and swiping cannot pass it. Skip on earlier pages stops there first. Allowing or refusing brings Skip and Continue back.
This commit is contained in:
1 parent
6407abedbf
commit
d30f0dbde3
4 files changed
+300
-140
No files matched your search
+38
-2
@@ -1118,11 +1118,47 @@
|
||||
},
|
||||
"whatsNewLinkNearbyAllow": "Allow nearby devices",
|
||||
"@whatsNewLinkNearbyAllow": {
|
||||
"description": "Button on the Mornye Link page of the What's New tour that asks for Android's Nearby devices permission"
|
||||
"description": "Main button on the Nearby devices page of the What's New tour that asks for Android's Nearby devices permission"
|
||||
},
|
||||
"whatsNewLinkNearbyGranted": "Nearby devices allowed",
|
||||
"@whatsNewLinkNearbyGranted": {
|
||||
"description": "Shown on the Mornye Link page of the What's New tour after the Nearby devices permission is granted"
|
||||
"description": "Shown on the Nearby devices page of the What's New tour after the Nearby devices permission is granted"
|
||||
},
|
||||
"whatsNewNearbyTitle": "Nearby devices",
|
||||
"@whatsNewNearbyTitle": {
|
||||
"description": "Title of the What's New page that asks for Android's Nearby devices permission; use Android's name for this permission"
|
||||
},
|
||||
"whatsNewNearbyDesc": "Android now asks before an app can reach other devices on your network. Mornye needs this for:",
|
||||
"@whatsNewNearbyDesc": {
|
||||
"description": "Description on the Nearby devices page of the What's New tour, followed by a list of uses"
|
||||
},
|
||||
"whatsNewNearbyLinkTitle": "Finding your computer",
|
||||
"@whatsNewNearbyLinkTitle": {
|
||||
"description": "Use of the Nearby devices permission: Mornye Link finds the computer"
|
||||
},
|
||||
"whatsNewNearbyLinkBody": "Mornye Link looks for your computer on the same Wi-Fi and stays connected to it.",
|
||||
"@whatsNewNearbyLinkBody": {
|
||||
"description": "Explains how Mornye Link uses the Nearby devices permission"
|
||||
},
|
||||
"whatsNewNearbyStorageTitle": "Network storage",
|
||||
"@whatsNewNearbyStorageTitle": {
|
||||
"description": "Use of the Nearby devices permission: SMB and WebDAV servers at home"
|
||||
},
|
||||
"whatsNewNearbyStorageBody": "Play music from a NAS or a server at home over SMB or WebDAV.",
|
||||
"@whatsNewNearbyStorageBody": {
|
||||
"description": "Explains how network storage uses the Nearby devices permission"
|
||||
},
|
||||
"whatsNewNearbyPrivateTitle": "Only your own devices",
|
||||
"@whatsNewNearbyPrivateTitle": {
|
||||
"description": "Reassurance on the Nearby devices page of the What's New tour"
|
||||
},
|
||||
"whatsNewNearbyPrivateBody": "Mornye uses it only to reach devices on your network, never to find where you are.",
|
||||
"@whatsNewNearbyPrivateBody": {
|
||||
"description": "Explains that the Nearby devices permission is not used for location"
|
||||
},
|
||||
"whatsNewNearbyRefused": "Not allowed. Mornye Link and network storage stay off until you allow Nearby devices for Mornye in Android settings.",
|
||||
"@whatsNewNearbyRefused": {
|
||||
"description": "Shown on the Nearby devices page of the What's New tour after the permission is refused"
|
||||
},
|
||||
"setupNext": "Next",
|
||||
"@setupNext": {
|
||||
|
||||
@@ -1026,6 +1026,15 @@
|
||||
"permissionNearbyDevices": "Perangkat di sekitar",
|
||||
"whatsNewLinkNearbyAllow": "Izinkan perangkat di sekitar",
|
||||
"whatsNewLinkNearbyGranted": "Perangkat di sekitar diizinkan",
|
||||
"whatsNewNearbyTitle": "Perangkat di sekitar",
|
||||
"whatsNewNearbyDesc": "Android kini meminta izin sebelum aplikasi bisa menjangkau perangkat lain di jaringanmu. Mornye memerlukannya untuk:",
|
||||
"whatsNewNearbyLinkTitle": "Menemukan komputermu",
|
||||
"whatsNewNearbyLinkBody": "Mornye Link mencari komputermu di Wi-Fi yang sama dan tetap terhubung dengannya.",
|
||||
"whatsNewNearbyStorageTitle": "Penyimpanan jaringan",
|
||||
"whatsNewNearbyStorageBody": "Putar musik dari NAS atau server di rumah lewat SMB atau WebDAV.",
|
||||
"whatsNewNearbyPrivateTitle": "Hanya perangkatmu sendiri",
|
||||
"whatsNewNearbyPrivateBody": "Mornye memakainya hanya untuk menjangkau perangkat di jaringanmu, tidak pernah untuk mengetahui lokasimu.",
|
||||
"whatsNewNearbyRefused": "Tidak diizinkan. Mornye Link dan penyimpanan jaringan tidak aktif sampai kamu mengizinkan Perangkat di sekitar untuk Mornye di pengaturan Android.",
|
||||
"setupNext": "Lanjut",
|
||||
"@setupNext": {
|
||||
"description": "Next button text"
|
||||
|
||||
+157
-122
@@ -32,7 +32,10 @@ import 'package:mornye/widgets/expressive_button.dart';
|
||||
/// 5.2 rebrand tour; pages list only what this device can use. Desktop uses
|
||||
/// [showWhatsNewDialog] instead.
|
||||
class WhatsNewScreen extends ConsumerStatefulWidget {
|
||||
const WhatsNewScreen({super.key});
|
||||
const WhatsNewScreen({super.key, this.localNetworkAccess});
|
||||
|
||||
/// Replaces [LocalNetworkAccess.instance] in tests.
|
||||
final LocalNetworkAccess? localNetworkAccess;
|
||||
|
||||
@override
|
||||
ConsumerState<WhatsNewScreen> createState() => _WhatsNewScreenState();
|
||||
@@ -42,6 +45,26 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
final _pages = PageController();
|
||||
int _page = 0;
|
||||
|
||||
/// Whether the tour asks for Nearby devices: Android 17 without it.
|
||||
/// Decided once, so the page stays after it is answered.
|
||||
bool _asksNearby = false;
|
||||
|
||||
/// Null until Android answers the request; true when allowed.
|
||||
bool? _nearbyAllowed;
|
||||
bool _askingNearby = false;
|
||||
|
||||
LocalNetworkAccess get _localNetwork =>
|
||||
widget.localNetworkAccess ?? LocalNetworkAccess.instance;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (isAndroidTv) return;
|
||||
_localNetwork.isGranted().then((granted) {
|
||||
if (mounted && !granted) setState(() => _asksNearby = true);
|
||||
}, onError: (_) {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pages.dispose();
|
||||
@@ -66,15 +89,33 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
if (_page > 0) _goTo(_page - 1);
|
||||
}
|
||||
|
||||
/// Skip never passes the Nearby devices request while Android still needs
|
||||
/// it: Link cannot find a computer on Android 17 without it.
|
||||
Future<void> _skip(List<WhatsNewHighlight> pages) async {
|
||||
final asks = pages.indexWhere((page) => page.asksNearbyDevices);
|
||||
if (asks > _page && !await LocalNetworkAccess.instance.isGranted()) {
|
||||
if (mounted) _goTo(asks);
|
||||
return;
|
||||
/// Skip never passes an unanswered Nearby devices page: Link cannot find a
|
||||
/// computer on Android 17 without it.
|
||||
void _skip(int nearbyPage) {
|
||||
if (nearbyPage > _page && _nearbyAllowed == null) {
|
||||
_goTo(nearbyPage);
|
||||
} else {
|
||||
_finish();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _allowNearby() async {
|
||||
setState(() => _askingNearby = true);
|
||||
try {
|
||||
await _localNetwork.ensureGranted();
|
||||
// Discovery that found nothing without it starts over.
|
||||
if (ref.read(linkClientSupportedProvider)) {
|
||||
ref
|
||||
.read(linkClientControllerProvider.notifier)
|
||||
.requestLocalNetworkAccess()
|
||||
.ignore();
|
||||
}
|
||||
if (mounted) setState(() => _nearbyAllowed = true);
|
||||
} on LocalNetworkPermissionException {
|
||||
if (mounted) setState(() => _nearbyAllowed = false);
|
||||
} finally {
|
||||
if (mounted) setState(() => _askingNearby = false);
|
||||
}
|
||||
if (mounted) _finish();
|
||||
}
|
||||
|
||||
/// Done and Skip both mark the tour seen. Opened from About, the tour
|
||||
@@ -94,8 +135,13 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final mornye = context.isMornye;
|
||||
final pages = whatsNewHighlights(l10n);
|
||||
final pages = whatsNewHighlights(l10n, nearbyDevices: _asksNearby);
|
||||
final last = _page == pages.length - 1;
|
||||
final nearbyPage = pages.indexWhere((page) => page.nearbyDevices);
|
||||
// Until Android answers, the Nearby devices page is the end of the tour:
|
||||
// no Skip, no Continue and no swiping past it.
|
||||
final awaitingNearby = nearbyPage >= 0 && _nearbyAllowed == null;
|
||||
final gated = awaitingNearby && _page == nearbyPage;
|
||||
// Back steps through the pages, then leaves the tour as Skip does.
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
@@ -145,16 +191,23 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
),
|
||||
),
|
||||
// Capped so large text cannot push it off screen;
|
||||
// the dots keep the rest of the row.
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 160),
|
||||
child: ExpressiveButton(
|
||||
text: true,
|
||||
onPressed: () => _skip(pages),
|
||||
child: Text(
|
||||
l10n.setupSkip,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
// the dots keep the rest of the row. Hidden in place
|
||||
// while gated, so the dots do not move.
|
||||
Visibility(
|
||||
visible: !gated,
|
||||
maintainSize: true,
|
||||
maintainAnimation: true,
|
||||
maintainState: true,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 160),
|
||||
child: ExpressiveButton(
|
||||
text: true,
|
||||
onPressed: () => _skip(nearbyPage),
|
||||
child: Text(
|
||||
l10n.setupSkip,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -164,10 +217,15 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
Expanded(
|
||||
child: PageView.builder(
|
||||
controller: _pages,
|
||||
itemCount: pages.length,
|
||||
itemCount: awaitingNearby ? nearbyPage + 1 : pages.length,
|
||||
onPageChanged: (page) => setState(() => _page = page),
|
||||
itemBuilder: (context, index) =>
|
||||
_TourPage(index: index, highlight: pages[index]),
|
||||
itemBuilder: (context, index) => _TourPage(
|
||||
index: index,
|
||||
highlight: pages[index],
|
||||
status: pages[index].nearbyDevices
|
||||
? _NearbyStatus(allowed: _nearbyAllowed)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
@@ -175,8 +233,13 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ExpressiveButton(
|
||||
onPressed: () => _next(pages.length),
|
||||
icon: last
|
||||
// Gated, the main button asks instead of moving on.
|
||||
onPressed: gated
|
||||
? (_askingNearby ? null : _allowNearby)
|
||||
: () => _next(pages.length),
|
||||
icon: gated
|
||||
? Icon(context.adaptiveIcon(Icons.wifi))
|
||||
: last
|
||||
? null
|
||||
: Icon(
|
||||
mornye
|
||||
@@ -193,7 +256,11 @@ class _WhatsNewScreenState extends ConsumerState<WhatsNewScreen> {
|
||||
textStyle: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
child: Text(
|
||||
last ? l10n.whatsNewDone : l10n.upgradeIntroContinue,
|
||||
gated
|
||||
? l10n.whatsNewLinkNearbyAllow
|
||||
: last
|
||||
? l10n.whatsNewDone
|
||||
: l10n.upgradeIntroContinue,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -469,7 +536,7 @@ class WhatsNewHighlight {
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.features,
|
||||
this.asksNearbyDevices = false,
|
||||
this.nearbyDevices = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
@@ -477,9 +544,9 @@ class WhatsNewHighlight {
|
||||
final String description;
|
||||
final List<WhatsNewFeature> features;
|
||||
|
||||
/// Ends the page with a request for Android's Nearby devices permission,
|
||||
/// which Mornye Link needs to find a computer from Android 17.
|
||||
final bool asksNearbyDevices;
|
||||
/// The page that asks for Android's Nearby devices permission, which
|
||||
/// Mornye Link and network storage need from Android 17.
|
||||
final bool nearbyDevices;
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
@@ -494,22 +561,22 @@ class WhatsNewFeature {
|
||||
}
|
||||
|
||||
/// The tour for [AppInfo.whatsNewRelease]: an overview, then one page per
|
||||
/// area. Android Auto, exclusive output and the Nearby devices request
|
||||
/// appear only where they exist.
|
||||
/// area. Android Auto and exclusive output appear only where they exist;
|
||||
/// [nearbyDevices] adds the Nearby devices page right after Mornye Link.
|
||||
@visibleForTesting
|
||||
List<WhatsNewHighlight> whatsNewHighlights(
|
||||
AppLocalizations l10n, {
|
||||
bool? androidPhone,
|
||||
bool? desktop,
|
||||
bool nearbyDevices = false,
|
||||
}) {
|
||||
final onAndroidPhone = androidPhone ?? (Platform.isAndroid && !isAndroidTv);
|
||||
final showAndroidAuto = androidPhone ?? (Platform.isAndroid && !isAndroidTv);
|
||||
final showExclusiveOutput = desktop ?? isDesktopPlatform;
|
||||
final sections = [
|
||||
WhatsNewHighlight(
|
||||
icon: Icons.computer,
|
||||
title: l10n.whatsNewLinkTitle,
|
||||
description: l10n.whatsNewLinkDesc,
|
||||
asksNearbyDevices: onAndroidPhone,
|
||||
features: [
|
||||
WhatsNewFeature(
|
||||
Icons.play_circle,
|
||||
@@ -570,7 +637,7 @@ List<WhatsNewHighlight> whatsNewHighlights(
|
||||
l10n.whatsNewPlayerTimingTitle,
|
||||
l10n.whatsNewPlayerTimingBody,
|
||||
),
|
||||
if (onAndroidPhone)
|
||||
if (showAndroidAuto)
|
||||
WhatsNewFeature(
|
||||
Icons.directions_car,
|
||||
l10n.whatsNewPlayerAutoTitle,
|
||||
@@ -649,7 +716,33 @@ List<WhatsNewHighlight> whatsNewHighlights(
|
||||
WhatsNewFeature(section.icon, section.title),
|
||||
],
|
||||
),
|
||||
...sections,
|
||||
sections.first,
|
||||
// A setup step rather than a highlight, so the overview leaves it out.
|
||||
if (nearbyDevices)
|
||||
WhatsNewHighlight(
|
||||
icon: Icons.wifi,
|
||||
title: l10n.whatsNewNearbyTitle,
|
||||
description: l10n.whatsNewNearbyDesc,
|
||||
nearbyDevices: true,
|
||||
features: [
|
||||
WhatsNewFeature(
|
||||
Icons.computer,
|
||||
l10n.whatsNewNearbyLinkTitle,
|
||||
l10n.whatsNewNearbyLinkBody,
|
||||
),
|
||||
WhatsNewFeature(
|
||||
Icons.dns,
|
||||
l10n.whatsNewNearbyStorageTitle,
|
||||
l10n.whatsNewNearbyStorageBody,
|
||||
),
|
||||
WhatsNewFeature(
|
||||
Icons.lock,
|
||||
l10n.whatsNewNearbyPrivateTitle,
|
||||
l10n.whatsNewNearbyPrivateBody,
|
||||
),
|
||||
],
|
||||
),
|
||||
...sections.skip(1),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -706,11 +799,14 @@ class _PageIndicator extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _TourPage extends StatelessWidget {
|
||||
const _TourPage({required this.index, required this.highlight});
|
||||
const _TourPage({required this.index, required this.highlight, this.status});
|
||||
|
||||
final int index;
|
||||
final WhatsNewHighlight highlight;
|
||||
|
||||
/// Shown under the description, above the rows, so it needs no scrolling.
|
||||
final Widget? status;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -754,8 +850,7 @@ class _TourPage extends StatelessWidget {
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
// Above the rows, so it shows without scrolling.
|
||||
if (highlight.asksNearbyDevices) const _NearbyDevicesPrompt(),
|
||||
?status,
|
||||
const SizedBox(height: 28),
|
||||
_FeatureList(features: highlight.features),
|
||||
],
|
||||
@@ -764,100 +859,40 @@ class _TourPage extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Asks for Nearby devices where Android requires it and it is not yet
|
||||
/// allowed; shows nothing otherwise, and a confirmation once allowed here.
|
||||
class _NearbyDevicesPrompt extends ConsumerStatefulWidget {
|
||||
const _NearbyDevicesPrompt();
|
||||
/// Android's answer on the Nearby devices page, under its description;
|
||||
/// nothing until it answers.
|
||||
class _NearbyStatus extends StatelessWidget {
|
||||
const _NearbyStatus({required this.allowed});
|
||||
|
||||
@override
|
||||
ConsumerState<_NearbyDevicesPrompt> createState() =>
|
||||
_NearbyDevicesPromptState();
|
||||
}
|
||||
|
||||
class _NearbyDevicesPromptState extends ConsumerState<_NearbyDevicesPrompt> {
|
||||
/// Null until the first check answers.
|
||||
bool? _neededAtStart;
|
||||
bool _granted = false;
|
||||
bool _refused = false;
|
||||
bool _asking = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
LocalNetworkAccess.instance.isGranted().then((granted) {
|
||||
if (mounted) setState(() => _neededAtStart = !granted);
|
||||
}, onError: (_) {});
|
||||
}
|
||||
|
||||
Future<void> _allow() async {
|
||||
setState(() {
|
||||
_asking = true;
|
||||
_refused = false;
|
||||
});
|
||||
try {
|
||||
// Through Link, so discovery that found nothing without it starts over.
|
||||
await ref
|
||||
.read(linkClientControllerProvider.notifier)
|
||||
.requestLocalNetworkAccess();
|
||||
if (mounted) setState(() => _granted = true);
|
||||
} on LocalNetworkPermissionException {
|
||||
if (mounted) setState(() => _refused = true);
|
||||
} finally {
|
||||
if (mounted) setState(() => _asking = false);
|
||||
}
|
||||
}
|
||||
final bool? allowed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_neededAtStart != true) return const SizedBox.shrink();
|
||||
final allowed = this.allowed;
|
||||
if (allowed == null) return const SizedBox.shrink();
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
if (_granted) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
context.adaptiveIcon(Icons.check_circle),
|
||||
color: scheme.primary,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.whatsNewLinkNearbyGranted,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: scheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
final color = allowed
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ExpressiveButton(
|
||||
tonal: true,
|
||||
onPressed: _asking ? null : _allow,
|
||||
icon: Icon(context.adaptiveIcon(Icons.wifi)),
|
||||
style: FilledButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
),
|
||||
child: Text(l10n.whatsNewLinkNearbyAllow),
|
||||
Icon(
|
||||
context.adaptiveIcon(allowed ? Icons.check_circle : Icons.info),
|
||||
color: color,
|
||||
),
|
||||
if (_refused) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.networkErrorLocalPermission,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
allowed
|
||||
? l10n.whatsNewLinkNearbyGranted
|
||||
: l10n.whatsNewNearbyRefused,
|
||||
style: theme.textTheme.titleSmall?.copyWith(color: color),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show LogicalKeyboardKey;
|
||||
import 'package:flutter/services.dart' show LogicalKeyboardKey, MethodChannel;
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -11,6 +11,7 @@ import 'package:mornye/l10n/app_localizations.dart';
|
||||
import 'package:mornye/models/settings.dart';
|
||||
import 'package:mornye/providers/settings_provider.dart';
|
||||
import 'package:mornye/screens/whats_new_screen.dart';
|
||||
import 'package:mornye/services/local_network_access.dart';
|
||||
import 'package:mornye/theme/mornye_theme.dart';
|
||||
|
||||
class _Preferences implements SharedPreferences {
|
||||
@@ -44,6 +45,44 @@ class _Settings extends SettingsNotifier {
|
||||
|
||||
const _updated = AppSettings(isFirstLaunch: false, hasCompletedTutorial: true);
|
||||
|
||||
/// Opens the tour as Android 17 without Nearby devices; Android answers a
|
||||
/// request with [allow].
|
||||
Future<void> _openNearbyTour(WidgetTester tester, {required bool allow}) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
const channel = MethodChannel('com.zarz.mornye/local_network');
|
||||
final messenger = tester.binding.defaultBinaryMessenger;
|
||||
var granted = false;
|
||||
messenger.setMockMethodCallHandler(channel, (call) async {
|
||||
if (call.method == 'request') granted = allow;
|
||||
return granted;
|
||||
});
|
||||
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
settingsProvider.overrideWith(() => _Settings(_updated, _Preferences())),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: WhatsNewScreen(
|
||||
localNetworkAccess: LocalNetworkAccess(
|
||||
isAndroid: true,
|
||||
channel: channel,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('only an update shows the tour, after setup and the tutorial', () {
|
||||
expect(
|
||||
@@ -126,21 +165,19 @@ void main() {
|
||||
final iPhone = titles(androidPhone: false, desktop: false);
|
||||
expect(iPhone, isNot(contains(l10n.whatsNewPlayerAutoTitle)));
|
||||
expect(iPhone, isNot(contains(l10n.whatsNewPlayerExclusiveTitle)));
|
||||
// Only Android phones ask for Nearby devices, on the Link page.
|
||||
List<String> asking({required bool androidPhone, required bool desktop}) =>
|
||||
[
|
||||
for (final page in whatsNewHighlights(
|
||||
l10n,
|
||||
androidPhone: androidPhone,
|
||||
desktop: desktop,
|
||||
))
|
||||
if (page.asksNearbyDevices) page.title,
|
||||
];
|
||||
expect(asking(androidPhone: true, desktop: false), [
|
||||
l10n.whatsNewLinkTitle,
|
||||
]);
|
||||
expect(asking(androidPhone: false, desktop: true), isEmpty);
|
||||
expect(asking(androidPhone: false, desktop: false), isEmpty);
|
||||
// The Nearby devices page follows Mornye Link only when asked for, and
|
||||
// the overview leaves it out.
|
||||
final asking = whatsNewHighlights(l10n, nearbyDevices: true);
|
||||
expect(asking[1].title, l10n.whatsNewLinkTitle);
|
||||
expect(asking[2].nearbyDevices, isTrue);
|
||||
expect(asking.where((page) => page.nearbyDevices), hasLength(1));
|
||||
expect([
|
||||
for (final feature in asking.first.features) feature.title,
|
||||
], isNot(contains(l10n.whatsNewNearbyTitle)));
|
||||
expect(
|
||||
whatsNewHighlights(l10n).where((page) => page.nearbyDevices),
|
||||
isEmpty,
|
||||
);
|
||||
|
||||
// The opening page names every section that follows it.
|
||||
final pages = whatsNewHighlights(l10n, androidPhone: true, desktop: false);
|
||||
@@ -156,6 +193,49 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Skip stops at Nearby devices, which waits for an answer', (
|
||||
tester,
|
||||
) async {
|
||||
await _openNearbyTour(tester, allow: false);
|
||||
final skip = find.text('Skip for now').hitTestable();
|
||||
|
||||
await tester.tap(skip);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Nearby devices'), findsOne);
|
||||
// No Skip, no Continue and no swiping on until Android answers.
|
||||
expect(skip, findsNothing);
|
||||
expect(find.text('Continue'), findsNothing);
|
||||
await tester.drag(find.byType(PageView), const Offset(-300, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Nearby devices'), findsOne);
|
||||
|
||||
await tester.tap(find.text('Allow nearby devices'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('Not allowed.'), findsOne);
|
||||
expect(skip, findsOne);
|
||||
await tester.tap(find.text('Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('A Home that learns'), findsOne);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('allowing Nearby devices confirms it and moves on', (
|
||||
tester,
|
||||
) async {
|
||||
await _openNearbyTour(tester, allow: true);
|
||||
await tester.tap(find.text('Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Allow nearby devices'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Nearby devices allowed'), findsOne);
|
||||
await tester.tap(find.text('Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('A Home that learns'), findsOne);
|
||||
});
|
||||
|
||||
for (final mornye in [false, true]) {
|
||||
final style = mornye ? 'Mornye' : 'Material';
|
||||
|
||||
|
||||
Reference in new issue
Block a user