Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan completed local notifications #188

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ android {
targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
Expand Down Expand Up @@ -83,6 +84,7 @@ android {

namespace "org.fsociety.vernet"
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
Expand All @@ -91,6 +93,12 @@ android {
}
}

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
implementation 'androidx.window:window:1.0.0'
implementation 'androidx.window:window-java:1.0.0'
}

flutter {
source '../..'
}
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- Add the block below to your manifest file to configure apps with action.VIEW intent filters as visible to your app -->
<queries>
<intent>
Expand Down
Binary file added android/app/src/main/res/drawable/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 27 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ PODS:
- Flutter
- flutter_isolate (0.0.1):
- Flutter
- flutter_local_notifications (0.0.1):
- Flutter
- flutter_native_splash (0.0.1):
- Flutter
- flutter_timezone (0.0.1):
- Flutter
- in_app_review (0.2.0):
- Flutter
- isar_flutter_libs (1.0.0):
- Flutter
- network_info_plus (0.0.1):
- Flutter
- nsd_ios (0.0.1):
Expand All @@ -30,7 +38,11 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_icmp_ping (from `.symlinks/plugins/flutter_icmp_ping/ios`)
- flutter_isolate (from `.symlinks/plugins/flutter_isolate/ios`)
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- flutter_timezone (from `.symlinks/plugins/flutter_timezone/ios`)
- in_app_review (from `.symlinks/plugins/in_app_review/ios`)
- isar_flutter_libs (from `.symlinks/plugins/isar_flutter_libs/ios`)
- network_info_plus (from `.symlinks/plugins/network_info_plus/ios`)
- nsd_ios (from `.symlinks/plugins/nsd_ios/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand All @@ -48,8 +60,16 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_icmp_ping/ios"
flutter_isolate:
:path: ".symlinks/plugins/flutter_isolate/ios"
flutter_local_notifications:
:path: ".symlinks/plugins/flutter_local_notifications/ios"
flutter_native_splash:
:path: ".symlinks/plugins/flutter_native_splash/ios"
flutter_timezone:
:path: ".symlinks/plugins/flutter_timezone/ios"
in_app_review:
:path: ".symlinks/plugins/in_app_review/ios"
isar_flutter_libs:
:path: ".symlinks/plugins/isar_flutter_libs/ios"
network_info_plus:
:path: ".symlinks/plugins/network_info_plus/ios"
nsd_ios:
Expand All @@ -70,14 +90,18 @@ SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_icmp_ping: 2b159955eee0c487c766ad83fec224ae35e7c935
flutter_isolate: 0edf5081826d071adf21759d1eb10ff5c24503b5
flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086
flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778
flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb
in_app_review: 318597b3a06c22bb46dc454d56828c85f444f99d
isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073
network_info_plus: 6d0c3eb8367b8164fa3fb0c19875e3f59d49697f
nsd_ios: 8c37babdc6538e3350dbed3a52674d2edde98173
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011

Expand Down
5 changes: 4 additions & 1 deletion ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
Expand Down
52 changes: 33 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:network_info_plus/network_info_plus.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
Expand All @@ -9,10 +8,11 @@ import 'package:vernet/helper/app_settings.dart';
import 'package:vernet/helper/consent_loader.dart';
import 'package:vernet/injection.dart';
import 'package:vernet/pages/home_page.dart';
import 'package:vernet/pages/host_scan_page/host_scan_page.dart';
import 'package:vernet/pages/location_consent_page.dart';
import 'package:vernet/pages/settings_page.dart';
import 'package:vernet/providers/dark_theme_provider.dart';
import 'package:vernet/services/impls/device_scanner_service.dart';
import 'package:vernet/repository/notification_service.dart';

AppSettings appSettings = AppSettings.instance;
Future<void> main() async {
Expand All @@ -27,12 +27,17 @@ Future<void> main() async {
final bool allowed = await ConsentLoader.isConsentPageShown();
await appSettings.load();

await NotificationService.initNotification();

runApp(MyApp(allowed));
FlutterNativeSplash.remove();
}

class MyApp extends StatefulWidget {
const MyApp(this.allowed, {super.key});
static final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
// static const Color mainColor = Colors.deepPurple;

final bool allowed;

Expand All @@ -46,21 +51,8 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
NotificationService.grantPermissions();
getCurrentAppTheme();
startScanOnStartup();
}

Future<void> startScanOnStartup() async {
if (appSettings.runScanOnStartup) {
final ip = await NetworkInfo().getWifiIP();
final gatewayIp = appSettings.customSubnet.isNotEmpty
? appSettings.customSubnet
: await NetworkInfo().getWifiGatewayIP();
final subnet = gatewayIp!.substring(0, gatewayIp.lastIndexOf('.'));
getIt<DeviceScannerService>()
.startNewScan(subnet, ip!, gatewayIp)
.listen((device) {});
}
}

Future<void> getCurrentAppTheme() async {
Expand All @@ -77,18 +69,40 @@ class _MyAppState extends State<MyApp> {
child: Consumer<DarkThemeProvider>(
builder: (BuildContext context, value, Widget? child) {
return MaterialApp(
navigatorKey: MyApp.navigatorKey,
initialRoute: '/',
onGenerateRoute: (settings) {
switch (settings.name) {
case '/':
return MaterialPageRoute(
builder: (context) => homePage,
);

case '/hostscan':
return MaterialPageRoute(
builder: (context) {
return HostScanPage();
},
);

default:
assert(false, 'Page ${settings.name} not found');
return null;
}
},
title: 'Vernet',
theme: themeChangeProvider.darkTheme
? ThemeData.dark()
: ThemeData.light(),
home: widget.allowed
? const TabBarPage()
: const LocationConsentPage(),
home: homePage,
);
},
),
);
}

Widget get homePage =>
widget.allowed ? const TabBarPage() : const LocationConsentPage();
}

class TabBarPage extends StatefulWidget {
Expand Down
13 changes: 12 additions & 1 deletion lib/models/wifi_info.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
class WifiInfo {
WifiInfo(this._ip, this._bssid, this._name, this.unknown);
WifiInfo(
this._ip,
this._bssid,
this._name,
this.unknown,
this.gatewayIp,
this.isLocationOn,
);

static Set<String> defaultBSSID = {'00:00:00:00:00:00'};
final String? _bssid;
final String? _ip;
final String? _name;
bool unknown;
String get ip => _ip ?? 'x.x.x.x';
int totalDevices = 0;
final String gatewayIp;
final bool isLocationOn;
String get subnet => gatewayIp.substring(0, gatewayIp.lastIndexOf('.'));

static const String noWifiName = 'Wi-Fi';

Expand Down
Loading
Loading