Skip to content

Commit

Permalink
Fix for slowness of device scan
Browse files Browse the repository at this point in the history
  • Loading branch information
git-elliot committed Nov 16, 2024
1 parent 4ab7fa3 commit 36e7487
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void main() {
await tester.tap(devicesButton);
await tester.pump();
expect(find.byType(AdaptiveListTile), findsAny);
await tester.pumpAndSettle(const Duration(seconds: 4));
await tester.pumpAndSettle();
await tester.pump();
expect(find.byType(AdaptiveListTile), findsAtLeast(2));

Expand Down
15 changes: 7 additions & 8 deletions lib/pages/host_scan_page/host_scan_bloc/host_scan_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:network_tools_flutter/network_tools_flutter.dart';
import 'package:vernet/helper/utils_helper.dart';
import 'package:vernet/injection.dart';
import 'package:vernet/main.dart';
import 'package:vernet/models/device_in_the_network.dart';
import 'package:vernet/models/isar/device.dart';
import 'package:vernet/models/isar/scan.dart';
import 'package:vernet/repository/notification_service.dart';
Expand Down Expand Up @@ -38,7 +37,7 @@ class HostScanBloc extends Bloc<HostScanEvent, HostScanState> {
String? subnet;

/// List of all ActiveHost devices that got found in the current scan
final List<DeviceInTheNetwork> deviceInTheNetworkList = [];
final Set<Device> devicesSet = {};

/// mDNS for each ip
final Map<String, MdnsInfo> mDnsDevices = {};
Expand All @@ -47,7 +46,7 @@ class HostScanBloc extends Bloc<HostScanEvent, HostScanState> {
Initialized event,
Emitter<HostScanState> emit,
) async {
deviceInTheNetworkList.clear();
devicesSet.clear();
mDnsDevices.clear();
emit(const HostScanState.loadInProgress());
await initializeWifiParameters(emit);
Expand Down Expand Up @@ -82,16 +81,16 @@ class HostScanBloc extends Bloc<HostScanEvent, HostScanState> {
) async {
emit(const HostScanState.loadInProgress());

final Set<Device> devices = {};
final deviceStream =
getIt<DeviceScannerService>().startNewScan(subnet!, ip!, gatewayIp!);
await for (final Device device in deviceStream) {
devices.add(device);
emit(HostScanState.foundNewDevice(devices));
devicesSet.add(device);
emit(const HostScanState.loadInProgress());
emit(HostScanState.foundNewDevice(devicesSet));
}

await NotificationService.showNotificationWithActions();
emit(HostScanState.loadSuccess(devices));
emit(HostScanState.loadSuccess(devicesSet));
}

Future<void> _loadScanAndShowResults(
Expand All @@ -100,10 +99,10 @@ class HostScanBloc extends Bloc<HostScanEvent, HostScanState> {
) async {
emit(const HostScanState.loadInProgress());

final Set<Device> devicesSet = {};
final deviceStream = await getIt<DeviceScannerService>().getOnGoingScan();
deviceStream.listen((devices) {
devicesSet.addAll(devices);
emit(const HostScanState.loadInProgress());
emit(HostScanState.foundNewDevice(devicesSet));
});

Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,10 @@ packages:
dependency: "direct main"
description:
name: shared_preferences
sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051"
sha256: "95f9997ca1fb9799d494d0cb2a780fd7be075818d59f00c43832ed112b158a82"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.3"
shared_preferences_android:
dependency: transitive
description:
Expand Down Expand Up @@ -1224,10 +1224,10 @@ packages:
dependency: transitive
description:
name: url_launcher_linux
sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.2.1"
url_launcher_macos:
dependency: transitive
description:
Expand Down

0 comments on commit 36e7487

Please sign in to comment.