don't let user continue if not connected to the internet, fixed #4

pull/2/head
axtlos 3 years ago
parent 597b106c34
commit a353275efe
No known key found for this signature in database
GPG Key ID: A468AFD71DD51D4A

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:io'; import 'dart:io';
Widget welcome(next) { Widget welcome(next, connected) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
@ -74,7 +74,7 @@ Widget welcome(next) {
elevation: 0, elevation: 0,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
onPressed: next, onPressed: connected ? next : null,
child: Container( child: Container(
width: 500, width: 500,
height: 500, height: 500,
@ -93,21 +93,31 @@ Widget welcome(next) {
), ),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [ children: [
SizedBox(height: 20), const SizedBox(height: 20),
Text("Start the installation", const Text("Start the installation",
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.white)), color: Colors.white)),
SizedBox(height: 5), const SizedBox(height: 5),
Image( const Image(
image: AssetImage( image: AssetImage(
'assets/jade_logo.png', 'assets/jade_logo.png',
), ),
height: 400, height: 400,
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
), ),
Visibility(
visible: !connected,
child: const Text(
"You are not connected to the internet!",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.red),
),
),
], ],
), ),
), ),

@ -37,6 +37,18 @@ Future<void> checkIsEfi(
} }
} }
Future<void> checkConnected(
setState,
) async {
final String scriptOutput =
await Process.run("/opt/jade_gui/scripts/checkNetwork.sh", [])
.then((ProcessResult result) {
return result.stdout;
});
bool connected = scriptOutput.contains("disconnected") ? false : true;
setState(connected);
}
Future<void> writeToLog(String message) async { Future<void> writeToLog(String message) async {
await File('${env["HOME"]}/jade_log.txt') await File('${env["HOME"]}/jade_log.txt')
.readAsString() .readAsString()
@ -85,6 +97,7 @@ class _JadeguiState extends State<Jadegui> {
bool isEfi = false; bool isEfi = false;
bool ipv6 = false; bool ipv6 = false;
bool enableTimeshift = true; bool enableTimeshift = true;
bool connected = false;
bool running = false; bool running = false;
bool runningInfo = false; bool runningInfo = false;
bool runningPart = false; bool runningPart = false;
@ -108,6 +121,13 @@ class _JadeguiState extends State<Jadegui> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
setWindowSize(); setWindowSize();
checkConnected(
(value) {
setState(() {
connected = value;
});
},
);
return Scaffold( return Scaffold(
backgroundColor: const Color.fromARGB(255, 23, 23, 23), backgroundColor: const Color.fromARGB(255, 23, 23, 23),
body: Row( body: Row(
@ -305,11 +325,14 @@ class _JadeguiState extends State<Jadegui> {
child: SizedBox( child: SizedBox(
width: logicWidth, width: logicWidth,
height: logicHeight, height: logicHeight,
child: welcome(() { child: welcome(
setState(() { () {
_selectedIndex = _selectedIndex + 1; setState(() {
}); _selectedIndex = _selectedIndex + 1;
}), });
},
connected,
),
), ),
), ),
); );

@ -0,0 +1,7 @@
#!/usr/bin/env bash
ping -c1 getcryst.al -q > /dev/null
if [[ $? -eq 0 ]]; then
echo "connected"
else
echo "disconnected"
fi
Loading…
Cancel
Save