improved app mode init, fallback
This commit is contained in:
parent
877fde1b26
commit
61ccb04caa
2 changed files with 60 additions and 56 deletions
|
@ -229,6 +229,7 @@ open class MainActivity : FlutterFragmentActivity() {
|
||||||
intentStreamHandler.notifyNewIntent(extractIntentData(intent))
|
intentStreamHandler.notifyNewIntent(extractIntentData(intent))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
|
|
|
@ -90,9 +90,10 @@ class _HomePageState extends State<HomePage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
var appMode = AppMode.main;
|
var appMode = AppMode.main;
|
||||||
|
var error = false;
|
||||||
final intentData = widget.intentData ?? await IntentService.getIntentData();
|
final intentData = widget.intentData ?? await IntentService.getIntentData();
|
||||||
final safeMode = intentData[IntentDataKeys.safeMode] ?? false;
|
final safeMode = (intentData[IntentDataKeys.safeMode] as bool?) ?? false;
|
||||||
final intentAction = intentData[IntentDataKeys.action];
|
final intentAction = intentData[IntentDataKeys.action] as String?;
|
||||||
_initialFilters = null;
|
_initialFilters = null;
|
||||||
_initialExplorerPath = null;
|
_initialExplorerPath = null;
|
||||||
_secureUris = null;
|
_secureUris = null;
|
||||||
|
@ -109,61 +110,22 @@ class _HomePageState extends State<HomePage> {
|
||||||
|
|
||||||
if (intentData.values.whereNotNull().isNotEmpty) {
|
if (intentData.values.whereNotNull().isNotEmpty) {
|
||||||
await reportService.log('Intent data=$intentData');
|
await reportService.log('Intent data=$intentData');
|
||||||
|
var intentUri = intentData[IntentDataKeys.uri] as String?;
|
||||||
|
final intentMimeType = intentData[IntentDataKeys.mimeType] as String?;
|
||||||
|
|
||||||
switch (intentAction) {
|
switch (intentAction) {
|
||||||
case IntentActions.view:
|
case IntentActions.view:
|
||||||
case IntentActions.widgetOpen:
|
appMode = AppMode.view;
|
||||||
String? uri, mimeType;
|
_secureUris = (intentData[IntentDataKeys.secureUris] as List?)?.cast<String>();
|
||||||
final widgetId = intentData[IntentDataKeys.widgetId];
|
|
||||||
if (widgetId != null) {
|
|
||||||
// widget settings may be modified in a different process after channel setup
|
|
||||||
await settings.reload();
|
|
||||||
final page = settings.getWidgetOpenPage(widgetId);
|
|
||||||
switch (page) {
|
|
||||||
case WidgetOpenPage.home:
|
|
||||||
case WidgetOpenPage.updateWidget:
|
|
||||||
break;
|
|
||||||
case WidgetOpenPage.collection:
|
|
||||||
_initialFilters = settings.getWidgetCollectionFilters(widgetId);
|
|
||||||
case WidgetOpenPage.viewer:
|
|
||||||
uri = settings.getWidgetUri(widgetId);
|
|
||||||
}
|
|
||||||
unawaited(WidgetService.update(widgetId));
|
|
||||||
} else {
|
|
||||||
uri = intentData[IntentDataKeys.uri];
|
|
||||||
mimeType = intentData[IntentDataKeys.mimeType];
|
|
||||||
}
|
|
||||||
_secureUris = intentData[IntentDataKeys.secureUris];
|
|
||||||
if (uri != null) {
|
|
||||||
_viewerEntry = await _initViewerEntry(
|
|
||||||
uri: uri,
|
|
||||||
mimeType: mimeType,
|
|
||||||
);
|
|
||||||
if (_viewerEntry != null) {
|
|
||||||
appMode = AppMode.view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case IntentActions.edit:
|
case IntentActions.edit:
|
||||||
_viewerEntry = await _initViewerEntry(
|
appMode = AppMode.edit;
|
||||||
uri: intentData[IntentDataKeys.uri],
|
|
||||||
mimeType: intentData[IntentDataKeys.mimeType],
|
|
||||||
);
|
|
||||||
if (_viewerEntry != null) {
|
|
||||||
appMode = AppMode.edit;
|
|
||||||
}
|
|
||||||
case IntentActions.setWallpaper:
|
case IntentActions.setWallpaper:
|
||||||
_viewerEntry = await _initViewerEntry(
|
appMode = AppMode.setWallpaper;
|
||||||
uri: intentData[IntentDataKeys.uri],
|
|
||||||
mimeType: intentData[IntentDataKeys.mimeType],
|
|
||||||
);
|
|
||||||
if (_viewerEntry != null) {
|
|
||||||
appMode = AppMode.setWallpaper;
|
|
||||||
}
|
|
||||||
case IntentActions.pickItems:
|
case IntentActions.pickItems:
|
||||||
// TODO TLAD apply pick mimetype(s)
|
// TODO TLAD apply pick mimetype(s)
|
||||||
// some apps define multiple types, separated by a space (maybe other signs too, like `,` `;`?)
|
// some apps define multiple types, separated by a space (maybe other signs too, like `,` `;`?)
|
||||||
String? pickMimeTypes = intentData[IntentDataKeys.mimeType];
|
final multiple = (intentData[IntentDataKeys.allowMultiple] as bool?) ?? false;
|
||||||
final multiple = intentData[IntentDataKeys.allowMultiple] ?? false;
|
debugPrint('pick mimeType=$intentMimeType multiple=$multiple');
|
||||||
debugPrint('pick mimeType=$pickMimeTypes multiple=$multiple');
|
|
||||||
appMode = multiple ? AppMode.pickMultipleMediaExternal : AppMode.pickSingleMediaExternal;
|
appMode = multiple ? AppMode.pickMultipleMediaExternal : AppMode.pickSingleMediaExternal;
|
||||||
case IntentActions.pickCollectionFilters:
|
case IntentActions.pickCollectionFilters:
|
||||||
appMode = AppMode.pickCollectionFiltersExternal;
|
appMode = AppMode.pickCollectionFiltersExternal;
|
||||||
|
@ -174,23 +136,64 @@ class _HomePageState extends State<HomePage> {
|
||||||
_initialRouteName = ScreenSaverSettingsPage.routeName;
|
_initialRouteName = ScreenSaverSettingsPage.routeName;
|
||||||
case IntentActions.search:
|
case IntentActions.search:
|
||||||
_initialRouteName = SearchPage.routeName;
|
_initialRouteName = SearchPage.routeName;
|
||||||
_initialSearchQuery = intentData[IntentDataKeys.query];
|
_initialSearchQuery = intentData[IntentDataKeys.query] as String?;
|
||||||
case IntentActions.widgetSettings:
|
case IntentActions.widgetSettings:
|
||||||
_initialRouteName = HomeWidgetSettingsPage.routeName;
|
_initialRouteName = HomeWidgetSettingsPage.routeName;
|
||||||
_widgetId = intentData[IntentDataKeys.widgetId] ?? 0;
|
_widgetId = (intentData[IntentDataKeys.widgetId] as int?) ?? 0;
|
||||||
|
case IntentActions.widgetOpen:
|
||||||
|
final widgetId = intentData[IntentDataKeys.widgetId] as int?;
|
||||||
|
if (widgetId == null) {
|
||||||
|
error = true;
|
||||||
|
} else {
|
||||||
|
// widget settings may be modified in a different process after channel setup
|
||||||
|
await settings.reload();
|
||||||
|
final page = settings.getWidgetOpenPage(widgetId);
|
||||||
|
switch (page) {
|
||||||
|
case WidgetOpenPage.collection:
|
||||||
|
_initialFilters = settings.getWidgetCollectionFilters(widgetId);
|
||||||
|
case WidgetOpenPage.viewer:
|
||||||
|
appMode = AppMode.view;
|
||||||
|
intentUri = settings.getWidgetUri(widgetId);
|
||||||
|
case WidgetOpenPage.home:
|
||||||
|
case WidgetOpenPage.updateWidget:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
unawaited(WidgetService.update(widgetId));
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// do not use 'route' as extra key, as the Flutter framework acts on it
|
// do not use 'route' as extra key, as the Flutter framework acts on it
|
||||||
final extraRoute = intentData[IntentDataKeys.page];
|
final extraRoute = intentData[IntentDataKeys.page] as String?;
|
||||||
if (allowedShortcutRoutes.contains(extraRoute)) {
|
if (allowedShortcutRoutes.contains(extraRoute)) {
|
||||||
_initialRouteName = extraRoute;
|
_initialRouteName = extraRoute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_initialFilters == null) {
|
if (_initialFilters == null) {
|
||||||
final extraFilters = intentData[IntentDataKeys.filters];
|
final extraFilters = (intentData[IntentDataKeys.filters] as List?)?.cast<String>();
|
||||||
_initialFilters = extraFilters != null ? (extraFilters as List).cast<String>().map(CollectionFilter.fromJson).whereNotNull().toSet() : null;
|
_initialFilters = extraFilters?.map(CollectionFilter.fromJson).whereNotNull().toSet();
|
||||||
|
}
|
||||||
|
_initialExplorerPath = intentData[IntentDataKeys.explorerPath] as String?;
|
||||||
|
|
||||||
|
switch (appMode) {
|
||||||
|
case AppMode.view:
|
||||||
|
case AppMode.edit:
|
||||||
|
case AppMode.setWallpaper:
|
||||||
|
if (intentUri != null) {
|
||||||
|
_viewerEntry = await _initViewerEntry(
|
||||||
|
uri: intentUri,
|
||||||
|
mimeType: intentMimeType,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
error = _viewerEntry == null;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
_initialExplorerPath = intentData[IntentDataKeys.explorerPath];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
debugPrint('Failed to init app mode=$appMode for intent data=$intentData. Fallback to main mode.');
|
||||||
|
appMode = AppMode.main;
|
||||||
|
}
|
||||||
|
|
||||||
context.read<ValueNotifier<AppMode>>().value = appMode;
|
context.read<ValueNotifier<AppMode>>().value = appMode;
|
||||||
unawaited(reportService.setCustomKey('app_mode', appMode.toString()));
|
unawaited(reportService.setCustomKey('app_mode', appMode.toString()));
|
||||||
debugPrint('Storage check complete in ${stopwatch.elapsed.inMilliseconds}ms');
|
debugPrint('Storage check complete in ${stopwatch.elapsed.inMilliseconds}ms');
|
||||||
|
|
Loading…
Reference in a new issue