diff --git a/lib/classes/receiver.dart b/lib/classes/receiver.dart index 9cabe2f..dbc7462 100644 --- a/lib/classes/receiver.dart +++ b/lib/classes/receiver.dart @@ -104,9 +104,9 @@ class Receiver { ///sends `400 Bad request` as response /// ///Returns the code generated for discovery. Other devices should select this code for - ///connecting to this device + ///connecting to this devices Future listen() async { - if (!saveToTemp) { + if (!saveToTemp && false) { final permissionStatus = await checkPermission(); if (!permissionStatus) { throw NoStoragePermissionException(); @@ -262,7 +262,7 @@ class Receiver { Map get map => { "useDb": useDb, "saveToTemp": saveToTemp, - "port": port, + if (port != null) "port": port, "code": _code, }; diff --git a/lib/classes/workers/worker_interface.dart b/lib/classes/workers/worker_interface.dart index 656d6e6..5b50ad8 100644 --- a/lib/classes/workers/worker_interface.dart +++ b/lib/classes/workers/worker_interface.dart @@ -72,6 +72,7 @@ class IsolatedSender extends Sender { AnimationController? uploadAnimC, bool useDb = true, void Function(double percent)? onUploadProgress}) async { + await initalize(); if (progressNotification) { progressNotification = await notifications.initalise(); } @@ -89,7 +90,7 @@ class IsolatedSender extends Sender { break; case final messages.FiledropError e: if (progressNotification) { - await cancelSend(); + await cancel(); } throw e.exception; default: @@ -107,8 +108,8 @@ class IsolatedSender extends Sender { } } - static Future cancelSend() => - _workManager.cancelByUniqueName(MyTasks.send.name); + @override + Future cancel() => _workManager.cancelByUniqueName(MyTasks.send.name); } Future initalize() async { @@ -139,10 +140,11 @@ class IsolatedReceiver extends Receiver { ///If called twice, it has no effect. @override Future listen() async { + await initalize(); if (progressNotification) { progressNotification = await notifications.initalise(); } - if (!saveToTemp) { + if (!saveToTemp && false) { final permissionStatus = await super.checkPermission(); if (!permissionStatus) { throw NoStoragePermissionException(); @@ -156,6 +158,12 @@ class IsolatedReceiver extends Receiver { return super.code; } + @override + Future stopListening() async { + await notifications.cancelDownload(); + await _workManager.cancelByUniqueName(MyTasks.receive.name); + } + Future _portCallback(message) async { switch (message as messages.ReceiverMessage) { case final messages.UpdatePercent e: @@ -190,10 +198,4 @@ class IsolatedReceiver extends Receiver { throw Error(); } } - - ///Stops [Receiver] worker. - static Future cancelReceive() async { - await notifications.cancelDownload(); - await _workManager.cancelByUniqueName(MyTasks.receive.name); - } } diff --git a/lib/screens/receive_page.dart b/lib/screens/receive_page.dart index 9528824..981e06d 100644 --- a/lib/screens/receive_page.dart +++ b/lib/screens/receive_page.dart @@ -31,11 +31,8 @@ class ReceivePageInner extends ConsumerStatefulWidget { } class _ReceivePageInnerState extends ConsumerState - with TickerProviderStateMixin { - late final _downloadAnimC = AnimationController(vsync: this) - ..addListener(() { - setState(() {}); - }); + with SingleTickerProviderStateMixin { + late AnimationController _downloadAnimC; late final _receiver = defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS ? IsolatedReceiver( @@ -75,6 +72,10 @@ class _ReceivePageInnerState extends ConsumerState @override void initState() { + _downloadAnimC = AnimationController(vsync: this) + ..addListener(() { + setState(() {}); + }); super.initState(); _receive(); }