#1008 opening app from launcher shows home page only when exited by back button

This commit is contained in:
Thibault Deckers 2024-06-09 00:37:30 +02:00
parent 1578d2d944
commit 27cf1bf4aa
4 changed files with 108 additions and 81 deletions

View file

@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
### Changed
- opening app from launcher shows home page only when exited by back button
- Screen saver: black background, consistent with slideshow
- upgraded Flutter to stable v3.22.2

View file

@ -285,10 +285,10 @@ open class MainActivity : FlutterFragmentActivity() {
open fun extractIntentData(intent: Intent?): FieldMap {
when (val action = intent?.action) {
Intent.ACTION_MAIN -> {
val fields = hashMapOf<String, Any?>(
INTENT_DATA_KEY_LAUNCHER to intent.hasCategory(Intent.CATEGORY_LAUNCHER),
INTENT_DATA_KEY_SAFE_MODE to intent.getBooleanExtra(EXTRA_KEY_SAFE_MODE, false),
)
val fields = HashMap<String, Any?>()
if (intent.getBooleanExtra(EXTRA_KEY_SAFE_MODE, false)) {
fields[INTENT_DATA_KEY_SAFE_MODE] = true
}
intent.getStringExtra(EXTRA_KEY_PAGE)?.let { page ->
val filters = extractFiltersFromIntent(intent)
fields[INTENT_DATA_KEY_PAGE] = page
@ -497,7 +497,6 @@ open class MainActivity : FlutterFragmentActivity() {
const val INTENT_DATA_KEY_ACTION = "action"
const val INTENT_DATA_KEY_ALLOW_MULTIPLE = "allowMultiple"
const val INTENT_DATA_KEY_FILTERS = "filters"
const val INTENT_DATA_KEY_LAUNCHER = "launcher"
const val INTENT_DATA_KEY_MIME_TYPE = "mimeType"
const val INTENT_DATA_KEY_PAGE = "page"
const val INTENT_DATA_KEY_QUERY = "query"

View file

@ -26,6 +26,7 @@ import 'package:aves/theme/themes.dart';
import 'package:aves/widgets/collection/collection_grid.dart';
import 'package:aves/widgets/collection/collection_page.dart';
import 'package:aves/widgets/common/basic/scaffold.dart';
import 'package:aves/widgets/common/behaviour/pop/scope.dart';
import 'package:aves/widgets/common/behaviour/route_tracker.dart';
import 'package:aves/widgets/common/behaviour/routes.dart';
import 'package:aves/widgets/common/extensions/build_context.dart';
@ -178,6 +179,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
static const defaultPageTransitionsBuilder = FadeUpwardsPageTransitionsBuilder();
static final GlobalKey<NavigatorState> _navigatorKey = GlobalKey(debugLabel: 'app-navigator');
static ScreenBrightness? _screenBrightness;
static bool _exitedMainByPop = false;
@override
void initState() {
@ -224,6 +226,13 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
DurationsProvider(),
HighlightInfoProvider(),
],
child: NotificationListener<PopExitNotification>(
onNotification: (notification) {
if (_appModeNotifier.value == AppMode.main) {
_exitedMainByPop = true;
}
return true;
},
child: OverlaySupport(
child: FutureBuilder<void>(
future: _appSetup,
@ -303,6 +312,7 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
},
),
),
),
);
}
@ -615,6 +625,18 @@ class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {
void _onNewIntent(Map? intentData) {
reportService.log('New intent data=$intentData');
if (_appModeNotifier.value == AppMode.main) {
// do not reset when relaunching the app, except when exiting by pop
final shouldReset = _exitedMainByPop;
_exitedMainByPop = false;
if (!shouldReset && (intentData ?? {}).isEmpty) {
reportService.log('Relaunch');
return;
}
}
_navigatorKey.currentState!.pushReplacement(DirectMaterialPageRoute(
settings: const RouteSettings(name: HomePage.routeName),
builder: (_) => _getFirstPage(intentData: intentData),

View file

@ -1,4 +1,5 @@
import 'package:aves/services/common/services.dart';
import 'package:aves/widgets/aves_app.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
@ -28,6 +29,7 @@ class AvesPopScope extends StatelessWidget {
} else {
// exit
reportService.log('Exit by pop');
PopExitNotification().dispatch(context);
SystemNavigator.pop();
}
}
@ -36,3 +38,6 @@ class AvesPopScope extends StatelessWidget {
);
}
}
@immutable
class PopExitNotification extends Notification {}