An open-source cross-platform alternative to AirDrop
feature: Added auto-closing dialog (#1917)
Himanshu04c1aa36202f
diff --git a/app/assets/i18n/strings.json b/app/assets/i18n/strings.jsonindex db6e4431..8fc22128 100644--- a/app/assets/i18n/strings.json+++ b/app/assets/i18n/strings.json@@ -340,6 +340,9 @@"addFile": {"title": "Add to selection","content": "What do you want to add?"+ },"openFile": {+ "title": "Open file",+ "content": "Do you want to open received file?"},"addressInput": {"title": "Enter address",diff --git a/app/lib/gen/strings.g.dart b/app/lib/gen/strings.g.dartindex 553162b9..0cc5aeb7 100644--- a/app/lib/gen/strings.g.dart+++ b/app/lib/gen/strings.g.dart@@ -4,7 +4,7 @@/// To regenerate, run: `dart run slang`////// Locales: 45-/// Strings: 14252 (316 per locale)+/// Strings: 14254 (316 per locale)// coverage:ignore-file// ignore_for_file: type=lintdiff --git a/app/lib/gen/strings_en.g.dart b/app/lib/gen/strings_en.g.dartindex 46f657ff..816bfb71 100644--- a/app/lib/gen/strings_en.g.dart+++ b/app/lib/gen/strings_en.g.dart@@ -417,6 +417,7 @@ class _StringsDialogsEn {// Translationslate final _StringsDialogsAddFileEn addFile = _StringsDialogsAddFileEn._(_root);+ late final _StringsDialogsOpenFileEn openFile = _StringsDialogsOpenFileEn._(_root);late final _StringsDialogsAddressInputEn addressInput = _StringsDialogsAddressInputEn._(_root);late final _StringsDialogsCancelSessionEn cancelSession = _StringsDialogsCancelSessionEn._(_root);late final _StringsDialogsCannotOpenFileEn cannotOpenFile = _StringsDialogsCannotOpenFileEn._(_root);@@ -730,6 +731,17 @@ class _StringsDialogsAddFileEn {String get content => 'What do you want to add?';}+// Path: dialogs.openFile+class _StringsDialogsOpenFileEn {+ _StringsDialogsOpenFileEn._(this._root);++ final Translations _root; // ignore: unused_field++ // Translations+ String get title => 'Open file';+ String get content => 'Do you want to open received file?';+}+// Path: dialogs.addressInputclass _StringsDialogsAddressInputEn {_StringsDialogsAddressInputEn._(this._root);diff --git a/app/lib/provider/network/server/controller/receive_controller.dart b/app/lib/provider/network/server/controller/receive_controller.dartindex f6b75fc9..05f03d00 100644--- a/app/lib/provider/network/server/controller/receive_controller.dart+++ b/app/lib/provider/network/server/controller/receive_controller.dart@@ -13,7 +13,9 @@ import 'package:common/model/dto/register_dto.dart';import 'package:common/model/file_status.dart';import 'package:common/model/file_type.dart';import 'package:common/model/session_status.dart';+import 'package:flutter/cupertino.dart';import 'package:flutter/foundation.dart';+import 'package:flutter/material.dart';import 'package:localsend_app/model/state/send/send_session_state.dart';import 'package:localsend_app/model/state/server/receive_session_state.dart';import 'package:localsend_app/model/state/server/receiving_file.dart';@@ -40,6 +42,7 @@ import 'package:localsend_app/util/native/file_saver.dart';import 'package:localsend_app/util/native/platform_check.dart';import 'package:localsend_app/util/native/tray_helper.dart';import 'package:localsend_app/util/simple_server.dart';+import 'package:localsend_app/widget/dialogs/open_file_dialog.dart';import 'package:logging/logging.dart';import 'package:permission_handler/permission_handler.dart';import 'package:routerino/routerino.dart';@@ -441,17 +444,15 @@ class ReceiveController {),),);+ final fileType = receivingFile.file.fileType;+ final saveToGallery = receiveState.saveToGallery && (fileType == FileType.image || fileType == FileType.video);+ final (destinationPath, documentUri, finalName) = await digestFilePathAndPrepareDirectory(+ parentDirectory: saveToGallery ? receiveState.cacheDirectory : receiveState.destinationDirectory,+ fileName: receivingFile.desiredName!,+ createdDirectories: receiveState.createdDirectories,+ );try {- final fileType = receivingFile.file.fileType;- final saveToGallery = receiveState.saveToGallery && (fileType == FileType.image || fileType == FileType.video);-- final (destinationPath, documentUri, finalName) = await digestFilePathAndPrepareDirectory(- parentDirectory: saveToGallery ? receiveState.cacheDirectory : receiveState.destinationDirectory,- fileName: receivingFile.desiredName!,- createdDirectories: receiveState.createdDirectories,- );-_logger.info('Saving ${receivingFile.file.fileName} to $destinationPath');await saveFile(@@ -549,8 +550,20 @@ class ReceiveController {// close the session **after** return of the responseFuture.delayed(Duration.zero, () {closeSession();+ _logger.info('Closing session');+// ignore: use_build_context_synchronouslyRouterino.context.pushRootImmediately(() => const HomePage(initialTab: HomeTab.receive, appStart: false));++ /* open the dialog to open file instantly*/+ if (destinationPath.isNotEmpty) {+ OpenFileDialog.open(+ // ignore: use_build_context_synchronously+ Routerino.context,+ filePath: destinationPath,+ fileName: receivingFile.desiredName!,+ fileType: fileType);+ }});}_logger.info('Received all files.');diff --git a/app/lib/provider/param/apk_provider_param.mapper.dart b/app/lib/provider/param/apk_provider_param.mapper.dartindex 97d58fe7..e8c9e27a 100644--- a/app/lib/provider/param/apk_provider_param.mapper.dart+++ b/app/lib/provider/param/apk_provider_param.mapper.dart@@ -26,20 +26,23 @@ class ApkProviderParamMapper extends ClassMapperBase<ApkProviderParam> {static const Field<ApkProviderParam, bool> _f$includeSystemApps = Field('includeSystemApps', _$includeSystemApps);static bool _$onlyAppsWithLaunchIntent(ApkProviderParam v) => v.onlyAppsWithLaunchIntent;static const Field<ApkProviderParam, bool> _f$onlyAppsWithLaunchIntent = Field('onlyAppsWithLaunchIntent', _$onlyAppsWithLaunchIntent);+ static bool _$selectMultipleApps(ApkProviderParam v) => v.selectMultipleApps;+ static const Field<ApkProviderParam, bool> _f$selectMultipleApps = Field('selectMultipleApps', _$selectMultipleApps, opt: true, def: false);@overridefinal MappableFields<ApkProviderParam> fields = const {#query: _f$query,#includeSystemApps: _f$includeSystemApps,#onlyAppsWithLaunchIntent: _f$onlyAppsWithLaunchIntent,+ #selectMultipleApps: _f$selectMultipleApps,};static ApkProviderParam _instantiate(DecodingData data) {return ApkProviderParam(- query: data.dec(_f$query),- includeSystemApps: data.dec(_f$includeSystemApps),- onlyAppsWithLaunchIntent: data.dec(_f$onlyAppsWithLaunchIntent),- );+ query: data.dec(_f$query),+ includeSystemApps: data.dec(_f$includeSystemApps),+ onlyAppsWithLaunchIntent: data.dec(_f$onlyAppsWithLaunchIntent),+ selectMultipleApps: data.dec(_f$selectMultipleApps));}@override@@ -86,7 +89,7 @@ extension ApkProviderParamValueCopy<$R, $Out> on ObjectCopyWith<$R, ApkProviderP}abstract class ApkProviderParamCopyWith<$R, $In extends ApkProviderParam, $Out> implements ClassCopyWith<$R, $In, $Out> {- $R call({String? query, bool? includeSystemApps, bool? onlyAppsWithLaunchIntent});+ $R call({String? query, bool? includeSystemApps, bool? onlyAppsWithLaunchIntent, bool? selectMultipleApps});ApkProviderParamCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);}@@ -97,16 +100,18 @@ class _ApkProviderParamCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, ApkP@overridelate final ClassMapperBase<ApkProviderParam> $mapper = ApkProviderParamMapper.ensureInitialized();@override- $R call({String? query, bool? includeSystemApps, bool? onlyAppsWithLaunchIntent}) => $apply(FieldCopyWithData({+ $R call({String? query, bool? includeSystemApps, bool? onlyAppsWithLaunchIntent, bool? selectMultipleApps}) => $apply(FieldCopyWithData({if (query != null) #query: query,if (includeSystemApps != null) #includeSystemApps: includeSystemApps,- if (onlyAppsWithLaunchIntent != null) #onlyAppsWithLaunchIntent: onlyAppsWithLaunchIntent+ if (onlyAppsWithLaunchIntent != null) #onlyAppsWithLaunchIntent: onlyAppsWithLaunchIntent,+ if (selectMultipleApps != null) #selectMultipleApps: selectMultipleApps}));@overrideApkProviderParam $make(CopyWithData data) => ApkProviderParam(query: data.get(#query, or: $value.query),includeSystemApps: data.get(#includeSystemApps, or: $value.includeSystemApps),- onlyAppsWithLaunchIntent: data.get(#onlyAppsWithLaunchIntent, or: $value.onlyAppsWithLaunchIntent));+ onlyAppsWithLaunchIntent: data.get(#onlyAppsWithLaunchIntent, or: $value.onlyAppsWithLaunchIntent),+ selectMultipleApps: data.get(#selectMultipleApps, or: $value.selectMultipleApps));@overrideApkProviderParamCopyWith<$R2, ApkProviderParam, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => _ApkProviderParamCopyWithImpl($value, $cast, t);diff --git a/app/lib/provider/param/cached_apk_provider_param.mapper.dart b/app/lib/provider/param/cached_apk_provider_param.mapper.dartindex b537935b..083a8639 100644--- a/app/lib/provider/param/cached_apk_provider_param.mapper.dart+++ b/app/lib/provider/param/cached_apk_provider_param.mapper.dart@@ -24,15 +24,21 @@ class CachedApkProviderParamMapper extends ClassMapperBase<CachedApkProviderParastatic const Field<CachedApkProviderParam, bool> _f$includeSystemApps = Field('includeSystemApps', _$includeSystemApps);static bool _$onlyAppsWithLaunchIntent(CachedApkProviderParam v) => v.onlyAppsWithLaunchIntent;static const Field<CachedApkProviderParam, bool> _f$onlyAppsWithLaunchIntent = Field('onlyAppsWithLaunchIntent', _$onlyAppsWithLaunchIntent);+ static bool _$selectMultipleApps(CachedApkProviderParam v) => v.selectMultipleApps;+ static const Field<CachedApkProviderParam, bool> _f$selectMultipleApps = Field('selectMultipleApps', _$selectMultipleApps, opt: true, def: false);@overridefinal MappableFields<CachedApkProviderParam> fields = const {#includeSystemApps: _f$includeSystemApps,#onlyAppsWithLaunchIntent: _f$onlyAppsWithLaunchIntent,+ #selectMultipleApps: _f$selectMultipleApps,};static CachedApkProviderParam _instantiate(DecodingData data) {- return CachedApkProviderParam(includeSystemApps: data.dec(_f$includeSystemApps), onlyAppsWithLaunchIntent: data.dec(_f$onlyAppsWithLaunchIntent));+ return CachedApkProviderParam(+ includeSystemApps: data.dec(_f$includeSystemApps),+ onlyAppsWithLaunchIntent: data.dec(_f$onlyAppsWithLaunchIntent),+ selectMultipleApps: data.dec(_f$selectMultipleApps));}@override@@ -80,7 +86,7 @@ extension CachedApkProviderParamValueCopy<$R, $Out> on ObjectCopyWith<$R, Cached}abstract class CachedApkProviderParamCopyWith<$R, $In extends CachedApkProviderParam, $Out> implements ClassCopyWith<$R, $In, $Out> {- $R call({bool? includeSystemApps, bool? onlyAppsWithLaunchIntent});+ $R call({bool? includeSystemApps, bool? onlyAppsWithLaunchIntent, bool? selectMultipleApps});CachedApkProviderParamCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);}@@ -91,14 +97,16 @@ class _CachedApkProviderParamCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R@overridelate final ClassMapperBase<CachedApkProviderParam> $mapper = CachedApkProviderParamMapper.ensureInitialized();@override- $R call({bool? includeSystemApps, bool? onlyAppsWithLaunchIntent}) => $apply(FieldCopyWithData({+ $R call({bool? includeSystemApps, bool? onlyAppsWithLaunchIntent, bool? selectMultipleApps}) => $apply(FieldCopyWithData({if (includeSystemApps != null) #includeSystemApps: includeSystemApps,- if (onlyAppsWithLaunchIntent != null) #onlyAppsWithLaunchIntent: onlyAppsWithLaunchIntent+ if (onlyAppsWithLaunchIntent != null) #onlyAppsWithLaunchIntent: onlyAppsWithLaunchIntent,+ if (selectMultipleApps != null) #selectMultipleApps: selectMultipleApps}));@overrideCachedApkProviderParam $make(CopyWithData data) => CachedApkProviderParam(includeSystemApps: data.get(#includeSystemApps, or: $value.includeSystemApps),- onlyAppsWithLaunchIntent: data.get(#onlyAppsWithLaunchIntent, or: $value.onlyAppsWithLaunchIntent));+ onlyAppsWithLaunchIntent: data.get(#onlyAppsWithLaunchIntent, or: $value.onlyAppsWithLaunchIntent),+ selectMultipleApps: data.get(#selectMultipleApps, or: $value.selectMultipleApps));@overrideCachedApkProviderParamCopyWith<$R2, CachedApkProviderParam, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) =>diff --git a/app/lib/widget/dialogs/open_file_dialog.dart b/app/lib/widget/dialogs/open_file_dialog.dartnew file mode 100644index 00000000..ee2cae20--- /dev/null+++ b/app/lib/widget/dialogs/open_file_dialog.dart@@ -0,0 +1,90 @@+import 'dart:async';++import 'package:common/model/file_type.dart';+import 'package:flutter/material.dart';+import 'package:localsend_app/gen/strings.g.dart';+import 'package:localsend_app/util/native/open_file.dart';+import 'package:routerino/routerino.dart';++class OpenFileDialog extends StatefulWidget {+ final String fileName;+ final String filePath;+ final FileType fileType;++ const OpenFileDialog({super.key, required this.filePath, required this.fileName, required this.fileType});++ static Future<void> open(+ BuildContext context, {+ required String filePath,+ required String fileName,+ required FileType fileType,+ }) async {+ await showDialog(+ context: context,+ builder: (context) => OpenFileDialog(+ filePath: filePath,+ fileName: fileName,+ fileType: fileType,+ ),+ );+ }++ @override+ State<OpenFileDialog> createState() => _OpenFileDialogState();+}++class _OpenFileDialogState extends State<OpenFileDialog> {+ int _countdown = 3; // Starting countdown value+ Timer? _timer;++ void _startCountdown() {+ _timer = Timer.periodic(const Duration(seconds: 1), (timer) {+ if (_countdown > 1) {+ setState(() {+ _countdown--;+ });+ } else {+ timer.cancel();+ if (context.mounted) {+ context.pop(); // Automatically close the dialog+ }+ }+ });+ }++ @override+ void dispose() {+ if (_timer != null) {+ _timer!.cancel();+ }+ super.dispose();+ }++ @override+ void initState() {+ super.initState();+ // Start the countdown timer+ _startCountdown();+ }++ @override+ Widget build(BuildContext context) {+ return AlertDialog(+ title: Text(t.dialogs.openFile.title),+ content: Text(t.dialogs.openFile.content),+ actions: [+ TextButton(+ onPressed: () async => openFile(context, widget.fileType, widget.filePath),+ child: Text(t.general.open),+ ),+ TextButton(+ onPressed: () {+ _timer!.cancel();+ context.pop();+ },+ child: Text('${t.general.close}($_countdown)'),+ ),+ ],+ );+ }+}diff --git a/app/test/mocks.mocks.dart b/app/test/mocks.mocks.dartindex e4d08fe7..b793a771 100644--- a/app/test/mocks.mocks.dart+++ b/app/test/mocks.mocks.dart@@ -380,6 +380,26 @@ class MockPersistenceService extends _i1.Mock implements _i3.PersistenceServicereturnValueForMissingStub: _i4.Future<void>.value(),) as _i4.Future<void>);+ @override+ bool getAdvancedSettingsEnabled() => (super.noSuchMethod(+ Invocation.method(+ #getAdvancedSettingsEnabled,+ [],+ ),+ returnValue: false,+ returnValueForMissingStub: false,+ ) as bool);++ @override+ _i4.Future<void> setAdvancedSettingsEnabled(bool? isEnabled) => (super.noSuchMethod(+ Invocation.method(+ #setAdvancedSettingsEnabled,+ [isEnabled],+ ),+ returnValue: _i4.Future<void>.value(),+ returnValueForMissingStub: _i4.Future<void>.value(),+ ) as _i4.Future<void>);+@overridebool isQuickSave() => (super.noSuchMethod(Invocation.method(