Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Support working on background #7
Browse files Browse the repository at this point in the history
correct overrides for isolates
  • Loading branch information
iamalper committed Dec 2, 2023
1 parent c2929ab commit 75c7486
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/classes/receiver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> listen() async {
if (!saveToTemp) {
if (!saveToTemp && false) {
final permissionStatus = await checkPermission();
if (!permissionStatus) {
throw NoStoragePermissionException();
Expand Down Expand Up @@ -262,7 +262,7 @@ class Receiver {
Map<String, dynamic> get map => {
"useDb": useDb,
"saveToTemp": saveToTemp,
"port": port,
if (port != null) "port": port,
"code": _code,
};

Expand Down
22 changes: 12 additions & 10 deletions lib/classes/workers/worker_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -89,7 +90,7 @@ class IsolatedSender extends Sender {
break;
case final messages.FiledropError e:
if (progressNotification) {
await cancelSend();
await cancel();
}
throw e.exception;
default:
Expand All @@ -107,8 +108,8 @@ class IsolatedSender extends Sender {
}
}

static Future<void> cancelSend() =>
_workManager.cancelByUniqueName(MyTasks.send.name);
@override
Future<void> cancel() => _workManager.cancelByUniqueName(MyTasks.send.name);
}

Future<void> initalize() async {
Expand Down Expand Up @@ -139,10 +140,11 @@ class IsolatedReceiver extends Receiver {
///If called twice, it has no effect.
@override
Future<int> listen() async {
await initalize();
if (progressNotification) {
progressNotification = await notifications.initalise();
}
if (!saveToTemp) {
if (!saveToTemp && false) {
final permissionStatus = await super.checkPermission();
if (!permissionStatus) {
throw NoStoragePermissionException();
Expand All @@ -156,6 +158,12 @@ class IsolatedReceiver extends Receiver {
return super.code;
}

@override
Future<void> stopListening() async {
await notifications.cancelDownload();
await _workManager.cancelByUniqueName(MyTasks.receive.name);
}

Future<void> _portCallback(message) async {
switch (message as messages.ReceiverMessage) {
case final messages.UpdatePercent e:
Expand Down Expand Up @@ -190,10 +198,4 @@ class IsolatedReceiver extends Receiver {
throw Error();
}
}

///Stops [Receiver] worker.
static Future<void> cancelReceive() async {
await notifications.cancelDownload();
await _workManager.cancelByUniqueName(MyTasks.receive.name);
}
}
11 changes: 6 additions & 5 deletions lib/screens/receive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ class ReceivePageInner extends ConsumerStatefulWidget {
}

class _ReceivePageInnerState extends ConsumerState<ReceivePageInner>
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(
Expand Down Expand Up @@ -75,6 +72,10 @@ class _ReceivePageInnerState extends ConsumerState<ReceivePageInner>

@override
void initState() {
_downloadAnimC = AnimationController(vsync: this)
..addListener(() {
setState(() {});
});
super.initState();
_receive();
}
Expand Down

0 comments on commit 75c7486

Please sign in to comment.