From a353275efec679949e59b2a0b084364d492e054f Mon Sep 17 00:00:00 2001 From: axtlos Date: Fri, 22 Apr 2022 14:15:04 +0200 Subject: [PATCH] don't let user continue if not connected to the internet, fixed #4 --- lib/functions/welcome.dart | 24 +++++++++++++++++------- lib/main.dart | 33 ++++++++++++++++++++++++++++----- scripts/checkNetwork.sh | 7 +++++++ 3 files changed, 52 insertions(+), 12 deletions(-) create mode 100755 scripts/checkNetwork.sh diff --git a/lib/functions/welcome.dart b/lib/functions/welcome.dart index 81e933b..68b585f 100644 --- a/lib/functions/welcome.dart +++ b/lib/functions/welcome.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'dart:io'; -Widget welcome(next) { +Widget welcome(next, connected) { return Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -74,7 +74,7 @@ Widget welcome(next) { elevation: 0, padding: EdgeInsets.zero, ), - onPressed: next, + onPressed: connected ? next : null, child: Container( width: 500, height: 500, @@ -93,21 +93,31 @@ Widget welcome(next) { ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, - children: const [ - SizedBox(height: 20), - Text("Start the installation", + children: [ + const SizedBox(height: 20), + const Text("Start the installation", style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white)), - SizedBox(height: 5), - Image( + const SizedBox(height: 5), + const Image( image: AssetImage( 'assets/jade_logo.png', ), height: 400, 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), + ), + ), ], ), ), diff --git a/lib/main.dart b/lib/main.dart index 5ccf1c3..dd95308 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -37,6 +37,18 @@ Future checkIsEfi( } } +Future 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 writeToLog(String message) async { await File('${env["HOME"]}/jade_log.txt') .readAsString() @@ -85,6 +97,7 @@ class _JadeguiState extends State { bool isEfi = false; bool ipv6 = false; bool enableTimeshift = true; + bool connected = false; bool running = false; bool runningInfo = false; bool runningPart = false; @@ -108,6 +121,13 @@ class _JadeguiState extends State { @override Widget build(BuildContext context) { setWindowSize(); + checkConnected( + (value) { + setState(() { + connected = value; + }); + }, + ); return Scaffold( backgroundColor: const Color.fromARGB(255, 23, 23, 23), body: Row( @@ -305,11 +325,14 @@ class _JadeguiState extends State { child: SizedBox( width: logicWidth, height: logicHeight, - child: welcome(() { - setState(() { - _selectedIndex = _selectedIndex + 1; - }); - }), + child: welcome( + () { + setState(() { + _selectedIndex = _selectedIndex + 1; + }); + }, + connected, + ), ), ), ); diff --git a/scripts/checkNetwork.sh b/scripts/checkNetwork.sh new file mode 100755 index 0000000..85da728 --- /dev/null +++ b/scripts/checkNetwork.sh @@ -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