Skip to content

Commit

Permalink
Avoid shutdown if theme changes during file selection
Browse files Browse the repository at this point in the history
There is a bug where if the theme changes at all on the Android native files app (via system theme) then it can force the app to rebuild while importing which can then get it into a state where it accesses the import page too early. One of the checks it would run to is if the imported file exist. This fails and so results in the 'file removed' briefly showing up.
While not a proper fix, this change helps avoid running into the import page too early by showing a loading page instead during the import process should this specific case happen. This loading page may briefly appear outside this case but generally it shouldn't.
  • Loading branch information
uintdev committed Feb 8, 2023
1 parent 2362a48 commit 39bbae2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 7 additions & 1 deletion lib/filemanager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class FileManager {
static String archivedLast = '';

static bool fileImported = false;
static bool fileImportPending = false;
static bool multipleFiles = false;
static bool allowWatcher = false;
final bool allowMultipleFiles = (Platform.isAndroid);
Expand Down Expand Up @@ -60,6 +61,7 @@ class FileManager {

Future selectFile(BuildContext context,
[Map<String, dynamic> fileSelection = const {}]) async {
FileManager.fileImportPending = true;
Map<String, dynamic> result = {'files': {}};

String cacheDir = await FileManager().filePickerPath();
Expand Down Expand Up @@ -100,7 +102,10 @@ class FileManager {
result = fileSelection;
}

if (result.containsKey('files') && result['files'].length == 0) return;
if (result.containsKey('files') && result['files'].length == 0) {
FileManager.fileImportPending = false;
return;
}

await Network().internalIP();
if (Network.interfaceList.isEmpty) {
Expand Down Expand Up @@ -207,5 +212,6 @@ class FileManager {
// Initiate server
await Network().fetchInterfaces(context);
}
FileManager.fileImportPending = false;
}
}
21 changes: 15 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,20 @@ class _Page extends State<PageState> with WidgetsBindingObserver {
index++;
}

await FileManager().selectFile(context, fileSelection).whenComplete(() {
// Update state
setState(() {
_actionButtonLoading = false;
_stateView = StateManagerPage();
try {
await FileManager().selectFile(context, fileSelection).whenComplete(() {
setState(() {
_actionButtonLoading = false;
_stateView = StateManagerPage();
});
});
});
} catch (error) {
showToast(AppLocalizations.of(context)!
.info_exception_fileselection_fallback +
error.toString());
} finally {
FileManager.fileImportPending = false;
}
}

if (!StateManager().isDesktop) {
Expand Down Expand Up @@ -265,6 +272,8 @@ class _Page extends State<PageState> with WidgetsBindingObserver {
showToast(
AppLocalizations.of(context)!.info_exception_fileselection_fallback +
error.toString());
} finally {
FileManager.fileImportPending = false;
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/statemanager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class StateManager extends State<StateManagerPage> {
@override
Widget build(BuildContext context) {
Widget _outputState;
if (pageTypeCurrent == PageType.imported) {
if (FileManager.fileImportPending) {
_outputState = loadingPage();
} else if (pageTypeCurrent == PageType.imported) {
_outputState = importedPage(context);
} else {
_outputState = msgPage(context);
Expand Down

0 comments on commit 39bbae2

Please sign in to comment.