From 5590dfc8aad3c256031051904f987277565b0071 Mon Sep 17 00:00:00 2001 From: Lennard Date: Wed, 16 Jun 2021 16:21:22 +0200 Subject: [PATCH] OC 0.0.7 --- lib/main.dart | 22 +-- lib/pages/home/home_page.dart | 6 +- lib/pages/home/sidebar.dart | 148 ++++++++++++------ lib/pages/load_config_page.dart | 37 +++-- lib/pages/misc/misc_entries_widget.dart | 1 + lib/pages/misc/misc_tools_widget.dart | 1 + lib/pages/nvram/nvram_add_widget.dart | 7 + lib/pages/nvram/nvram_delete_widget.dart | 44 +++--- .../nvram/nvram_legacy_schema_widget.dart | 7 +- pubspec.yaml | 4 +- 10 files changed, 170 insertions(+), 107 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 9b71924..55a52f8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,16 +2,22 @@ import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:desktop_window/desktop_window.dart'; +import 'package:flutter/services.dart'; import 'package:open_configurator/pages/home/home_page.dart'; import 'package:open_configurator/globals.dart' as globals; import 'package:open_configurator/pages/load_config_page.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - if (/*Platform.isWindows || */Platform.isLinux || Platform.isMacOS) { + + globals.isMobile = !(Platform.isWindows || Platform.isLinux || Platform.isMacOS); + if (globals.isMobile ) { + SystemChrome.setPreferredOrientations([ + DeviceOrientation.landscapeLeft, + ]); + } else if (/*Platform.isWindows || */Platform.isLinux || Platform.isMacOS) { await DesktopWindow.setWindowSize(Size(900, 620)); } - globals.isMobile = !(Platform.isWindows || Platform.isLinux || Platform.isMacOS); runApp(Main()); } @@ -47,18 +53,6 @@ class _MainState extends State
{ globals.changeColorMode2 = null; }); }, - onSave: () { - final path = globals.pConfig.path; - String newPath; - for (int i=path.length-1; i>-1; i--) { - if (path[i] == ".") { - newPath = path.substring(0, i) + "_OpenConf.plist"; - break; - } - } - if (newPath == null) newPath = path + "_OpenConf.plist"; - globals.pConfig.write(newPath); - }, ), ); } diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index e9f94d4..0c2977a 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -4,8 +4,8 @@ import 'package:open_configurator/pages/home/sidebar.dart'; import 'package:open_configurator/pages/nvram/nvram_page.dart'; class HomePage extends StatefulWidget { - final Function onSave, onReset; - const HomePage({this.onSave, this.onReset}); + final Function onReset; + const HomePage({this.onReset}); @override _HomePageState createState() => _HomePageState(); } @@ -20,7 +20,7 @@ class _HomePageState extends State { body: SafeArea( child: Row( children: [ - SideBar(setPage: _setPage, onSave: widget.onSave, onReset: widget.onReset), + SideBar(setPage: _setPage, onReset: widget.onReset), Expanded(child: _page), ], ), diff --git a/lib/pages/home/sidebar.dart b/lib/pages/home/sidebar.dart index 5aa085c..c1b2b9a 100644 --- a/lib/pages/home/sidebar.dart +++ b/lib/pages/home/sidebar.dart @@ -1,3 +1,7 @@ +import 'dart:io'; + +import 'package:file_picker/file_picker.dart'; +import 'package:filesystem_picker/filesystem_picker.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -13,8 +17,8 @@ import 'package:open_configurator/globals.dart' as globals; class SideBar extends StatefulWidget { - final Function setPage, onSave, onReset; - const SideBar({this.setPage, this.onSave, this.onReset}); + final Function setPage, onReset; + const SideBar({this.setPage, this.onReset}); @override _SideBarState createState() => _SideBarState(); } @@ -48,59 +52,71 @@ class _SideBarState extends State { @override Widget build(BuildContext context) { return Container( - width: globals.isMobile ? 190 : 150, + width: globals.isMobile ? 175 : 170, height: double.infinity, color: globals.isDark ? Color(0xff0C0C0D) : null, child: Column( children: [ - ..._ENTRIES.keys.map((String key) => Container( - margin: globals.isMobile ? EdgeInsets.only(bottom: 5) : null, - padding: EdgeInsets.only(right: 12), - width: double.infinity, - height: globals.isMobile ? 35 : 25, - child: ClipRRect( - borderRadius: BorderRadius.circular(25), - child: Material( - color: _selectedPage == key ? Colors.blue : Colors.transparent, - child: InkWell( - onTap: () { - setState(() => _selectedPage = key); - widget.setPage(_getPage(key)); - }, - child: Padding( - padding: EdgeInsets.only(left: 5), - child: Row( - children: [ - Icon(_ENTRIES[key], size: 14, color: globals.isDark ? Colors.white : Colors.black), - SizedBox(width: 4), - Text(key, style: TextStyle(fontSize: globals.isMobile ? 17 : 14, color: globals.isDark ? Colors.white : Colors.black)) - ], - ), + Expanded( + child: Padding( + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + child: ClipRRect( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(15), + bottomRight: Radius.circular(15), + ), + child: Container( + color: globals.isDark ? Colors.white.withOpacity(0.07) : Colors.white.withOpacity(0.01), + child: ListView( + children: [ + ..._ENTRIES.keys.map((String key) => Container( + margin: globals.isMobile ? EdgeInsets.only(bottom: 5) : null, + padding: EdgeInsets.only(right: 0), + width: double.infinity, + height: globals.isMobile ? 31 : 25, + child: ClipRRect( + borderRadius: BorderRadius.circular(25), + child: Material( + color: _selectedPage == key ? Colors.blue : Colors.transparent, + child: InkWell( + onTap: () { + setState(() => _selectedPage = key); + widget.setPage(_getPage(key)); + }, + child: Padding( + padding: EdgeInsets.only(left: 5), + child: Row( + children: [ + Icon(_ENTRIES[key], size: 14, color: globals.isDark ? Colors.white : Colors.black), + SizedBox(width: 4), + Text(key, style: TextStyle(fontSize: globals.isMobile ? 17 : 14, color: globals.isDark ? Colors.white : Colors.black)) + ], + ), + ), + ), + ), + ), + )).toList(), + ], ), ), ), ), - )).toList(), - Expanded(child: Container()), + ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text("Darkmode", style: TextStyle(fontSize: 13)), - Transform.scale( - scale: 0.7, - child: CupertinoSwitch( - value: globals.isDark, - onChanged: (value) => globals.changeColorMode(), - ), - ), - ], + Text("Darkmode", style: TextStyle(fontSize: 13)), + Transform.scale( + scale: 0.7, + child: CupertinoSwitch( + value: globals.isDark, + onChanged: (value) => globals.changeColorMode(), + ), ), ], ), - SizedBox(height: 15), + SizedBox(height: 5), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -108,8 +124,8 @@ class _SideBarState extends State { Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - Text("OpenConfigurator 0.0.1-4", style: TextStyle(fontSize: 10)), - Text("OpenCore 0.6.9", style: TextStyle(fontSize: 10)), + Text("OpenConfigurator 0.0.1-5", style: TextStyle(fontSize: 10)), + Text("OpenCore 0.7.0", style: TextStyle(fontSize: 10)), ], ), ], @@ -126,7 +142,7 @@ class _SideBarState extends State { timeInSecForIosWeb: 1, fontSize: 16.0 ); - }else undoDialog(); + }else _undoDialog(); }, // icon: Icon(Icons.undo, size: 13), icon: Icon(Icons.undo, size: globals.isMobile ? 30 : 18), @@ -134,13 +150,13 @@ class _SideBarState extends State { splashRadius: 12, ), IconButton( - onPressed: widget.onSave, + onPressed: _safeDialog, icon: Icon(Icons.save, size: globals.isMobile ? 25 : 13), padding: EdgeInsets.all(0), splashRadius: 12, ), IconButton( - onPressed: resetDialog, + onPressed: _resetDialog, icon: Icon(Icons.exit_to_app, size: globals.isMobile ? 25 : 13), padding: EdgeInsets.all(0), splashRadius: 12, @@ -152,7 +168,43 @@ class _SideBarState extends State { ); } - void undoDialog() { + void _safeDialog() async { + String newPath; + if (globals.isMobile) { + final path = await FilesystemPicker.open( + title: 'Save to folder', + context: context, + rootDirectory: Directory("/sdcard/"), + fsType: FilesystemType.folder, + pickText: 'Save file to this folder', + folderIconColor: Colors.teal, + ); + if (path == null) return; + newPath = path + "_OpenConf.plist"; + }else { + final path = globals.pConfig.path; + for (int i=path.length-1; i>-1; i--) { + if (path[i] == ".") { + newPath = path.substring(0, i) + "_OpenConf.plist"; + break; + } + } + if (newPath == null) newPath = path + "_OpenConf.plist"; + } + globals.pConfig.write(newPath); + showDialog(context: context, builder: (BuildContext context) => CupertinoAlertDialog( + title: Text("Done"), + content: Text("Config has been written to \"$newPath\""), + actions: [ + TextButton( + child: Text("Ok", style: TextStyle(color: Colors.blue)), + onPressed: () => Navigator.of(context).pop(), + ), + ], + )); + } + + void _undoDialog() { showDialog( context: context, builder: (BuildContext context) => CupertinoAlertDialog( @@ -176,7 +228,7 @@ class _SideBarState extends State { ); } - void resetDialog() { + void _resetDialog() { showDialog( context: context, builder: (BuildContext context) => CupertinoAlertDialog( diff --git a/lib/pages/load_config_page.dart b/lib/pages/load_config_page.dart index 35cc18b..dfed9a8 100644 --- a/lib/pages/load_config_page.dart +++ b/lib/pages/load_config_page.dart @@ -1,4 +1,5 @@ import 'package:clipboard/clipboard.dart'; +import 'package:file_picker/file_picker.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -21,8 +22,10 @@ class _LoadConfigPageState extends State { Future _loadConfig() async { // check permission bool storageError = false; - + // load + String value; if (Platform.isAndroid) { + // load form android if (! await Permission.storage.request().isGranted) storageError = true; else if (! await Permission.manageExternalStorage.request().isGranted) storageError = true; if (storageError) { @@ -34,22 +37,26 @@ class _LoadConfigPageState extends State { ); return; } - } - // load - String value = await FlutterClipboard.paste(); - if (value == null || value.length == 0) { - // error: clipboard is empty - _showError("Error (Clipboard is empty)"); - return; - } - // remove quotation marks - if (value[0] == "\"" && value[value.length-1] == "\"") { - value = value.substring(1, value.length-1); - if (value.length == 0) { + final result = await FilePicker.platform.pickFiles(); + if (result == null) return; + value = result.files.single.path; + }else { + // load from desktop os + value = await FlutterClipboard.paste(); + if (value == null || value.length == 0) { // error: clipboard is empty _showError("Error (Clipboard is empty)"); return; } + // remove quotation marks + if (value[0] == "\"" && value[value.length-1] == "\"") { + value = value.substring(1, value.length-1); + if (value.length == 0) { + // error: clipboard is empty + _showError("Error (Clipboard is empty)"); + return; + } + } } // read and parse file final pConfig = PConfig(path: value); @@ -122,7 +129,7 @@ class _LoadConfigPageState extends State { onTap: _loadConfig, child: Center( child: Text( - "Paste path", + Platform.isAndroid ? "Open" : "Paste path", style: TextStyle( color: const Color(0xff000000), fontWeight: FontWeight.bold @@ -161,7 +168,7 @@ class _LoadConfigPageState extends State { style: TextStyle(fontSize: 12), ), Text( - "Android: /sdcard/...", + "Android: Press Open", style: TextStyle(fontSize: 12), ), ], diff --git a/lib/pages/misc/misc_entries_widget.dart b/lib/pages/misc/misc_entries_widget.dart index 7002a73..a80fd86 100644 --- a/lib/pages/misc/misc_entries_widget.dart +++ b/lib/pages/misc/misc_entries_widget.dart @@ -25,6 +25,7 @@ class _MiscEntriesWidgetState extends State { "Auxiliary": {"type": "bool", "content": "0"}, "Comment": {"type": "string", "content": ""}, "Enabled": {"type": "bool", "content": "0"}, + "Flavour": {"type": "string", "content": "Auto"}, "Name": {"type": "string", "content": ""}, "Path": {"type": "string", "content": ""}, "TextMode": {"type": "bool", "content": "0"}, diff --git a/lib/pages/misc/misc_tools_widget.dart b/lib/pages/misc/misc_tools_widget.dart index 694f36c..bb3a1a6 100644 --- a/lib/pages/misc/misc_tools_widget.dart +++ b/lib/pages/misc/misc_tools_widget.dart @@ -25,6 +25,7 @@ class _MiscToolsWidgetState extends State { "Auxiliary": {"type": "bool", "content": "0"}, "Comment": {"type": "string", "content": ""}, "Enabled": {"type": "bool", "content": "0"}, + "Flavour": {"type": "string", "content": "Auto"}, "Name": {"type": "string", "content": ""}, "Path": {"type": "string", "content": ""}, "RealPath": {"type": "bool", "content": "0"}, diff --git a/lib/pages/nvram/nvram_add_widget.dart b/lib/pages/nvram/nvram_add_widget.dart index f783572..5b4a265 100644 --- a/lib/pages/nvram/nvram_add_widget.dart +++ b/lib/pages/nvram/nvram_add_widget.dart @@ -70,6 +70,13 @@ class _NvramAddWidgetState extends State { getValue: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Add"]["content"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["content"]["run-efi-updater"]["content"], setValue: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Add"]["content"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["content"]["run-efi-updater"]["content"] = value, ), + SizedBox(height: 4), + StringWidget( + width: 270, + title: "ForceDisplayRotationInEFI", + getValue: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Add"]["content"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["content"]["ForceDisplayRotationInEFI"]["content"], + setValue: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Add"]["content"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["content"]["ForceDisplayRotationInEFI"]["content"] = value, + ), ], ); } diff --git a/lib/pages/nvram/nvram_delete_widget.dart b/lib/pages/nvram/nvram_delete_widget.dart index b4bbb8f..e425d09 100644 --- a/lib/pages/nvram/nvram_delete_widget.dart +++ b/lib/pages/nvram/nvram_delete_widget.dart @@ -11,30 +11,28 @@ class _NvramDeleteWidgetState extends State { @override Widget build(BuildContext context) { return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - StringArrayWidget( - width: 220, - height: 200, - getStringArray: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["content"], - setStringArray: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["content"] = value, - ), - SizedBox(width: 8), - StringArrayWidget( - width: 220, - height: 200, - getStringArray: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["content"], - setStringArray: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["content"] = value, - ), - SizedBox(width: 8), - StringArrayWidget( - width: 220, - height: 200, - getStringArray: () => globals.pConfig.getValue(["content", "NVRAM", "content", "Delete", "content", "7C436110-AB2A-4BBB-A880-FE41995C9F82", "content"], null), - setStringArray: (value) => globals.pConfig.setValue(["content", "NVRAM", "content", "Delete", "content", "7C436110-AB2A-4BBB-A880-FE41995C9F82", "content"], value, null) - ), - ], + SizedBox(height: 8), + StringArrayWidget( + width: 300, + height: 200, + getStringArray: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["content"], + setStringArray: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14"]["content"] = value, + ), + SizedBox(height: 8), + StringArrayWidget( + width: 300, + height: 200, + getStringArray: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["content"], + setStringArray: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["Delete"]["content"]["4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102"]["content"] = value, + ), + SizedBox(height: 8), + StringArrayWidget( + width: 300, + height: 200, + getStringArray: () => globals.pConfig.getValue(["content", "NVRAM", "content", "Delete", "content", "7C436110-AB2A-4BBB-A880-FE41995C9F82", "content"], null), + setStringArray: (value) => globals.pConfig.setValue(["content", "NVRAM", "content", "Delete", "content", "7C436110-AB2A-4BBB-A880-FE41995C9F82", "content"], value, null) ), ], ); diff --git a/lib/pages/nvram/nvram_legacy_schema_widget.dart b/lib/pages/nvram/nvram_legacy_schema_widget.dart index 716eecb..0fdf824 100644 --- a/lib/pages/nvram/nvram_legacy_schema_widget.dart +++ b/lib/pages/nvram/nvram_legacy_schema_widget.dart @@ -10,18 +10,19 @@ class LegacySchemaWidget extends StatefulWidget { class _LegacySchemaWidgetState extends State { @override Widget build(BuildContext context) { - return Row( + return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + SizedBox(height: 8), StringArrayWidget( width: 400, height: 200, getStringArray: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["LegacySchema"]["content"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["content"], setStringArray: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["LegacySchema"]["content"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["content"] = value, ), - SizedBox(width: 8), + SizedBox(height: 8), StringArrayWidget( - width: 200, + width: 400, height: 200, getStringArray: () => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["LegacySchema"]["content"]["8BE4DF61-93CA-11D2-AA0D-00E098032B8C"]["content"], setStringArray: (value) => globals.pConfig.pConfig["content"]["NVRAM"]["content"]["LegacySchema"]["content"]["8BE4DF61-93CA-11D2-AA0D-00E098032B8C"]["content"] = value, diff --git a/pubspec.yaml b/pubspec.yaml index 6946380..d1e9553 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 0.0.1+5 environment: sdk: ">=2.7.0 <3.0.0" @@ -27,6 +27,8 @@ dependencies: hex: ^0.2.0 permission_handler: ^8.0.0+2 fluttertoast: ^8.0.7 + file_picker: ^3.0.2+2 + filesystem_picker: ^1.0.4 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.