Skip to content

Commit f2fe24b

Browse files
committed
Send in byte count instead of generic progress
1 parent 37e5cd7 commit f2fe24b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

lib/backend/fs.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ class TransferFileOperation extends BaseFileSystemOperation<bool> {
190190
final bool allowOverwrite;
191191

192192
late final NativeCallable<Void Function(Bool)> _completeCallable;
193-
late final NativeCallable<Void Function(Float)> _progressCallable;
194-
final ValueNotifier<double> _progress = ValueNotifier(0);
193+
late final NativeCallable<Void Function(Long, Long)> _progressCallable;
194+
final ValueNotifier<(int, int)> _progress = ValueNotifier((0, 0));
195195

196-
ValueListenable<double> get progress => _progress;
196+
ValueListenable<(int currentBytes, int totalBytes)> get progress => _progress;
197197

198198
@override
199199
void _start() {
@@ -223,7 +223,7 @@ class TransferFileOperation extends BaseFileSystemOperation<bool> {
223223
@override
224224
void _create() {
225225
super._create();
226-
_progressCallable = NativeCallable<Void Function(Float)>.listener(
226+
_progressCallable = NativeCallable<Void Function(Long, Long)>.listener(
227227
_onProgress,
228228
);
229229
_completeCallable = NativeCallable<Void Function(Bool)>.listener(
@@ -238,8 +238,8 @@ class TransferFileOperation extends BaseFileSystemOperation<bool> {
238238
super._destroy();
239239
}
240240

241-
void _onProgress(double progress) {
242-
_progress.value = progress;
241+
void _onProgress(int current, int total) {
242+
_progress.value = (current, total);
243243
}
244244
}
245245

lib/backend/fs_native.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ external void file_query_info(
170170
Pointer<GFile>,
171171
Uint32,
172172
Pointer<GCancellable>,
173-
Pointer<NativeFunction<Void Function(Float)>>,
173+
Pointer<NativeFunction<Void Function(Long, Long)>>,
174174
Pointer<NativeFunction<Void Function(Bool)>>,
175175
Pointer<Pointer<GError>>,
176176
)
@@ -180,7 +180,7 @@ external void file_copy(
180180
Pointer<GFile> dst,
181181
int flags,
182182
Pointer<GCancellable> cancellable,
183-
Pointer<NativeFunction<Void Function(Float)>> progressCallback,
183+
Pointer<NativeFunction<Void Function(Long, Long)>> progressCallback,
184184
Pointer<NativeFunction<Void Function(Bool)>> resultCallback,
185185
Pointer<Pointer<GError>> error,
186186
);
@@ -191,7 +191,7 @@ external void file_copy(
191191
Pointer<GFile>,
192192
Uint32,
193193
Pointer<GCancellable>,
194-
Pointer<NativeFunction<Void Function(Float)>>,
194+
Pointer<NativeFunction<Void Function(Long, Long)>>,
195195
Pointer<NativeFunction<Void Function(Bool)>>,
196196
Pointer<Pointer<GError>>,
197197
)
@@ -201,7 +201,7 @@ external bool file_move(
201201
Pointer<GFile> dst,
202202
int flags,
203203
Pointer<GCancellable> cancellable,
204-
Pointer<NativeFunction<Void Function(Float)>> progressCallback,
204+
Pointer<NativeFunction<Void Function(Long, Long)>> progressCallback,
205205
Pointer<NativeFunction<Void Function(Bool)>> resultCallback,
206206
Pointer<Pointer<GError>> error,
207207
);

src/src/lib.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn AsyncResultCallback(comptime T: type) type {
1818

1919
pub const LoopControl = extern struct { quit: bool = false };
2020

21-
const file_progress_callback = *fn (f32) void;
21+
const file_progress_callback = *fn (c_long, c_long) void;
2222

2323
// -------- ASYNC -------- //
2424
fn ioThread(user_data: ?*anyopaque) callconv(.c) ?*anyopaque {
@@ -195,7 +195,7 @@ fn fileProgress(current: c_long, total: c_long, user_data: ?*anyopaque) callconv
195195
if (user_data == null) return;
196196

197197
const callback: file_progress_callback = @ptrCast(user_data);
198-
callback(@as(f32, @floatFromInt(current)) / @as(f32, @floatFromInt(total)));
198+
callback(current, total);
199199
}
200200

201201
fn fileCopyFinish(obj: [*c]c.GObject, result: ?*c.GAsyncResult, user_data: ?*anyopaque) callconv(.c) void {

0 commit comments

Comments
 (0)