Skip to content

Commit

Permalink
Merge pull request #206 from osociety/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
git-elliot authored Nov 16, 2024
2 parents bed4af4 + 73f720a commit e3ca586
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 173 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/flutter_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ jobs:
- name: Download pub dependencies
run: flutter pub get

- name: Upgrade pub dependencies
run: flutter pub upgrade

- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs

Expand Down Expand Up @@ -150,9 +147,6 @@ jobs:
- name: Download pub dependencies
run: flutter pub get

- name: Upgrade pub dependencies
run: flutter pub upgrade

- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs

Expand Down Expand Up @@ -204,9 +198,6 @@ jobs:
- name: Download pub dependencies
run: flutter pub get

- name: Upgrade pub dependencies
run: flutter pub upgrade

- name: Run build_runner
run: dart run build_runner build --delete-conflicting-outputs

Expand Down
27 changes: 17 additions & 10 deletions .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_call:

concurrency:
group: ${{ github.head_ref }}
group: ${{ github.head_ref || github.run_id}}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -51,10 +51,14 @@ jobs:
name: 'Flutter Analyze + Test'
needs: changes
if: ${{ needs.changes.outputs.lib == 'true' || needs.changes.outputs.test == 'true' || needs.changes.outputs.yaml == 'true' || needs.changes.outputs.android == 'true' || needs.changes.outputs.linux == 'true' || needs.changes.outputs.macos == 'true' || needs.changes.outputs.windows == 'true' }}
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Setup Java JDK
uses: actions/[email protected]
with:
Expand Down Expand Up @@ -85,14 +89,23 @@ jobs:
build-runner-
- name: Download pub dependencies
run: flutter pub get
- name: Upgrade pub dependencies
run: flutter pub upgrade
- name: Run build_runner
run: flutter pub run build_runner build
- name: Run analyzer
run: flutter analyze
- name: Install coverage tools
run: flutter pub global activate coverage
- name: Run tests
run: flutter test
- name: Run integration tests
if: ${{ steps.extract_branch.outputs.branch == 'dev' }}
run: flutter test integration_test --coverage -d macos
- name: Upload Coverage to CodeCov
if: ${{ steps.extract_branch.outputs.branch == 'dev' }}
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coverage/lcov.info

