From 35fa6a7e17b1fa4bc9800435a880ea89ca954aa6 Mon Sep 17 00:00:00 2001 From: axtlos Date: Wed, 30 Mar 2022 18:01:05 +0200 Subject: [PATCH] added function to check if user is using uefi or legacy --- lib/classes/desktop.dart | 10 ++--- lib/classes/installPrefs.dart | 28 ++++++++++++ lib/classes/location.dart | 10 ++--- lib/functions/install.dart | 35 +++++++++++++++ lib/functions/partition.dart | 5 ++- lib/functions/summary.dart | 3 ++ lib/main.dart | 83 ++++++++++++++++++++++++----------- scripts/checkEfi.sh | 2 + 8 files changed, 139 insertions(+), 37 deletions(-) create mode 100644 lib/classes/installPrefs.dart create mode 100644 lib/functions/install.dart create mode 100755 scripts/checkEfi.sh diff --git a/lib/classes/desktop.dart b/lib/classes/desktop.dart index 573ca30..50ba5d9 100644 --- a/lib/classes/desktop.dart +++ b/lib/classes/desktop.dart @@ -1,10 +1,10 @@ class Desktop { - String name = ""; - String displayManager = ""; - List packages = []; - String imageurl = ""; + final String name; + final String displayManager; + final List packages; + final String imageurl; - Desktop({ + const Desktop({ this.name = "", this.displayManager = "", this.packages = const [""], diff --git a/lib/classes/installPrefs.dart b/lib/classes/installPrefs.dart new file mode 100644 index 0000000..d1f0e23 --- /dev/null +++ b/lib/classes/installPrefs.dart @@ -0,0 +1,28 @@ +import 'package:jade_gui/classes/desktop.dart'; +import 'package:jade_gui/classes/location.dart'; + +class installPrefs { + final Location locale; + final String keymap; + final String layout; + final String username; + final bool enableSudo; + final bool enableRoot; + final Desktop desktop; + final String disk; + + installPrefs({ + this.locale = const Location(), + this.keymap = "", + this.layout = "", + this.username = "", + this.enableSudo = false, + this.enableRoot = false, + this.desktop = const Desktop(), + this.disk = "", + }); + + /* Map toJson() => { + + }*/ +} diff --git a/lib/classes/location.dart b/lib/classes/location.dart index 61cf511..da8c93c 100644 --- a/lib/classes/location.dart +++ b/lib/classes/location.dart @@ -1,10 +1,10 @@ class Location { - String region = ""; - String location = ""; - String locale = ""; - String image = ""; + final String region; + final String location; + final String locale; + final String image; - Location({ + const Location({ this.region = "", this.location = "", this.locale = "", diff --git a/lib/functions/install.dart b/lib/functions/install.dart new file mode 100644 index 0000000..fbe73e6 --- /dev/null +++ b/lib/functions/install.dart @@ -0,0 +1,35 @@ +import 'package:flutter/material.dart'; +import 'package:jade_gui/classes/installPrefs.dart'; +import 'package:jade_gui/classes/desktop.dart'; +import 'package:jade_gui/classes/location.dart'; + +Widget install( + String keymap, + String layout, + bool enableSudo, + bool enableRoot, + String username, + String disk, + Desktop currDesktop, + Location locale, +) { + installPrefs prefs = installPrefs( + locale: locale, + keymap: keymap, + layout: layout, + username: username, + enableSudo: enableSudo, + enableRoot: enableRoot, + desktop: currDesktop); + return Column( + children: [ + const Text( + 'Installing...', + style: TextStyle( + fontSize: 50, + fontWeight: FontWeight.bold, + color: Color.fromARGB(255, 169, 0, 255)), + ), + ], + ); +} diff --git a/lib/functions/partition.dart b/lib/functions/partition.dart index 474393d..dcbbe75 100644 --- a/lib/functions/partition.dart +++ b/lib/functions/partition.dart @@ -56,7 +56,7 @@ Widget partitionTemplate(partition, setPartition, setPartitionInfo) { ], ); } else { - return SizedBox(height: 0); + return const SizedBox(height: 0); } } @@ -155,7 +155,8 @@ Widget partitioning(partitions, setState, setPartition, next, setPartitionInfo, ), ), const SizedBox(height: 5), - Image(image: AssetImage('assets/jade_logo.png')), + const Image( + image: AssetImage('assets/jade_logo.png')), ], ), ), diff --git a/lib/functions/summary.dart b/lib/functions/summary.dart index c1a4cb7..f271167 100644 --- a/lib/functions/summary.dart +++ b/lib/functions/summary.dart @@ -50,6 +50,7 @@ Widget summary( nextPage, setDiskType, String rotational, + bool isEfi, ) { getDiskType(setDiskType, disk); return Column( @@ -242,6 +243,8 @@ Widget summary( infoTextTemplate("Disk Size", diskSize), const SizedBox(height: 10), infoTextTemplate("Disk Type", diskType(disk, rotational)), + const SizedBox(height: 10), + infoTextTemplate("Boot Type", isEfi ? "UEFI" : "Legacy") ], ), ), diff --git a/lib/main.dart b/lib/main.dart index 439b37c..2769301 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,10 +7,25 @@ import 'package:jade_gui/functions/users.dart'; import 'package:jade_gui/functions/desktop.dart'; import 'package:jade_gui/functions/partition.dart'; import 'package:jade_gui/functions/summary.dart'; +import 'package:jade_gui/functions/install.dart'; import 'package:jade_gui/classes/keymap.dart'; import 'package:jade_gui/classes/desktop.dart'; import 'package:jade_gui/desktops/desktops.dart'; +import 'dart:io'; + +Future checkIsEfi(setState) async { + final String scriptOutput = + await Process.run("/opt/jade_gui/scripts/checkEfi.sh", []) + .then((ProcessResult result) { + return result.stdout; + }); + bool isEfi = scriptOutput == "UEFI" ? false : true; + debugPrint(isEfi.toString()); + debugPrint(scriptOutput); + setState(isEfi); +} + void main() => runApp( const MaterialApp( debugShowCheckedModeBanner: false, @@ -29,9 +44,9 @@ class _JadeguiState extends State { int _selectedIndex = 0; bool nextpage = false; bool choseLayout = false; - Keymap chosenLayout = Keymap(); bool enableSudo = false; bool enableRoot = false; + bool isEfi = false; String password = ""; String confirmPassword = ""; String username = ""; @@ -43,6 +58,8 @@ class _JadeguiState extends State { String _diskType = ""; Desktop currDesktop = desktops[0]; + Keymap chosenLayout = Keymap(); + @override Widget build(BuildContext context) { return Scaffold( @@ -337,25 +354,38 @@ class _JadeguiState extends State { ); break; case 5: - widget = partitioning(disks, (value) { - setState(() { - disks = value; - }); - }, (value) { - setState(() { - selectedDisk = value; - }); - }, () { - setState(() { - _selectedIndex = _selectedIndex + 1; - }); - }, (value) { - setState(() { - partitionInfo = value; - }); - }, selectedDisk, partitionInfo); + widget = partitioning( + disks, + (value) { + setState(() { + disks = value; + }); + }, + (value) { + setState(() { + selectedDisk = value; + }); + }, + () { + setState(() { + _selectedIndex = _selectedIndex + 1; + }); + }, + (value) { + setState(() { + partitionInfo = value; + }); + }, + selectedDisk, + partitionInfo, + ); break; case 6: + checkIsEfi((value) { + setState(() { + isEfi = value; + }); + }); widget = summary( getChosenLayout(), getChosenVariant(), @@ -377,16 +407,19 @@ class _JadeguiState extends State { }); }, _diskType, + isEfi, ); break; case 7: - widget = const Text( - 'Showing Installing screen', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Color.fromARGB(255, 169, 0, 255), - ), + widget = install( + getChosenLayout(), + getChosenVariant(), + enableSudo, + enableRoot, + username, + selectedDisk, + currDesktop, + getSelectedLocPack(), ); break; default: diff --git a/scripts/checkEfi.sh b/scripts/checkEfi.sh new file mode 100755 index 0000000..55e5901 --- /dev/null +++ b/scripts/checkEfi.sh @@ -0,0 +1,2 @@ +#!/usr/bin/bash +[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS