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

Dev #732

Merged
merged 2 commits into from
Feb 11, 2024
Merged

Dev #732

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
2 changes: 1 addition & 1 deletion lib/domain/manage_network/i_manage_network_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract interface class IManageNetworkRepository {

static ManageNetworkEntity? manageWiFiEntity;

Future loadWifi();
Future<bool> loadWifi();

Future<Either<HomeUserFailures, String?>> doesWiFiEnabled();

Expand Down
15 changes: 8 additions & 7 deletions lib/infrastructure/manage_wifi_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ class _ManageWiFiRepository implements IManageNetworkRepository {
}

@override
Future loadWifi() async {
Future<bool> loadWifi() async {
final NetworkInfo info = NetworkInfo();

if (Platform.isLinux) {
final String? bssid = await info.getWifiBSSID();
final String? wifiName = await info.getWifiName();
final String? ip = await info.getWifiIP();
if (bssid == null || wifiName == null || ip == null) {
return;
return false;
}
final String subnet = ipToSubnet(ip);

Expand All @@ -150,7 +150,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository {
);
NetworksManager().addNetwork(network);
NetworksManager().setCurrentNetwork(network.uniqueId);
return;
return true;
}

final PermissionStatus locationStatus = await Permission.location.status;
Expand All @@ -166,7 +166,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository {

if (!isWifiEnabled || !isWifiConnected) {
logger.w('Not connected to WiFi');
exit(0);
return false;
}

String bssid;
Expand All @@ -176,12 +176,12 @@ class _ManageWiFiRepository implements IManageNetworkRepository {
logger.w(
'Location is not on or user-allowed approximate location instead of precise location',
);
exit(0);
return false;
}
bssid = bssidTemp;
} else {
logger.w('Missing location permission');
exit(0);
return false;
}
final String? ssid = await WiFiForIoTPlugin.getSSID();
final String? ip = await WiFiForIoTPlugin.getIP();
Expand All @@ -190,7 +190,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository {

if (ssid == null || ip == null) {
logger.w('Ssid is null');
exit(0);
return false;
}

final String subNet = ipToSubnet(ip);
Expand All @@ -206,6 +206,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository {
);
NetworksManager().addNetwork(network);
NetworksManager().setCurrentNetwork(network.uniqueId);
return true;
}

String ipToSubnet(String ip) {
Expand Down
1 change: 0 additions & 1 deletion lib/presentation/core/theme_data.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';

// TODO: Add at least 4 more colors
///List of all the GradientColors to iterate on
final Set<List<Color>> gradientColorsList = {
GradientColors.sky,
Expand Down
47 changes: 47 additions & 0 deletions lib/presentation/molecules/permissions_dialog_molecule.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:io';

import 'package:cybearjinni/presentation/atoms/button_atom.dart';
import 'package:cybearjinni/presentation/atoms/separator_atom.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';

void permsissionsDialog(BuildContext context) => showDialog(
context: context,
barrierDismissible: false,
builder: (_) => const PermsissionsDialogMolecule(),
);

class PermsissionsDialogMolecule extends StatelessWidget {
const PermsissionsDialogMolecule({super.key});

@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
final TextTheme textTheme = themeData.textTheme;

return AlertDialog(
content: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'1. Make sure you are connected to home WiFi\n'
'2. Please make sure location is on and permission grented.',
style: textTheme.labelLarge,
textAlign: TextAlign.center,
).tr(),
const SeparatorAtom(),
ButtonWidgetAtom(
variant: ButtonVariant.primary,
onPressed: () async {
exit(0);
},
text: 'exit',
),
],
),
),
);
}
}
9 changes: 8 additions & 1 deletion lib/presentation/pages/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:cybearjinni/infrastructure/core/logger.dart';
import 'package:cybearjinni/infrastructure/mqtt.dart';
import 'package:cybearjinni/presentation/atoms/atoms.dart';
import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart';
import 'package:cybearjinni/presentation/molecules/permissions_dialog_molecule.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
Expand All @@ -32,7 +33,13 @@ class _SplashPageState extends State<SplashPage> {
await Hive.initFlutter();
await IDbRepository.instance.asyncConstactor();
NetworksManager().loadFromDb();
await IManageNetworkRepository.instance.loadWifi();
final bool sucess = await IManageNetworkRepository.instance.loadWifi();
if (!sucess) {
if (mounted) {
permsissionsDialog(context);
}
return;
}
final String? bssid = NetworksManager().currentNetwork?.bssid;
if (bssid == null) {
logger.e('Please set up network');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: cybearjinni
description: CyBear Jinni app to interact with your CyBear Jinni Smart Devices
version: 1.4.10+74
version: 1.4.11+75
homepage: https://cybearjinni.com

publish_to: 'none'
Expand Down
Loading