Skip to content

Commit 1a3c8a3

Browse files
authored
Merge pull request #36 from CCExtractor/sse-fix
Transfer rate fix
2 parents 21440e3 + 1f907e6 commit 1a3c8a3

File tree

7 files changed

+38
-39
lines changed

7 files changed

+38
-39
lines changed

ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>9.0</string>
2525
</dict>
2626
</plist>

ios/Podfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ PODS:
5252
- Flutter
5353
- SwiftyGif (5.4.0)
5454
- Toast (4.0.0)
55+
- url_launcher (0.0.1):
56+
- Flutter
5557
- video_player (0.0.1):
5658
- Flutter
5759
- wakelock (0.0.1):
@@ -66,6 +68,7 @@ DEPENDENCIES:
6668
- path_provider (from `.symlinks/plugins/path_provider/ios`)
6769
- permission_handler (from `.symlinks/plugins/permission_handler/ios`)
6870
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
71+
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
6972
- video_player (from `.symlinks/plugins/video_player/ios`)
7073
- wakelock (from `.symlinks/plugins/wakelock/ios`)
7174

@@ -94,6 +97,8 @@ EXTERNAL SOURCES:
9497
:path: ".symlinks/plugins/permission_handler/ios"
9598
shared_preferences:
9699
:path: ".symlinks/plugins/shared_preferences/ios"
100+
url_launcher:
101+
:path: ".symlinks/plugins/url_launcher/ios"
97102
video_player:
98103
:path: ".symlinks/plugins/video_player/ios"
99104
wakelock:
@@ -103,7 +108,7 @@ SPEC CHECKSUMS:
103108
DKImagePickerController: b5eb7f7a388e4643264105d648d01f727110fc3d
104109
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
105110
file_picker: 3e6c3790de664ccf9b882732d9db5eaf6b8d4eb1
106-
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
111+
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
107112
flutter_downloader: 058b9c41564a90500f67f3e432e3524613a7fd83
108113
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
109114
fluttertoast: 6122fa75143e992b1d3470f61000f591a798cc58
@@ -113,6 +118,7 @@ SPEC CHECKSUMS:
113118
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
114119
SwiftyGif: 5d4af95df24caf1c570dbbcb32a3b8a0763bc6d7
115120
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
121+
url_launcher: b6e016d912f04be9f5bf6e8e82dc599b7ba59649
116122
video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e
117123
wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f
118124

lib/Api/event_handler_api.dart

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,17 @@ import 'package:json_patch/json_patch.dart';
1010
import 'package:provider/provider.dart';
1111

1212
class EventHandlerApi {
13-
//Sets the transfer rate if the event returned is TRANSFER_SUMMARY_DIFF_CHANGE
13+
//Sets the transfer rate if the event returned is TRANSFER_SUMMARY_FULL_UPDATE
1414
static void setTransferRate({
1515
required SSEModel model,
1616
required BuildContext context,
1717
}) {
18-
List<dynamic> data = json.decode(model.data ?? '');
19-
if (data != []) {
20-
String upSpeed = '0';
21-
String downSpeed = '0';
22-
23-
List<RateModel> rateList = [];
24-
for (var i in data) {
25-
rateList.add(RateModel.fromJson(i));
26-
}
27-
for (RateModel model in rateList) {
28-
if (model.path == '/downRate') {
29-
downSpeed = filesize(model.value);
30-
} else if (model.path == '/upRate') {
31-
upSpeed = filesize(model.value);
32-
}
33-
}
34-
Provider.of<HomeProvider>(context, listen: false)
35-
.setSpeed(upSpeed, downSpeed);
36-
}
18+
dynamic data = json.decode(model.data ?? '');
19+
RateModel rateModel = RateModel.fromJson(data);
20+
String downSpeed = filesize(rateModel.downRate.toString());
21+
String upSpeed = filesize(rateModel.upRate.toString());
22+
Provider.of<HomeProvider>(context, listen: false)
23+
.setSpeed(upSpeed, downSpeed);
3724
}
3825

3926
//Getting full list of torrents

lib/Constants/event_names.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Events {
22
//Transfer rate
3-
static const String TRANSFER_SUMMARY_DIFF_CHANGE =
4-
'TRANSFER_SUMMARY_DIFF_CHANGE';
3+
static const String TRANSFER_SUMMARY_FULL_UPDATE =
4+
'TRANSFER_SUMMARY_FULL_UPDATE';
55

66
//Full list of torrents
77
static const String TORRENT_LIST_FULL_UPDATE = 'TORRENT_LIST_FULL_UPDATE';

lib/Model/download_rate_model.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
import 'package:flutter/material.dart';
2+
13
class RateModel {
2-
String op;
3-
String path;
4-
int value;
5-
RateModel({
6-
required this.value,
7-
required this.op,
8-
required this.path,
9-
});
4+
int downRate;
5+
int downTotal;
6+
int upRate;
7+
int upTotal;
8+
RateModel(
9+
{required this.downRate,
10+
required this.downTotal,
11+
required this.upRate,
12+
required this.upTotal});
1013
factory RateModel.fromJson(Map<String, dynamic> json) {
1114
return RateModel(
12-
op: json['op'],
13-
path: json['path'],
14-
value: json['value'],
15+
downTotal: json['downTotal'],
16+
downRate: json['downRate'],
17+
upTotal: json['upTotal'],
18+
upRate: json['upRate'],
1519
);
1620
}
1721
}

lib/Provider/sse_provider.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class SSEProvider extends ChangeNotifier {
2121
Provider.of<UserDetailProvider>(context).token)
2222
.listen((event) {
2323
if (event.id != '' && event.data != '' && event.event != '') {
24-
// print('Id: ' + event.id);
25-
// print('Event: ' + event.event);
26-
// print('Data: ' + event.data);
24+
// print('Id: ' + event.id!);
25+
// print('Event: ' + event.event!);
26+
// print('Data: ' + event.data!);
2727
sseModel = event;
2828
switch (event.event) {
29-
case Events.TRANSFER_SUMMARY_DIFF_CHANGE:
29+
case Events.TRANSFER_SUMMARY_FULL_UPDATE:
3030
EventHandlerApi.setTransferRate(model: event, context: context);
3131
break;
3232
case Events.TORRENT_LIST_FULL_UPDATE:

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import Foundation
77

88
import path_provider_macos
99
import shared_preferences_macos
10+
import url_launcher_macos
1011
import wakelock_macos
1112

1213
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
1314
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
1415
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
16+
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
1517
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
1618
}

0 commit comments

Comments
 (0)