From a381c1cf390a1509a2c5568f58af0eb9febb5f7a Mon Sep 17 00:00:00 2001 From: axtlos Date: Wed, 20 Apr 2022 14:34:17 +0200 Subject: [PATCH] add logging (locale is excluded because it doesn't work properly and will have to be redone) --- jade_log.txt | 24 ++++ lib/desktops/desktops.dart | 2 +- lib/functions/install.dart | 9 +- lib/functions/keyboard.dart | 18 +-- lib/functions/keymap/layout.dart | 25 ---- lib/functions/keymap/variant.dart | 43 ------- lib/functions/locale.dart | 2 +- lib/functions/partition.dart | 67 +++++++---- lib/functions/summary.dart | 56 +++++---- lib/main.dart | 185 +++++++++++++++++++++--------- 10 files changed, 247 insertions(+), 184 deletions(-) create mode 100644 jade_log.txt delete mode 100644 lib/functions/keymap/layout.dart delete mode 100644 lib/functions/keymap/variant.dart diff --git a/jade_log.txt b/jade_log.txt new file mode 100644 index 0000000..0b9eb9f --- /dev/null +++ b/jade_log.txt @@ -0,0 +1,24 @@ + +Chosen layout: at +Chosen variant: normal +Username: s +Enable sudo: true +Desktop: KDE Plasma +Hostname: n +Disks: /dev/sda +/dev/nvme0n1 + +Selected disk: /dev/nvme0n1 +Partition info: 476.9G + +Is efi: true +Json config: {"partition":{"device":"nvme0n1","mode":"auto","efi":true},"bootloader":{"type":"grub-efi","location":"/boot/efi"},"locale":{"locale":["en_US.UTF-8 UTF-8"],"keymap":"Af","timezone":"America"},"networking":{"hostname":"n","ipv6":false},"users":[{"name":"s","password":"$1$KRz8vYrK$mTO2iNwmZnkHTpevyAcHN0\n","hasroot":true}],"rootpass":"","desktop":"KDE Plasma","timeshift":true,"extra_packages":["firefox"]} +[LOG] doing thing + +[ERROR] failed doing thing + +[LOG] + +[ERROR] + +Installation finished! You may reboot now! diff --git a/lib/desktops/desktops.dart b/lib/desktops/desktops.dart index e239442..92fcb35 100644 --- a/lib/desktops/desktops.dart +++ b/lib/desktops/desktops.dart @@ -24,7 +24,7 @@ List desktops = const [ //imageurl: '', ), Desktop( - name: "KDE Plasma", + name: "Kde", displayManager: "sddm", packages: [ "plasma", diff --git a/lib/functions/install.dart b/lib/functions/install.dart index d7181f3..deeefb9 100644 --- a/lib/functions/install.dart +++ b/lib/functions/install.dart @@ -5,12 +5,14 @@ import 'package:jade_gui/classes/location.dart'; import 'dart:convert'; import 'dart:io'; -test(setOutput, running, setRunning, config) async { +test(setOutput, running, setRunning, config, writeToLog) async { if (!running) { const filename = "/tmp/jade.json"; await File(filename).writeAsString(config); + writeToLog("Json config: $config"); var process = - await Process.start('pkexec', ['jade', 'config', '/tmp/jade.json']); + //await Process.start('pkexec', ['jade', 'config', '/tmp/jade.json']); + await Process.start('/opt/jade_gui/scripts/jadeemu.sh', []); process.stdout.transform(utf8.decoder).forEach(setOutput); setRunning(true); } @@ -35,6 +37,7 @@ Widget install( output, running, setRunning, + writeToLog, ) { InstallPrefs prefs = InstallPrefs( locale: locale, @@ -55,7 +58,7 @@ Widget install( ); String jsonPrefs = jsonEncode(prefs.toJson()); //writeConfig(jsonPrefs); - test(setOutput, running, setRunning, jsonPrefs); + test(setOutput, running, setRunning, jsonPrefs, writeToLog); return Column( children: [ Text( diff --git a/lib/functions/keyboard.dart b/lib/functions/keyboard.dart index 3f96904..d8faa71 100644 --- a/lib/functions/keyboard.dart +++ b/lib/functions/keyboard.dart @@ -13,7 +13,7 @@ String getChosenLayout() { return chosenLayout.backLayout; } -Widget variantTemplate(variant, chosenLayout, nextPage) { +Widget variantTemplate(variant, chosenLayout, nextPage, writeToLog) { return Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.stretch, @@ -28,6 +28,7 @@ Widget variantTemplate(variant, chosenLayout, nextPage) { child: ElevatedButton( onPressed: () { chosenVariant = variant; + writeToLog("Chosen variant: $chosenVariant"); nextPage(); }, style: TextButton.styleFrom( @@ -49,7 +50,7 @@ Widget variantTemplate(variant, chosenLayout, nextPage) { ); } -Widget layoutTemplate(keymap, setChosenLayout) { +Widget layoutTemplate(keymap, setChosenLayout, writeToLog) { return Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.stretch, @@ -64,6 +65,7 @@ Widget layoutTemplate(keymap, setChosenLayout) { child: ElevatedButton( onPressed: () { setChosenLayout(keymap); + writeToLog("Chosen layout: ${keymap.backLayout}"); }, style: TextButton.styleFrom( primary: Colors.white, @@ -84,8 +86,8 @@ Widget layoutTemplate(keymap, setChosenLayout) { ); } -Widget keyboard( - nextPage, showVariant, choseLayout, setChosenLayout, chosenLayout) { +Widget keyboard(nextPage, showVariant, choseLayout, setChosenLayout, + chosenLayout, writeToLog) { return Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -121,8 +123,8 @@ Widget keyboard( primary: false, child: Column( children: keymaps - .map( - (keymap) => layoutTemplate(keymap, setChosenLayout)) + .map((keymap) => + layoutTemplate(keymap, setChosenLayout, writeToLog)) .toList(), ), ), @@ -148,8 +150,8 @@ Widget keyboard( primary: false, child: Column( children: chosenLayout.variant - .map((map) => - variantTemplate(map, chosenLayout, nextPage)) + .map((map) => variantTemplate( + map, chosenLayout, nextPage, writeToLog)) .toList(), ), ), diff --git a/lib/functions/keymap/layout.dart b/lib/functions/keymap/layout.dart deleted file mode 100644 index 4123bca..0000000 --- a/lib/functions/keymap/layout.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flutter/material.dart'; - -Widget layout(keymap, chosenLayout, showVariant) { - return Container( - color: const Color.fromARGB(100, 169, 0, 255), - padding: const EdgeInsets.all(8), - child: ElevatedButton( - onPressed: () { - chosenLayout = keymap; - showVariant(); - }, - style: TextButton.styleFrom( - primary: Colors.white, - backgroundColor: const Color.fromARGB(100, 169, 0, 255), - padding: const EdgeInsets.all(10), - ), - child: Text( - keymap.layout, - style: const TextStyle( - fontWeight: FontWeight.bold, - ), - ), - ), - ); -} diff --git a/lib/functions/keymap/variant.dart b/lib/functions/keymap/variant.dart deleted file mode 100644 index ab3ba49..0000000 --- a/lib/functions/keymap/variant.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'package:flutter/material.dart'; - -String chosenVariant = "none"; - -String getChosenVariant() { - return chosenVariant; -} - -Widget variantButton(variant, nextPage) { - return Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - ElevatedButton( - onPressed: () { - chosenVariant = variant; - nextPage(); - }, - child: Text(variant), - style: TextButton.styleFrom( - primary: Colors.white, - backgroundColor: const Color.fromARGB(100, 169, 0, 255), - ), - ), - const SizedBox(height: 10), - ], - ); -} - -Widget variant(keymap, nextPage) { - return Container( - padding: const EdgeInsets.all(8), - color: const Color.fromARGB(100, 169, 0, 255), - child: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: keymap.variant - .map((variant) => variantButton(variant, nextPage)) - .toList()), - ), - ); -} diff --git a/lib/functions/locale.dart b/lib/functions/locale.dart index 4dc7824..ee3ae75 100644 --- a/lib/functions/locale.dart +++ b/lib/functions/locale.dart @@ -3,7 +3,7 @@ import 'package:jade_gui/functions/location/region.dart'; import 'package:jade_gui/functions/location/location.dart'; import 'package:jade_gui/locales/locales.dart'; -Widget locale(next, nextPage, selectlocation, isnextpage) { +Widget locale(next, nextPage, selectlocation, isnextpage, writeToLog) { Widget widget; selectlocation(getSelectedRegion()); String selectedregion = getSelectedRegion(); diff --git a/lib/functions/partition.dart b/lib/functions/partition.dart index dcbbe75..c36a977 100644 --- a/lib/functions/partition.dart +++ b/lib/functions/partition.dart @@ -2,25 +2,33 @@ import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; -Future getPartitionInfo(currPartition, setState) async { - final String partitionInfo = await Process.run( - "/opt/jade_gui/scripts/getPartitionInfo.sh", ['$currPartition']) - .then((ProcessResult results) { - return results.stdout; - }); - setState(partitionInfo); +Future getPartitionInfo( + currPartition, setState, runningInfo, setRunningInfo) async { + if (!runningInfo) { + final String partitionInfo = await Process.run( + "/opt/jade_gui/scripts/getPartitionInfo.sh", ['$currPartition']) + .then((ProcessResult results) { + return results.stdout; + }); + setState(partitionInfo); + setRunningInfo(); + } } -Future getPartitions(setState) async { - final String partitions = - await Process.run("/opt/jade_gui/scripts/getPartitions.sh", []) - .then((ProcessResult result) { - return result.stdout; - }); - setState(partitions); +Future getPartitions(setState, runningPart, setRunningPart) async { + if (!runningPart) { + final String partitions = + await Process.run("/opt/jade_gui/scripts/getPartitions.sh", []) + .then((ProcessResult result) { + return result.stdout; + }); + setState(partitions); + setRunningPart(); + } } -Widget partitionTemplate(partition, setPartition, setPartitionInfo) { +Widget partitionTemplate( + partition, setPartition, setPartitionInfo, runningInfo, setRunningInfo) { if (partition != "") { return Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -36,7 +44,8 @@ Widget partitionTemplate(partition, setPartition, setPartitionInfo) { child: ElevatedButton( onPressed: () { setPartition(partition); - getPartitionInfo(partition, setPartitionInfo); + getPartitionInfo( + partition, setPartitionInfo, runningInfo, setRunningInfo); }, style: TextButton.styleFrom( primary: Colors.white, @@ -60,10 +69,20 @@ Widget partitionTemplate(partition, setPartition, setPartitionInfo) { } } -Widget partitioning(partitions, setState, setPartition, next, setPartitionInfo, - selectedPartition, partitionInfo) { +Widget partitioning( + partitions, + setState, + setPartition, + next, + setPartitionInfo, + selectedPartition, + partitionInfo, + runningPart, + setRunningPart, + runningInfo, + setRunningInfo) { return FutureBuilder( - future: getPartitions(setState), + future: getPartitions(setState, runningPart, setRunningPart), builder: (BuildContext context, AsyncSnapshot snapshot) { return Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -101,8 +120,14 @@ Widget partitioning(partitions, setState, setPartition, next, setPartitionInfo, child: Column( children: partitions .split('\n') - .map((partition) => partitionTemplate( - partition, setPartition, setPartitionInfo)) + .map( + (partition) => partitionTemplate( + partition, + setPartition, + setPartitionInfo, + runningInfo, + setRunningInfo), + ) .toList(), ), ), diff --git a/lib/functions/summary.dart b/lib/functions/summary.dart index 86c1b10..a214263 100644 --- a/lib/functions/summary.dart +++ b/lib/functions/summary.dart @@ -14,13 +14,16 @@ Widget infoTextTemplate(infoSection, infoText) { ); } -Future getDiskType(setState, disk) async { - final String partitions = - await Process.run("/opt/jade_gui/scripts/getDiskType.sh", [disk]) - .then((ProcessResult result) { - return result.stdout; - }); - setState(partitions); +Future getDiskType(setState, disk, running, setRunning) async { + if (!running) { + final String partitions = + await Process.run("/opt/jade_gui/scripts/getDiskType.sh", [disk]) + .then((ProcessResult result) { + return result.stdout; + }); + setState(partitions); + setRunning(); + } } String diskType(String disk, String diskType) { @@ -40,24 +43,27 @@ String diskType(String disk, String diskType) { } Widget summary( - Location locale, - String keymap, - String layout, - String username, - bool enableSudo, - bool enableRoot, - Desktop desktop, - String disk, - bool isEfi, - String bootloader, - String hostname, - bool ipv6, - bool enableTimeshift, - String rotational, - String diskSize, - setDiskType, - nextPage) { - getDiskType(setDiskType, disk); + Location locale, + String keymap, + String layout, + String username, + bool enableSudo, + bool enableRoot, + Desktop desktop, + String disk, + bool isEfi, + String bootloader, + String hostname, + bool ipv6, + bool enableTimeshift, + String rotational, + String diskSize, + setDiskType, + nextPage, + running, + setRunning, +) { + getDiskType(setDiskType, disk, running, setRunning); return Column( children: [ const Text( diff --git a/lib/main.dart b/lib/main.dart index 9f58084..45eacd6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,19 +15,31 @@ 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\n" ? true : false; - debugPrint(isEfi.toString()); - debugPrint(scriptOutput); - setState(isEfi); +Future checkIsEfi( + setState, + runningEfi, + setRunningEfi, +) async { + if (!runningEfi) { + final String scriptOutput = + await Process.run("/opt/jade_gui/scripts/checkEfi.sh", []) + .then((ProcessResult result) { + return result.stdout; + }); + bool isEfi = scriptOutput == "UEFI\n" ? true : false; + debugPrint(isEfi.toString()); + debugPrint(scriptOutput); + + setState(isEfi); + setRunningEfi(); + } } -void writeToLog() {} +Future writeToLog(String message) async { + await File('/var/log/jade_log.txt').readAsString().then((String contents) { + File("/var/log/jade_log.txt").writeAsString(contents + "\n" + message); + }); +} void main() => runApp( const MaterialApp( @@ -54,6 +66,7 @@ class Jadegui extends StatefulWidget { } class _JadeguiState extends State { + var file = File("jade_log.txt").writeAsString(""); int _selectedIndex = 0; bool nextpage = false; bool choseLayout = false; @@ -63,6 +76,10 @@ class _JadeguiState extends State { bool ipv6 = false; bool enableTimeshift = true; bool running = false; + bool runningInfo = false; + bool runningPart = false; + bool runningSum = false; + bool runningEfi = false; String clearPass = ""; String password = ""; String confirmPassword = ""; @@ -276,25 +293,35 @@ class _JadeguiState extends State { }); break; case 1: - widget = locale(() { - setState(() { - _selectedIndex = _selectedIndex + 1; - }); - }, () { - setState(() { - nextpage = true; - }); - }, (region) { - if (region != "") { + widget = locale( + () { setState(() { - nextpage = false; + _selectedIndex = _selectedIndex + 1; }); - } else { + }, + () { setState(() { nextpage = true; }); - } - }, nextpage); + }, + (region) { + if (region != "") { + setState(() { + nextpage = false; + }); + } else { + setState(() { + nextpage = true; + }); + } + }, + nextpage, + (value) { + writeToLog(value); + }, + ); + //writeToLog("locale: $region"); + break; case 2: widget = keyboard( @@ -315,6 +342,9 @@ class _JadeguiState extends State { }); }, chosenLayout, + (value) { + writeToLog(value); + }, ); break; case 3: @@ -322,6 +352,7 @@ class _JadeguiState extends State { (value) { setState(() { enableSudo = value; + writeToLog("Enable sudo: $enableSudo"); }); }, enableSudo, @@ -347,12 +378,14 @@ class _JadeguiState extends State { (value) { setState(() { username = value; + writeToLog("Username: $username"); }); }, username, (value) { setState(() { enableRoot = value; + writeToLog("Enable root: $enableRoot"); }); }, enableRoot, @@ -376,6 +409,7 @@ class _JadeguiState extends State { }); }, ); + break; case 4: debugPrint(password); @@ -384,6 +418,7 @@ class _JadeguiState extends State { (selectedDesktop) { setState(() { currDesktop = selectedDesktop; + writeToLog("Desktop: ${selectedDesktop.name}"); }); }, () { @@ -398,16 +433,19 @@ class _JadeguiState extends State { (value) { setState(() { ipv6 = value; + writeToLog("IPv6: $ipv6"); }); }, (value) { setState(() { hostname = value; + writeToLog("Hostname: $hostname"); }); }, (value) { setState(() { enableTimeshift = value; + writeToLog("Enable timeshift: $enableTimeshift"); }); }, ipv6, @@ -426,11 +464,13 @@ class _JadeguiState extends State { (value) { setState(() { disks = value; + writeToLog("Disks: $disks"); }); }, (value) { setState(() { selectedDisk = value; + writeToLog("Selected disk: $selectedDisk"); }); }, () { @@ -441,18 +481,39 @@ class _JadeguiState extends State { (value) { setState(() { partitionInfo = value; + writeToLog("Partition info: $partitionInfo"); }); }, selectedDisk, partitionInfo, + runningPart, + () { + setState(() { + runningPart = true; + }); + }, + runningInfo, + () { + setState(() { + runningInfo = true; + }); + }, ); break; case 7: - checkIsEfi((value) { - setState(() { - isEfi = value; - }); - }); + checkIsEfi( + (value) { + setState(() { + isEfi = value; + }); + writeToLog("Is efi: $isEfi"); + }, + runningEfi, + () { + setState(() { + runningEfi = true; + }); + }); widget = summary( getSelectedLocPack(), getChosenLayout(), @@ -472,6 +533,7 @@ class _JadeguiState extends State { (value) { setState(() { _diskType = value; + //writeToLog("diskType: $_diskType"); }); }, () { @@ -479,36 +541,47 @@ class _JadeguiState extends State { _selectedIndex = _selectedIndex + 1; }); }, + runningSum, + () { + setState(() { + runningSum = true; + }); + }, ); break; case 8: widget = install( - getSelectedLocPack(), - getChosenLayout(), - getChosenVariant(), - username, - password, - enableSudo, - rootPass, - currDesktop, - selectedDisk, - isEfi, - isEfi ? "grub-efi" : "grub-legacy", - hostname, - ipv6, - enableTimeshift, - (value) { - setState(() { - output = output + "\n" + value; - }); - }, - output, - running, - (value) { - setState(() { - running = value; - }); + getSelectedLocPack(), + getChosenLayout(), + getChosenVariant(), + username, + password, + enableSudo, + rootPass, + currDesktop, + selectedDisk, + isEfi, + isEfi ? "grub-efi" : "grub-legacy", + hostname, + ipv6, + enableTimeshift, + (value) { + setState(() { + if (value.compareTo(output) == 1) { + writeToLog(value.replaceAll(output, "")); + } + output = output + "\n" + value; + }); + }, + output, + running, + (value) { + setState(() { + running = value; }); + }, + writeToLog, + ); break; default: widget = const Text( @@ -524,6 +597,4 @@ class _JadeguiState extends State { // Finally returning a Widget return widget; } - - void selectlocation(region) {} }