Skip to content

Commit

Permalink
Merge pull request #199 from osociety/bug-fix-scan
Browse files Browse the repository at this point in the history
Fix for scan for devices broken issue
  • Loading branch information
git-elliot authored Nov 3, 2024
2 parents f7ba5e0 + 0b2aee0 commit ec722aa
Show file tree
Hide file tree
Showing 4 changed files with 1,351 additions and 6 deletions.
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/27.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fix for scan for devices not working
23 changes: 18 additions & 5 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 @@ -50,18 +50,31 @@ class HostScanBloc extends Bloc<HostScanEvent, HostScanState> {
deviceInTheNetworkList.clear();
mDnsDevices.clear();
emit(const HostScanState.loadInProgress());
ip = await NetworkInfo().getWifiIP();
gatewayIp = appSettings.customSubnet.isNotEmpty
? appSettings.customSubnet
: await NetworkInfo().getWifiGatewayIP();
subnet = gatewayIp!.substring(0, gatewayIp!.lastIndexOf('.'));
await initializeWifiParameters(emit);
if (appSettings.runScanOnStartup) {
add(const HostScanEvent.loadScan());
} else {
add(const HostScanEvent.startNewScan());
}
}

Future<void> initializeWifiParameters(Emitter<HostScanState> emit) async {
final wifiGatewayIP = await NetworkInfo().getWifiGatewayIP();
if (appSettings.customSubnet.isNotEmpty) {
gatewayIp = appSettings.customSubnet;
} else if (wifiGatewayIP != null) {
gatewayIp = wifiGatewayIP;
} else {
// NetworkInfo().getWifiGatewayIP() is null on android 35, so fail-safe
// to NetworkInfo().getWifiIP()
gatewayIp = ip = await NetworkInfo().getWifiIP();
}
if (gatewayIp == null) {
emit(const HostScanState.error());
}
subnet = gatewayIp!.substring(0, gatewayIp!.lastIndexOf('.'));
}

Future<void> _startNewScanBuiltInIsolate(
StartNewScan event,
Emitter<HostScanState> emit,
Expand Down
Loading

0 comments on commit ec722aa

Please sign in to comment.