Skip to content

Commit

Permalink
OC 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
trueToastedCode committed Jun 16, 2021
1 parent 9e5ee83 commit 5590dfc
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 107 deletions.
22 changes: 8 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -47,18 +53,6 @@ class _MainState extends State<Main> {
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);
},
),
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -20,7 +20,7 @@ class _HomePageState extends State<HomePage> {
body: SafeArea(
child: Row(
children: [
SideBar(setPage: _setPage, onSave: widget.onSave, onReset: widget.onReset),
SideBar(setPage: _setPage, onReset: widget.onReset),
Expanded(child: _page),
],
),
Expand Down
148 changes: 100 additions & 48 deletions lib/pages/home/sidebar.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
}
Expand Down Expand Up @@ -48,68 +52,80 @@ class _SideBarState extends State<SideBar> {
@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: [
SizedBox(width: 3),
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)),
],
),
],
Expand All @@ -126,21 +142,21 @@ class _SideBarState extends State<SideBar> {
timeInSecForIosWeb: 1,
fontSize: 16.0
);
}else undoDialog();
}else _undoDialog();
},
// icon: Icon(Icons.undo, size: 13),
icon: Icon(Icons.undo, size: globals.isMobile ? 30 : 18),
padding: EdgeInsets.all(0),
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,
Expand All @@ -152,7 +168,43 @@ class _SideBarState extends State<SideBar> {
);
}

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: <Widget>[
TextButton(
child: Text("Ok", style: TextStyle(color: Colors.blue)),
onPressed: () => Navigator.of(context).pop(),
),
],
));
}

void _undoDialog() {
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
Expand All @@ -176,7 +228,7 @@ class _SideBarState extends State<SideBar> {
);
}

void resetDialog() {
void _resetDialog() {
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
Expand Down
37 changes: 22 additions & 15 deletions lib/pages/load_config_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -21,8 +22,10 @@ class _LoadConfigPageState extends State<LoadConfigPage> {
Future<void> _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) {
Expand All @@ -34,22 +37,26 @@ class _LoadConfigPageState extends State<LoadConfigPage> {
);
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);
Expand Down Expand Up @@ -122,7 +129,7 @@ class _LoadConfigPageState extends State<LoadConfigPage> {
onTap: _loadConfig,
child: Center(
child: Text(
"Paste path",
Platform.isAndroid ? "Open" : "Paste path",
style: TextStyle(
color: const Color(0xff000000),
fontWeight: FontWeight.bold
Expand Down Expand Up @@ -161,7 +168,7 @@ class _LoadConfigPageState extends State<LoadConfigPage> {
style: TextStyle(fontSize: 12),
),
Text(
"Android: /sdcard/...",
"Android: Press Open",
style: TextStyle(fontSize: 12),
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/pages/misc/misc_entries_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _MiscEntriesWidgetState extends State<MiscEntriesWidget> {
"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"},
Expand Down
1 change: 1 addition & 0 deletions lib/pages/misc/misc_tools_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _MiscToolsWidgetState extends State<MiscToolsWidget> {
"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"},
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/nvram/nvram_add_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class _NvramAddWidgetState extends State<NvramAddWidget> {
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,
),
],
);
}
Expand Down
Loading

0 comments on commit 5590dfc

Please sign in to comment.