Skip to content

Commit

Permalink
Merge pull request #185 from osociety/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
git-elliot authored Aug 29, 2024
2 parents 8d17b3d + c29bd86 commit e4a23c8
Show file tree
Hide file tree
Showing 41 changed files with 554 additions and 130 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/flutter_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: flutter pub upgrade

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

- name: Download Android keystore
id: android_keystore
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
run: flutter pub upgrade

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

- name: Build macos release
run: flutter build macos --release
Expand Down Expand Up @@ -208,7 +208,7 @@ jobs:
run: flutter pub upgrade

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

- name: Build windows release
run: flutter build windows --release
Expand Down
3 changes: 2 additions & 1 deletion android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ GeneratedPluginRegistrant.java
# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
report.xml
report.xml
/app/property**
6 changes: 4 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdk 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -38,7 +37,8 @@ android {
defaultConfig {
applicationId "org.fsociety.vernet"
minSdkVersion 24
targetSdkVersion 34
compileSdk 34
targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand All @@ -55,6 +55,7 @@ android {
release {
signingConfig signingConfigs.release
minifyEnabled true
crunchPngs false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -66,6 +67,7 @@ android {
dimension "deploy"
signingConfig signingConfigs.release
}

fdroid {
dimension "deploy"
signingConfig signingConfigs.release
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
// Fix for Gradle Error.
// Namespace not specified. Specify a namespace in the module's build file
Expand Down
15 changes: 15 additions & 0 deletions android/fastlane/metadata/android/en-US/changelogs/25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## What's Changed
* Added rate our app in readme by @git-elliot in https://github.com/osociety/vernet/pull/169
* Update issue templates by @git-elliot in https://github.com/osociety/vernet/pull/170
* Added adaptive widgets for ios and macos by @git-elliot in https://github.com/osociety/vernet/pull/171
* Run test before build and restore keys in GHA by @git-elliot in https://github.com/osociety/vernet/pull/172
* fastlane i18n ru by @yurtpage in https://github.com/osociety/vernet/pull/175
* Add link to blog for f-droid publishing guide. by @git-elliot in https://github.com/osociety/vernet/pull/178
* Update README.md by @git-elliot in https://github.com/osociety/vernet/pull/179
* Uploaded to play store 1.0.7 by @git-elliot in https://github.com/osociety/vernet/pull/181
* Dev -> Main by @git-elliot in https://github.com/osociety/vernet/pull/180

## New Contributors
* @yurtpage made their first contribution in https://github.com/osociety/vernet/pull/175

**Full Changelog**: https://github.com/osociety/vernet/compare/v1.0.6+24...v1.0.7+25
2 changes: 2 additions & 0 deletions android/fastlane/metadata/android/en-US/changelogs/26.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added option in settings to run scan at app startup/launch
Upgraded to latest Android SDK.
24 changes: 19 additions & 5 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
org.gradle.jvmargs=-Xmx1536M
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
#Tue Aug 20 07:29:49 IST 2024
android.enableJetifier=false
android.nonFinalResIds=false
android.nonTransitiveRClass=true
android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g
# org.gradle.configuration-cache=true
# org.gradle.configuration-cache.problems=warn
2 changes: 1 addition & 1 deletion lib/api/isp_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:vernet/models/internet_provider.dart';
import 'package:vernet/providers/internet_provider.dart';

class ISPLoader {
static Future<String> loadIP(String url) async {
Expand Down
15 changes: 15 additions & 0 deletions lib/helper/app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class AppSettings {
//TODO: move it to isar db
AppSettings._();

static const String _lastSubnetKey = 'AppSettings-LAST_SUBNET';
static const String _firstSubnetKey = 'AppSettings-FIRST_SUBNET';
static const String _socketTimeoutKey = 'AppSettings-SOCKET_TIMEOUT';
static const String _pingCountKey = 'AppSettings-PING_COUNT';
static const String _inAppInternetKey = 'AppSettings-IN-APP-INTERNET';
static const String _runScanOnStartupKey = 'AppSettings-RUN-SCAN-ON-STARTUP';
static const String _customSubnetKey = 'AppSettings-CUSTOM-SUBNET';
int _firstSubnet = 1;
int _lastSubnet = 254;
int _socketTimeout = 500;
int _pingCount = 5;
bool _inAppInternet = false;
bool _runScanOnStartup = false;
String _customSubnet = '';

static final AppSettings _instance = AppSettings._();
Expand All @@ -25,6 +28,7 @@ class AppSettings {
int get socketTimeout => _socketTimeout;
int get pingCount => _pingCount;
bool get inAppInternet => _inAppInternet;
bool get runScanOnStartup => _runScanOnStartup;
String get customSubnet => _customSubnet;
String get gatewayIP => _customSubnet.isNotEmpty
? _customSubnet.substring(0, _customSubnet.lastIndexOf('.'))
Expand Down Expand Up @@ -60,6 +64,12 @@ class AppSettings {
.setBool(_inAppInternetKey, _inAppInternet);
}

Future<bool> setRunScanOnStartup(bool runScanOnStartup) async {
_runScanOnStartup = runScanOnStartup;
return (await SharedPreferences.getInstance())
.setBool(_runScanOnStartupKey, _runScanOnStartup);
}

Future<bool> setCustomSubnet(String customSubnet) async {
_customSubnet = customSubnet;
return (await SharedPreferences.getInstance())
Expand Down Expand Up @@ -93,6 +103,11 @@ class AppSettings {
_inAppInternet;
debugPrint("In-App Internet : $_inAppInternet");

_runScanOnStartup =
(await SharedPreferences.getInstance()).getBool(_runScanOnStartupKey) ??
runScanOnStartup;
debugPrint("Run scan on startup : $_runScanOnStartup");

_customSubnet =
(await SharedPreferences.getInstance()).getString(_customSubnetKey) ??
_customSubnet;
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/dark_theme_preference.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:vernet/models/dark_theme_provider.dart';
import 'package:vernet/providers/dark_theme_provider.dart';

class DarkThemePreference {
static const themeStatus = 'THEMESTATUS_NEW';
Expand Down
9 changes: 9 additions & 0 deletions lib/helper/utils_helper.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:vernet/ui/external_link_dialog.dart';

Expand All @@ -14,3 +15,11 @@ Future<void> launchURLWithWarning(BuildContext context, String url) {
),
);
}

Future<void> storeCurrentScanId(int scanId) async {
(await SharedPreferences.getInstance()).setInt('CurrentScanIDKey', scanId);
}

Future<int?> getCurrentScanId() async {
return (await SharedPreferences.getInstance()).getInt('CurrentScanIDKey');
}
18 changes: 17 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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';
import 'package:vernet/api/update_checker.dart';
import 'package:vernet/helper/app_settings.dart';
import 'package:vernet/helper/consent_loader.dart';
import 'package:vernet/injection.dart';
import 'package:vernet/models/dark_theme_provider.dart';
import 'package:vernet/pages/home_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';

AppSettings appSettings = AppSettings.instance;
Future<void> main() async {
Expand Down Expand Up @@ -45,6 +47,20 @@ class _MyAppState extends State<MyApp> {
void initState() {
super.initState();
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DeviceInTheNetwork {
required this.internetAddress,
required Future<String?> makeVar,
required this.pingData,
required this.currentDeviceIp,
required this.gatewayIp,
MdnsInfo? mdnsVar,
String? mac,
this.iconData = Icons.devices,
Expand Down Expand Up @@ -71,6 +73,8 @@ class DeviceInTheNetwork {
internetAddress: internetAddress,
makeVar: deviceMake,
pingData: pingData,
currentDeviceIp: currentDeviceIp,
gatewayIp: gatewayIp,
hostId: hostId,
iconData: iconData,
mdnsVar: mdns,
Expand All @@ -80,6 +84,8 @@ class DeviceInTheNetwork {

/// Ip of the device
final InternetAddress internetAddress;
final String currentDeviceIp;
final String gatewayIp;
late Future<String?> make;
String? _mac;

Expand All @@ -96,14 +102,13 @@ class DeviceInTheNetwork {
set mdns(MdnsInfo? name) {
_mdns = name;

final Future<String?> deviceMake = getDeviceMake(
make = getDeviceMake(
currentDeviceIp: '',
hostIp: internetAddress.address,
gatewayIp: '',
hostMake: make,
mdns: _mdns,
);
make = deviceMake;
}

/// Some name to show the user
Expand Down
64 changes: 64 additions & 0 deletions lib/models/isar/device.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:isar/isar.dart';

part 'device.g.dart';

@collection
class Device {
Device({
required this.internetAddress,
required this.hostMake,
required this.currentDeviceIp,
required this.gatewayIp,
required this.scanId,
this.mdnsDomainName,
this.macAddress,
});
final Id id = Isar.autoIncrement;
@Index(type: IndexType.value)
final int scanId;
@Index(type: IndexType.value)
final String internetAddress;
final String currentDeviceIp;
final String gatewayIp;
final String? macAddress;
final String? hostMake;
final String? mdnsDomainName;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Device &&
runtimeType == other.runtimeType &&
internetAddress == other.internetAddress;

@override
int get hashCode => internetAddress.hashCode;

@ignore
String? get deviceMake {
if (currentDeviceIp == internetAddress) {
return 'This device';
} else if (gatewayIp == internetAddress) {
return 'Router/Gateway';
} else if (mdnsDomainName != null) {
return mdnsDomainName;
}
return hostMake;
}

@ignore
IconData get iconData {
if (internetAddress == currentDeviceIp) {
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
return Icons.computer;
}
return Icons.smartphone;
} else if (internetAddress == gatewayIp) {
return Icons.router;
}
return Icons.devices;
}
}
18 changes: 18 additions & 0 deletions lib/models/isar/scan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:isar/isar.dart';
part 'scan.g.dart';

@collection
class Scan {
Scan({
required this.gatewayIp,
this.startTime,
this.endTime,
this.onGoing,
});
Id id = Isar.autoIncrement;
@Index(type: IndexType.value)
final String gatewayIp;
bool? onGoing;
DateTime? startTime;
DateTime? endTime;
}
Loading

0 comments on commit e4a23c8

Please sign in to comment.