Browse Source

Merge pull request #271 from provokateurin/fix/unable-to-open-file

Display error message when file can't be opened
pull/273/head
Kate 2 years ago committed by GitHub
parent
commit
2a6ae25db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/neon/neon/lib/l10n/en.arb
  2. 6
      packages/neon/neon/lib/l10n/localizations.dart
  3. 3
      packages/neon/neon/lib/l10n/localizations_en.dart
  4. 2
      packages/neon/neon/lib/neon.dart
  5. 10
      packages/neon/neon/lib/src/utils/bloc.dart
  6. 2
      packages/neon/neon/lib/src/utils/exceptions.dart
  7. 6
      packages/neon/neon/lib/src/widgets/exception.dart
  8. 5
      packages/neon/neon_files/lib/blocs/files.dart

1
packages/neon/neon/lib/l10n/en.arb

@ -34,6 +34,7 @@
}
}
},
"errorUnableToOpenFile": "Unable to open the file",
"errorUnsupportedVersion": "Sorry, this Nextcloud {name} version is not supported.",
"@errorUnsupportedVersion" : {
"placeholders": {

6
packages/neon/neon/lib/l10n/localizations.dart

@ -179,6 +179,12 @@ abstract class AppLocalizations {
/// **'Permission for {name} is missing'**
String errorMissingPermission(String name);
/// No description provided for @errorUnableToOpenFile.
///
/// In en, this message translates to:
/// **'Unable to open the file'**
String get errorUnableToOpenFile;
/// No description provided for @errorUnsupportedVersion.
///
/// In en, this message translates to:

3
packages/neon/neon/lib/l10n/localizations_en.dart

@ -72,6 +72,9 @@ class AppLocalizationsEn extends AppLocalizations {
return 'Permission for $name is missing';
}
@override
String get errorUnableToOpenFile => 'Unable to open the file';
@override
String errorUnsupportedVersion(String name) {
return 'Sorry, this Nextcloud $name version is not supported.';

2
packages/neon/neon/lib/neon.dart

@ -72,12 +72,12 @@ part 'src/utils/app_implementation.dart';
part 'src/utils/bloc.dart';
part 'src/utils/branding.dart';
part 'src/utils/confirmation_dialog.dart';
part 'src/utils/exceptions.dart';
part 'src/utils/global.dart';
part 'src/utils/global_options.dart';
part 'src/utils/global_popups.dart';
part 'src/utils/hex_color.dart';
part 'src/utils/localizations.dart';
part 'src/utils/missing_permission_exception.dart';
part 'src/utils/nextcloud_app_specific_options.dart';
part 'src/utils/push_utils.dart';
part 'src/utils/rename_dialog.dart';

10
packages/neon/neon/lib/src/utils/bloc.dart

@ -16,7 +16,7 @@ abstract class InteractiveBloc extends Bloc {
Future refresh();
void addError(final Object error) {
_errorsStreamController.add(e);
_errorsStreamController.add(error);
}
// ignore: avoid_void_async
@ -33,10 +33,10 @@ abstract class InteractiveBloc extends Bloc {
}
await (refresh ?? this.refresh)();
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());
addError(e);
} catch (error, stacktrace) {
debugPrint(error.toString());
debugPrint(stacktrace.toString());
addError(error);
}
}
}

2
packages/neon/neon/lib/src/utils/missing_permission_exception.dart → packages/neon/neon/lib/src/utils/exceptions.dart

@ -5,3 +5,5 @@ class MissingPermissionException implements Exception {
final Permission permission;
}
class UnableToOpenFileException implements Exception {}

6
packages/neon/neon/lib/src/widgets/exception.dart

@ -108,6 +108,12 @@ class NeonException extends StatelessWidget {
);
}
if (exception is UnableToOpenFileException) {
return _ExceptionDetails(
text: AppLocalizations.of(context).errorUnableToOpenFile,
);
}
if (exception is NextcloudApiException) {
if (exception.statusCode == 401) {
return _ExceptionDetails(

5
packages/neon/neon_files/lib/blocs/files.dart

@ -101,7 +101,10 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
}
await _downloadFile(path, file);
}
await OpenFile.open(file.path, type: mimeType);
final result = await OpenFile.open(file.path, type: mimeType);
if (result.type != ResultType.done) {
throw UnableToOpenFileException();
}
},
disableTimeout: true,
);

Loading…
Cancel
Save