added cache folder sweep check before file actions, preventing errors
This commit is contained in:
@@ -14,8 +14,11 @@ import 'package:share_plus/share_plus.dart';
|
||||
import '../routing/app_routes.dart';
|
||||
import '../share_intent/remote_file_ref.dart';
|
||||
import '../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../utils/downloads/download_manager.dart';
|
||||
import 'app_progress_indicator.dart';
|
||||
import 'async_action_button.dart';
|
||||
import 'centered_leading.dart';
|
||||
import 'confirm_dialog.dart';
|
||||
import 'file_viewer/code_line.dart';
|
||||
import 'file_viewer/deferred_pdf_viewer.dart';
|
||||
import 'file_viewer/file_kind.dart';
|
||||
@@ -82,9 +85,43 @@ class _FileViewerState extends State<FileViewer> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Android may clear the cache dir behind an open viewer at any time —
|
||||
/// verify the file is still there before handing its path to an action.
|
||||
bool _ensureLocalFile() {
|
||||
if (File(widget.path).existsSync()) return true;
|
||||
final remote = widget.remoteFile;
|
||||
if (remote == null) {
|
||||
InfoDialog.show(
|
||||
context,
|
||||
'Die Datei wurde vom System aus dem Zwischenspeicher entfernt. Bitte lade sie erneut herunter.',
|
||||
title: 'Datei nicht mehr verfügbar',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
ConfirmDialog(
|
||||
title: 'Datei nicht mehr verfügbar',
|
||||
content:
|
||||
'Die Datei wurde vom System aus dem Zwischenspeicher entfernt.\nErneut herunterladen?',
|
||||
confirmButton: 'Herunterladen',
|
||||
onConfirm: () {
|
||||
// Pop the viewer before starting so the fresh download auto-opens.
|
||||
Navigator.of(context).pop();
|
||||
unawaited(
|
||||
DownloadManager.instance.start(
|
||||
remotePath: remote.path,
|
||||
name: remote.name,
|
||||
remoteFile: remote,
|
||||
),
|
||||
);
|
||||
},
|
||||
).asDialog(context);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> _handleAction(FileViewingActions value) async {
|
||||
switch (value) {
|
||||
case FileViewingActions.openExternal:
|
||||
if (!_ensureLocalFile()) return;
|
||||
AppRoutes.openFileViewer(
|
||||
context,
|
||||
widget.path,
|
||||
@@ -99,16 +136,21 @@ class _FileViewerState extends State<FileViewer> {
|
||||
AppRoutes.openInternalSaveToFolder(context, widget.remoteFile!);
|
||||
break;
|
||||
case FileViewingActions.share:
|
||||
if (!_ensureLocalFile()) return;
|
||||
unawaited(
|
||||
SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [XFile(widget.path)],
|
||||
sharePositionOrigin: SharePositionOrigin.get(context),
|
||||
runWithErrorDialog(
|
||||
context,
|
||||
() => SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [XFile(widget.path)],
|
||||
sharePositionOrigin: SharePositionOrigin.get(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
break;
|
||||
case FileViewingActions.save:
|
||||
if (!_ensureLocalFile()) return;
|
||||
try {
|
||||
final source = File(widget.path);
|
||||
final size = await source.length();
|
||||
|
||||
Reference in New Issue
Block a user