android-linux-build:
name: 'Build Android + Linux'
Expand Down Expand Up @@ -130,8 +143,6 @@ jobs:
build-runner-
- name: Download pub dependencies
run: flutter pub get
- name: Upgrade pub dependencies
run: flutter pub upgrade
- name: Run build_runner
run: flutter pub run build_runner build
- name: Build Android
Expand Down Expand Up @@ -186,8 +197,6 @@ jobs:
${{ runner.os }}-pods-
- name: Download pub dependencies
run: flutter pub get
- name: Upgrade pub dependencies
run: flutter pub upgrade
- name: Run build_runner
run: flutter pub run build_runner build
- name: Build macos
Expand Down Expand Up @@ -224,8 +233,6 @@ jobs:
build-runner-
- name: Download pub dependencies
run: flutter pub get
- name: Upgrade pub dependencies
run: flutter pub upgrade
- name: Run build_runner
run: flutter pub run build_runner build
- name: Build windows
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Vernet - Network Analyzer and Monitoring Tool
![GitHub repo size](https://img.shields.io/github/repo-size/git-elliot/vernet)
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/osociety/vernet/total)
![Liberapay receiving](https://img.shields.io/liberapay/receives/opensociety)
[![codecov](https://codecov.io/gh/osociety/vernet/graph/badge.svg?token=B25JBP4RCI)](https://codecov.io/gh/osociety/vernet)

## Features

Expand Down
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/29.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed slowness of devices scan.
2 changes: 2 additions & 0 deletions generate_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
genhtml coverage/lcov.info -o coverage/html
open coverage/html/index.html
88 changes: 88 additions & 0 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:vernet/injection.dart';
import 'package:vernet/main.dart';
import 'package:vernet/ui/adaptive/adaptive_list.dart';
import 'package:vernet/values/keys.dart';

void main() {
late ServerSocket server;
int port = 0;
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async {
configureDependencies(Env.test);
final appDocDirectory = await getApplicationDocumentsDirectory();
await configureNetworkToolsFlutter(appDocDirectory.path);
//open a port in shared way because of portscanner using same,
//if passed false then two hosts come up in search and breaks test.
server =
await ServerSocket.bind(InternetAddress.anyIPv4, port, shared: true);
port = server.port;
debugPrint("Opened port in this machine at $port");
});

group('host scanner end-to-end test', () {
testWidgets('just test if app is able to launch and display homepage',
(tester) async {
// Load app widget.
await tester.pumpWidget(const MyApp(true));
await tester.pumpAndSettle();

// Verify that there are 4 widgets at homepage
expect(find.bySubtype<AdaptiveListTile>(), findsAtLeastNWidgets(4));
});

testWidgets('tap on the scan for devices button, verify device found',
(tester) async {
// Load app widget.
await tester.pumpWidget(const MyApp(true));
await tester.pumpAndSettle();

// Verify that there are 4 widgets at homepage
expect(find.bySubtype<AdaptiveListTile>(), findsAtLeastNWidgets(4));

// Finds the scan for devices button to tap on.
final devicesButton = find.byKey(WidgetKey.scanForDevicesButton.key);

// Emulate a tap on the button.
await tester.tap(devicesButton);
await tester.pump();
expect(find.byType(AdaptiveListTile), findsAny);
await tester.pumpAndSettle();
await tester.pump();
expect(find.byType(AdaptiveListTile), findsAtLeast(2));

final routerIconButton =
find.byKey(WidgetKey.thisDeviceTileIconButton.key);

await tester.tap(routerIconButton);
await tester.pumpAndSettle();
expect(find.byType(AppBar), findsOne);

final radioButton = find.byKey(WidgetKey.singlePortScanRadioButton.key);
await tester.tap(radioButton);
await tester.pumpAndSettle();

await tester.enterText(
find.byKey(WidgetKey.enterPortTextField.key),
port.toString(),
);
await tester.pumpAndSettle();

final portScanButton = find.byKey(WidgetKey.portScanButton.key);
await tester.tap(portScanButton);
await tester.pumpAndSettle();
await tester.pump();
expect(find.byType(AdaptiveListTile), findsAny);
});
});

tearDownAll(() {
server.close();
});
}
4 changes: 4 additions & 0 deletions lib/helper/app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ class AppSettings {
_customSubnet;
debugPrint("Custom Subnet : $_customSubnet");
}

Future<bool> clearAll() async {
return (await SharedPreferences.getInstance()).clear();
}
}
5 changes: 4 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:vernet/repository/notification_service.dart';
import 'package:vernet/services/impls/device_scanner_service.dart';
import 'package:vernet/ui/adaptive/adaptive_list.dart';
import 'package:vernet/ui/custom_tile.dart';
import 'package:vernet/values/keys.dart';
import 'package:vernet/values/strings.dart';

class HomePage extends StatefulWidget {
Expand Down Expand Up @@ -168,6 +169,7 @@ class _WifiDetailState extends State<HomePage> {
width: 4,
),
ElevatedButton(
key: WidgetKey.scanForDevicesButton.key,
onPressed: () {
Navigator.push(
context,
Expand All @@ -192,7 +194,7 @@ class _WifiDetailState extends State<HomePage> {
} else if (snapshot.hasError) {
return const Text("Unable to fetch WiFi details");
} else {
return const CircularProgressIndicator.adaptive();
return const Text('Loading...');
}
},
),
Expand Down Expand Up @@ -221,6 +223,7 @@ class _WifiDetailState extends State<HomePage> {
),
const SizedBox(width: 10),
ElevatedButton.icon(
key: WidgetKey.scanForOpenPortsButton.key,
onPressed: () {
Navigator.push(
context,
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
20 changes: 10 additions & 10 deletions lib/pages/host_scan_page/widgets/host_scan_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'package:vernet/models/isar/device.dart';
import 'package:vernet/pages/host_scan_page/host_scan_bloc/host_scan_bloc.dart';
import 'package:vernet/pages/network_troubleshoot/port_scan_page.dart';
import 'package:vernet/ui/adaptive/adaptive_list.dart';
import 'package:vernet/values/keys.dart';
import 'package:vernet/values/strings.dart';
import 'package:vernet/values/tooltip_messages.dart';

//TODO: Device doesn't refresh when active scan going on
class HostScanWidget extends StatelessWidget {
Expand All @@ -29,7 +32,7 @@ class HostScanWidget extends StatelessWidget {
Text(
appSettings.gatewayIP.isNotEmpty
? 'Searching for devices in ${appSettings.gatewayIP} network'
: 'Searching for devices in your local network',
: StringValue.loadingDevicesMessage,
textAlign: TextAlign.center,
),
],
Expand Down Expand Up @@ -68,15 +71,9 @@ class HostScanWidget extends StatelessWidget {
textAlign: TextAlign.center,
),
trailing: loading
? const Padding(
padding: EdgeInsets.all(8.0),
child: SizedBox(
height: 25.0,
width: 25.0,
child: Center(child: CircularProgressIndicator.adaptive()),
),
)
? const SizedBox()
: IconButton(
key: WidgetKey.rescanIconButton.key,
onPressed: () {
context
.read<HostScanBloc>()
Expand All @@ -97,7 +94,10 @@ class HostScanWidget extends StatelessWidget {
'${host.internetAddress}, ${host.macAddress ?? ''}',
),
trailing: IconButton(
tooltip: 'Scan open ports for this target',
key: host.deviceMake == 'This device'
? WidgetKey.thisDeviceTileIconButton.key
: null,
tooltip: TooltipMessages.currentDevicePortScan,
icon: const Icon(Icons.radar),
onPressed: () {
Navigator.push(
Expand Down
Loading

0 comments on commit e3ca586

Please sign in to comment.