Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
add cli flags and cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tricked-dev committed Feb 24, 2022
1 parent 18a8da1 commit 0412ac2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
14 changes: 12 additions & 2 deletions lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TMOD Installer (c) by tricked
//
//
// TMOD Installer is licensed under a
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
//
//
// You should have received a copy of the license along with this
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

Expand All @@ -13,6 +13,7 @@ import 'package:tmodinstaller/src/utils.dart';
class Config {
static SharedPreferences? preferences;
static String _directory = "";
static bool _icons = true;

static Future<void> initializePreference() async {
preferences = await SharedPreferences.getInstance();
Expand All @@ -33,4 +34,13 @@ class Config {
static String get directory {
return _directory;
}

static set icons(bool v) {
Config.preferences?.setBool("icons", v);
_icons = v;
}

static bool get icons {
return _icons;
}
}
9 changes: 8 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// You should have received a copy of the license along with this
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

import 'package:args/args.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmodinstaller/config.dart';
import 'package:tmodinstaller/src/models/models.dart';
Expand All @@ -24,7 +25,7 @@ import 'package:url_strategy/url_strategy.dart';
import 'package:window_manager/window_manager.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() async {
void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();

setPathUrlStrategy();
Expand All @@ -35,6 +36,12 @@ void main() async {
WindowManager.instance.ensureInitialized()
]);

var parser = ArgParser();
parser.addOption("moddir",
abbr: "d", callback: (v) => v != null ? Config.directory = v : null);
parser.addFlag("icon", abbr: "i", callback: (v) => Config.icons = v);
var result = parser.parse(args);

// await WindowManager.instance.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
// await windowManager.setTitleBarStyle('hidden');
Expand Down
16 changes: 5 additions & 11 deletions lib/src/screens/modlist.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TMOD Installer (c) by tricked
//
//
// TMOD Installer is licensed under a
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
//
//
// You should have received a copy of the license along with this
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

Expand All @@ -28,16 +28,10 @@ class ModListsPage extends StatefulWidget {
}

class _ModLists extends State<ModListsPage> {
String selectedVersion = "unknown";
bool _icons = true;
@override
Widget build(BuildContext context) {
final padding = PageHeader.horizontalPadding(context);

var noicons = Config.preferences?.getBool("noicons");
if (noicons != null && noicons == true) {
_icons = false;
}
return ScaffoldPage.scrollable(
header: PageHeader(title: Text('${widget.version} Mods')),
children: [
Expand Down Expand Up @@ -66,7 +60,7 @@ class _ModLists extends State<ModListsPage> {
),
child: Row(children: <Widget>[
SizedBox(height: 100),
if (_icons)
if (Config.icons)
Padding(
padding: const EdgeInsets.only(right: 14),
child: Image.network(
Expand Down Expand Up @@ -216,8 +210,8 @@ class _ModLists extends State<ModListsPage> {
builder: (BuildContext context) => _installer(
context,
mod,
mod.downloads
.firstWhere((element) => element.url == selectedVersion)),
mod.downloads.firstWhere(
(element) => element.url == _selectedVersion)),
);
},
child: const Text('Install'),
Expand Down
20 changes: 7 additions & 13 deletions lib/src/screens/settings.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TMOD Installer (c) by tricked
//
//
// TMOD Installer is licensed under a
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
//
//
// You should have received a copy of the license along with this
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

Expand Down Expand Up @@ -38,7 +38,6 @@ class Settings extends StatefulWidget {

class _SettingsState extends State<Settings> {
// const Settings({Key? key, }) : super(key: key);
bool _checked = false;
final _clearController = TextEditingController();
String current = "";
@override
Expand All @@ -59,11 +58,8 @@ class _SettingsState extends State<Settings> {
String _modfolder = "";
@override
Widget build(BuildContext context) {
var icons = Config.preferences?.getBool("noicons");
var modfolder = Config.preferences?.getString("modfolder");
if (icons != null && icons == true) {
_checked = true;
}

final appTheme = context.watch<AppTheme>();
final tooltipThemeData = TooltipThemeData(decoration: () {
const radius = BorderRadius.zero;
Expand Down Expand Up @@ -154,14 +150,12 @@ class _SettingsState extends State<Settings> {
Row(
children: [
Checkbox(
checked: _checked,
checked: !Config.icons,
onChanged: (value) => setState(() {
if (value != null && value == true) {
Config.preferences?.setBool("noicons", true);
_checked = true;
if (value != null && value == false) {
Config.icons = true;
} else {
Config.preferences?.setBool("noicons", false);
_checked = false;
Config.icons = false;
}
}),
),
Expand Down
13 changes: 4 additions & 9 deletions lib/src/screens/updater.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TMOD Installer (c) by tricked
//
//
// TMOD Installer is licensed under a
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
//
//
// You should have received a copy of the license along with this
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

Expand Down Expand Up @@ -31,8 +31,6 @@ class Updater extends StatefulWidget {
}

class _UpdaterState extends State<Updater> {
String _directory = "";
bool _icons = true;
@override
Widget build(BuildContext context) {
var updater_enabled = false;
Expand Down Expand Up @@ -66,10 +64,7 @@ class _UpdaterState extends State<Updater> {
children: [
...files.map((mod) {
final style = FluentTheme.of(context);
var noicons = Config.preferences?.getBool("noicons");
if (noicons != null && noicons == true) {
_icons = false;
}

Mod? foundMod;
DownloadMod? current;
DownloadMod? update;
Expand Down Expand Up @@ -131,7 +126,7 @@ class _UpdaterState extends State<Updater> {

child: Row(children: <Widget>[
SizedBox(height: 100),
if (_icons && foundMod != null)
if (Config.icons && foundMod != null)
Padding(
padding: const EdgeInsets.only(right: 14),
child: Image.network(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ packages:
source: hosted
version: "3.2.0"
args:
dependency: transitive
dependency: "direct main"
description:
name: args
url: "https://pub.dartlang.org"
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies:
shared_preferences: ^2.0.8
filesystem_picker: ^2.0.0
flutter_svg: ^1.0.3
args: ^2.3.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 0412ac2

Please sign in to comment.