Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

407-importing-token-from-deeplink-otpauth-migration #408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import '../../../utils/home_widget_utils.dart';
import '../../../utils/logger.dart';
import '../../../utils/riverpod_providers.dart';
import '../../../views/link_home_widget_view/link_home_widget_view.dart';
import '../../../views/splash_screen/splash_screen.dart';
import 'navigation_scheme_processor_interface.dart';

class HomeWidgetNavigateProcessor implements NavigationSchemeProcessor {
Expand Down Expand Up @@ -42,15 +41,13 @@ class HomeWidgetNavigateProcessor implements NavigationSchemeProcessor {
return;
}
if (fromInit) {
SplashScreen.setInitialView(
LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!),
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!)),
);
} else {
Navigator.popUntil(context, (route) => route.isFirst);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!),
),
MaterialPageRoute(builder: (context) => LinkHomeWidgetView(homeWidgetId: uri.queryParameters['id']!)),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/state_notifiers/token_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ class TokenNotifier extends StateNotifier<TokenState> {
Future<List<Token>> _tokensFromUri(Uri uri) async {
try {
final results = await TokenImportSchemeProcessor.processUriByAny(uri);
// final anyConflict = tokens.any((newToken) => state.tokens.any((stateToken) => stateToken.sameValuesAs(newToken)));
if (results != null && results.length > 1) {
if (results != null && (results.length > 1 || state.tokens.any((e) => results.first.asSuccess?.resultData.isSameTokenAs(e) == true))) {
Navigator.of(globalNavigatorKey.currentContext!).popUntil((route) => route.isFirst);
final tokensToKeep = await Navigator.of(globalNavigatorKey.currentContext!).push<List<Token>>(
MaterialPageRoute<List<Token>>(
builder: (context) => ImportPlainTokensPage(
Expand Down
73 changes: 12 additions & 61 deletions lib/views/splash_screen/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,10 @@ import '../view_interface.dart';

class SplashScreen extends ConsumerStatefulWidget {
static const routeName = '/';
static Widget? _initialView;
static bool didNavigated = false;

final ApplicationCustomization customization;

const SplashScreen({required this.customization, super.key});

@override
ConsumerState<SplashScreen> createState() => _SplashScreenState();

static void setInitialView(Widget initialView) {
if (_initialView != null) {
Logger.warning('Initial view is already set. Ignoring new initial view: $initialView', name: 'splash_screen.dart#setInitialView');
return;
}
if (didNavigated) {
Logger.warning('Splashscreen already navigated. Ignoring new initial view: $initialView', name: 'splash_screen.dart#setInitialView');
return;
}
_initialView = initialView;
}
}

class _SplashScreenState extends ConsumerState<SplashScreen> {
Expand All @@ -53,11 +36,8 @@ class _SplashScreenState extends ConsumerState<SplashScreen> {

Logger.info('Starting app.', name: 'main.dart#initState');
Future.delayed(_splashScreenDelay, () {
if (mounted) {
setState(() {
_appIconIsVisible = true;
});
}
if (mounted) setState(() => _appIconIsVisible = true);

Future.wait(
<Future>[
Future.delayed(_splashScreenDuration),
Expand Down Expand Up @@ -87,29 +67,7 @@ class _SplashScreenState extends ConsumerState<SplashScreen> {
super.dispose();
}

Future<void> _navigate() async {
SplashScreen.didNavigated = true;
if (SplashScreen._initialView != null) {
await Navigator.push<bool>(
context,
PageRouteBuilder(
pageBuilder: (_, __, ___) => SplashScreen._initialView!,
transitionDuration: _splashScreenDuration,
transitionsBuilder: (_, a, __, view) => FadeTransition(
opacity: CurvedAnimation(
curve: const Interval(0, 1, curve: Curves.easeOut),
parent: a,
),
child: view,
),
),
);
}
if (!mounted) return;
_pushReplace();
}

void _pushReplace() {
void _navigate() async {
if (_customization.disabledFeatures.isNotEmpty) {
Logger.info('Disabled features: ${_customization.disabledFeatures}', name: 'main.dart#_pushReplace');
}
Expand All @@ -118,22 +76,15 @@ class _SplashScreenState extends ConsumerState<SplashScreen> {
appIcon: _customization.appIcon,
disablePatchNotes: _customization.disabledFeatures.contains(AppFeature.patchNotes),
);
final routeBuilder = SplashScreen._initialView == null
? PageRouteBuilder(
pageBuilder: (_, __, ___) => nextView,
transitionDuration: _splashScreenDuration,
settings: nextView.routeSettings,
transitionsBuilder: (_, a, __, view) => FadeTransition(
opacity: CurvedAnimation(
curve: const Interval(0, 1, curve: Curves.easeOut),
parent: a,
),
child: view,
),
)
: PageRouteBuilder(
pageBuilder: (_, __, ___) => nextView,
);
final routeBuilder = PageRouteBuilder(pageBuilder: (_, __, ___) => nextView);
// Idle until the splash screen is the top route.
// By default it is the top route, but it can be overridden by pushing a new route before initializing the app, e.g. by a deep link.
await Future.doWhile(() async {
await Future.delayed(const Duration(milliseconds: 100));
if (!mounted) return false;
return (ModalRoute.of(context)?.isCurrent == false);
});
if (!mounted) return;
Navigator.of(context).popUntil((route) => route.isFirst);
Navigator.pushReplacement(context, routeBuilder);
}
Expand Down
Loading