Skip to content

Commit

Permalink
Enable multithreading on sending side (localsend#1983)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto authored Oct 31, 2024
1 parent 8633e14 commit fa8170d
Show file tree
Hide file tree
Showing 21 changed files with 597 additions and 133 deletions.
9 changes: 8 additions & 1 deletion app/lib/config/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:common/util/dio.dart';
import 'package:common/util/logger.dart';
import 'package:dart_mappable/dart_mappable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:localsend_app/config/refena.dart';
Expand All @@ -23,8 +24,10 @@ import 'package:localsend_app/provider/device_info_provider.dart';
import 'package:localsend_app/provider/network/nearby_devices_provider.dart';
import 'package:localsend_app/provider/network/server/server_provider.dart';
import 'package:localsend_app/provider/persistence_provider.dart';

// [FOSS_REMOVE_START]
import 'package:localsend_app/provider/purchase_provider.dart';

// [FOSS_REMOVE_END]
import 'package:localsend_app/provider/selection/selected_sending_files_provider.dart';
import 'package:localsend_app/provider/settings_provider.dart';
Expand All @@ -33,6 +36,7 @@ import 'package:localsend_app/provider/window_dimensions_provider.dart';
import 'package:localsend_app/util/i18n.dart';
import 'package:localsend_app/util/native/autostart_helper.dart';
import 'package:localsend_app/util/native/cache_helper.dart';
import 'package:localsend_app/util/native/content_uri_helper.dart';
import 'package:localsend_app/util/native/context_menu_helper.dart';
import 'package:localsend_app/util/native/cross_file_converters.dart';
import 'package:localsend_app/util/native/device_info_helper.dart';
Expand Down Expand Up @@ -141,6 +145,7 @@ Future<RefenaContainer> preInit(List<String> args) async {
return IsolateController(
initialState: ParentIsolateState.initial(
SyncState(
rootIsolateToken: RootIsolateToken.instance!,
securityContext: persistenceService.getSecurityContext(),
deviceInfo: ref.read(deviceInfoProvider),
alias: settings.alias,
Expand All @@ -155,7 +160,9 @@ Future<RefenaContainer> preInit(List<String> args) async {
);
}));

await container.redux(parentIsolateProvider).dispatchAsync(IsolateSetupAction());
await container.redux(parentIsolateProvider).dispatchAsync(IsolateSetupAction(
uriContentStreamResolver: AndroidUriContentStreamResolver(),
));

return container;
}
Expand Down
17 changes: 13 additions & 4 deletions app/lib/model/state/send/send_session_state.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:common/model/device.dart';
import 'package:common/model/session_status.dart';
import 'package:dart_mappable/dart_mappable.dart';
import 'package:dio/dio.dart';
import 'package:localsend_app/model/state/send/sending_file.dart';

part 'send_session_state.mapper.dart';
Expand All @@ -16,7 +15,7 @@ class SendSessionState with SendSessionStateMappable {
final Map<String, SendingFile> files; // file id as key
final int? startTime;
final int? endTime;
final CancelToken? cancelToken;
final List<SendingTask>? sendingTasks; // used to cancel tasks
final String? errorMessage;

const SendSessionState({
Expand All @@ -28,7 +27,7 @@ class SendSessionState with SendSessionStateMappable {
required this.files,
required this.startTime,
required this.endTime,
required this.cancelToken,
required this.sendingTasks,
required this.errorMessage,
});

Expand All @@ -37,6 +36,16 @@ class SendSessionState with SendSessionStateMappable {
/// SendingFile.
@override
String toString() {
return 'SendSessionState(sessionId: $sessionId, remoteSessionId: $remoteSessionId, background: $background, status: $status, target: $target, files: $files, startTime: $startTime, endTime: $endTime, cancelToken: $cancelToken, errorMessage: $errorMessage)';
return 'SendSessionState(sessionId: $sessionId, remoteSessionId: $remoteSessionId, background: $background, status: $status, target: $target, files: $files, startTime: $startTime, endTime: $endTime, sendingTasks: $sendingTasks, errorMessage: $errorMessage)';
}
}

class SendingTask {
final int isolateIndex;
final int taskId;

SendingTask({
required this.isolateIndex,
required this.taskId,
});
}
21 changes: 13 additions & 8 deletions app/lib/model/state/send/send_session_state.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class SendSessionStateMapper extends ClassMapperBase<SendSessionState> {
static const Field<SendSessionState, int> _f$startTime = Field('startTime', _$startTime);
static int? _$endTime(SendSessionState v) => v.endTime;
static const Field<SendSessionState, int> _f$endTime = Field('endTime', _$endTime);
static CancelToken? _$cancelToken(SendSessionState v) => v.cancelToken;
static const Field<SendSessionState, CancelToken> _f$cancelToken = Field('cancelToken', _$cancelToken);
static List<SendingTask>? _$sendingTasks(SendSessionState v) => v.sendingTasks;
static const Field<SendSessionState, List<SendingTask>> _f$sendingTasks = Field('sendingTasks', _$sendingTasks);
static String? _$errorMessage(SendSessionState v) => v.errorMessage;
static const Field<SendSessionState, String> _f$errorMessage = Field('errorMessage', _$errorMessage);

Expand All @@ -53,7 +53,7 @@ class SendSessionStateMapper extends ClassMapperBase<SendSessionState> {
#files: _f$files,
#startTime: _f$startTime,
#endTime: _f$endTime,
#cancelToken: _f$cancelToken,
#sendingTasks: _f$sendingTasks,
#errorMessage: _f$errorMessage,
};

Expand All @@ -67,7 +67,7 @@ class SendSessionStateMapper extends ClassMapperBase<SendSessionState> {
files: data.dec(_f$files),
startTime: data.dec(_f$startTime),
endTime: data.dec(_f$endTime),
cancelToken: data.dec(_f$cancelToken),
sendingTasks: data.dec(_f$sendingTasks),
errorMessage: data.dec(_f$errorMessage));
}

Expand Down Expand Up @@ -117,6 +117,7 @@ extension SendSessionStateValueCopy<$R, $Out> on ObjectCopyWith<$R, SendSessionS
abstract class SendSessionStateCopyWith<$R, $In extends SendSessionState, $Out> implements ClassCopyWith<$R, $In, $Out> {
DeviceCopyWith<$R, Device, Device> get target;
MapCopyWith<$R, String, SendingFile, SendingFileCopyWith<$R, SendingFile, SendingFile>> get files;
ListCopyWith<$R, SendingTask, ObjectCopyWith<$R, SendingTask, SendingTask>>? get sendingTasks;
$R call(
{String? sessionId,
String? remoteSessionId,
Expand All @@ -126,7 +127,7 @@ abstract class SendSessionStateCopyWith<$R, $In extends SendSessionState, $Out>
Map<String, SendingFile>? files,
int? startTime,
int? endTime,
CancelToken? cancelToken,
List<SendingTask>? sendingTasks,
String? errorMessage});
SendSessionStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}
Expand All @@ -143,6 +144,10 @@ class _SendSessionStateCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Send
MapCopyWith<$R, String, SendingFile, SendingFileCopyWith<$R, SendingFile, SendingFile>> get files =>
MapCopyWith($value.files, (v, t) => v.copyWith.$chain(t), (v) => call(files: v));
@override
ListCopyWith<$R, SendingTask, ObjectCopyWith<$R, SendingTask, SendingTask>>? get sendingTasks => $value.sendingTasks != null
? ListCopyWith($value.sendingTasks!, (v, t) => ObjectCopyWith(v, $identity, t), (v) => call(sendingTasks: v))
: null;
@override
$R call(
{String? sessionId,
Object? remoteSessionId = $none,
Expand All @@ -152,7 +157,7 @@ class _SendSessionStateCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Send
Map<String, SendingFile>? files,
Object? startTime = $none,
Object? endTime = $none,
Object? cancelToken = $none,
Object? sendingTasks = $none,
Object? errorMessage = $none}) =>
$apply(FieldCopyWithData({
if (sessionId != null) #sessionId: sessionId,
Expand All @@ -163,7 +168,7 @@ class _SendSessionStateCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Send
if (files != null) #files: files,
if (startTime != $none) #startTime: startTime,
if (endTime != $none) #endTime: endTime,
if (cancelToken != $none) #cancelToken: cancelToken,
if (sendingTasks != $none) #sendingTasks: sendingTasks,
if (errorMessage != $none) #errorMessage: errorMessage
}));
@override
Expand All @@ -176,7 +181,7 @@ class _SendSessionStateCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Send
files: data.get(#files, or: $value.files),
startTime: data.get(#startTime, or: $value.startTime),
endTime: data.get(#endTime, or: $value.endTime),
cancelToken: data.get(#cancelToken, or: $value.cancelToken),
sendingTasks: data.get(#sendingTasks, or: $value.sendingTasks),
errorMessage: data.get(#errorMessage, or: $value.errorMessage));

@override
Expand Down
1 change: 1 addition & 0 deletions app/lib/pages/progress_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
onPressed: () async {
await ref.notifier(sendProvider).sendFile(
sessionId: widget.sessionId,
isolateIndex: 0,
file: sendSession.files[file.id]!,
isRetry: true,
);
Expand Down
Loading

0 comments on commit fa8170d

Please sign in to comment.