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

Commit 0412ac2

Browse files
committed
add cli flags and cleanup code
1 parent 18a8da1 commit 0412ac2

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed

lib/config.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// TMOD Installer (c) by tricked
2-
//
2+
//
33
// TMOD Installer is licensed under a
44
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
5-
//
5+
//
66
// You should have received a copy of the license along with this
77
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.
88

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

1718
static Future<void> initializePreference() async {
1819
preferences = await SharedPreferences.getInstance();
@@ -33,4 +34,13 @@ class Config {
3334
static String get directory {
3435
return _directory;
3536
}
37+
38+
static set icons(bool v) {
39+
Config.preferences?.setBool("icons", v);
40+
_icons = v;
41+
}
42+
43+
static bool get icons {
44+
return _icons;
45+
}
3646
}

lib/main.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// You should have received a copy of the license along with this
77
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.
88

9+
import 'package:args/args.dart';
910
import 'package:shared_preferences/shared_preferences.dart';
1011
import 'package:tmodinstaller/config.dart';
1112
import 'package:tmodinstaller/src/models/models.dart';
@@ -24,7 +25,7 @@ import 'package:url_strategy/url_strategy.dart';
2425
import 'package:window_manager/window_manager.dart';
2526
import 'package:flutter_svg/flutter_svg.dart';
2627

27-
void main() async {
28+
void main(List<String> args) async {
2829
WidgetsFlutterBinding.ensureInitialized();
2930

3031
setPathUrlStrategy();
@@ -35,6 +36,12 @@ void main() async {
3536
WindowManager.instance.ensureInitialized()
3637
]);
3738

39+
var parser = ArgParser();
40+
parser.addOption("moddir",
41+
abbr: "d", callback: (v) => v != null ? Config.directory = v : null);
42+
parser.addFlag("icon", abbr: "i", callback: (v) => Config.icons = v);
43+
var result = parser.parse(args);
44+
3845
// await WindowManager.instance.ensureInitialized();
3946
windowManager.waitUntilReadyToShow().then((_) async {
4047
// await windowManager.setTitleBarStyle('hidden');

lib/src/screens/modlist.dart

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// TMOD Installer (c) by tricked
2-
//
2+
//
33
// TMOD Installer is licensed under a
44
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
5-
//
5+
//
66
// You should have received a copy of the license along with this
77
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.
88

@@ -28,16 +28,10 @@ class ModListsPage extends StatefulWidget {
2828
}
2929

3030
class _ModLists extends State<ModListsPage> {
31-
String selectedVersion = "unknown";
32-
bool _icons = true;
3331
@override
3432
Widget build(BuildContext context) {
3533
final padding = PageHeader.horizontalPadding(context);
3634

37-
var noicons = Config.preferences?.getBool("noicons");
38-
if (noicons != null && noicons == true) {
39-
_icons = false;
40-
}
4135
return ScaffoldPage.scrollable(
4236
header: PageHeader(title: Text('${widget.version} Mods')),
4337
children: [
@@ -66,7 +60,7 @@ class _ModLists extends State<ModListsPage> {
6660
),
6761
child: Row(children: <Widget>[
6862
SizedBox(height: 100),
69-
if (_icons)
63+
if (Config.icons)
7064
Padding(
7165
padding: const EdgeInsets.only(right: 14),
7266
child: Image.network(
@@ -216,8 +210,8 @@ class _ModLists extends State<ModListsPage> {
216210
builder: (BuildContext context) => _installer(
217211
context,
218212
mod,
219-
mod.downloads
220-
.firstWhere((element) => element.url == selectedVersion)),
213+
mod.downloads.firstWhere(
214+
(element) => element.url == _selectedVersion)),
221215
);
222216
},
223217
child: const Text('Install'),

lib/src/screens/settings.dart

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// TMOD Installer (c) by tricked
2-
//
2+
//
33
// TMOD Installer is licensed under a
44
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
5-
//
5+
//
66
// You should have received a copy of the license along with this
77
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.
88

@@ -38,7 +38,6 @@ class Settings extends StatefulWidget {
3838

3939
class _SettingsState extends State<Settings> {
4040
// const Settings({Key? key, }) : super(key: key);
41-
bool _checked = false;
4241
final _clearController = TextEditingController();
4342
String current = "";
4443
@override
@@ -59,11 +58,8 @@ class _SettingsState extends State<Settings> {
5958
String _modfolder = "";
6059
@override
6160
Widget build(BuildContext context) {
62-
var icons = Config.preferences?.getBool("noicons");
6361
var modfolder = Config.preferences?.getString("modfolder");
64-
if (icons != null && icons == true) {
65-
_checked = true;
66-
}
62+
6763
final appTheme = context.watch<AppTheme>();
6864
final tooltipThemeData = TooltipThemeData(decoration: () {
6965
const radius = BorderRadius.zero;
@@ -154,14 +150,12 @@ class _SettingsState extends State<Settings> {
154150
Row(
155151
children: [
156152
Checkbox(
157-
checked: _checked,
153+
checked: !Config.icons,
158154
onChanged: (value) => setState(() {
159-
if (value != null && value == true) {
160-
Config.preferences?.setBool("noicons", true);
161-
_checked = true;
155+
if (value != null && value == false) {
156+
Config.icons = true;
162157
} else {
163-
Config.preferences?.setBool("noicons", false);
164-
_checked = false;
158+
Config.icons = false;
165159
}
166160
}),
167161
),

lib/src/screens/updater.dart

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// TMOD Installer (c) by tricked
2-
//
2+
//
33
// TMOD Installer is licensed under a
44
// Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
5-
//
5+
//
66
// You should have received a copy of the license along with this
77
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.
88

@@ -31,8 +31,6 @@ class Updater extends StatefulWidget {
3131
}
3232

3333
class _UpdaterState extends State<Updater> {
34-
String _directory = "";
35-
bool _icons = true;
3634
@override
3735
Widget build(BuildContext context) {
3836
var updater_enabled = false;
@@ -66,10 +64,7 @@ class _UpdaterState extends State<Updater> {
6664
children: [
6765
...files.map((mod) {
6866
final style = FluentTheme.of(context);
69-
var noicons = Config.preferences?.getBool("noicons");
70-
if (noicons != null && noicons == true) {
71-
_icons = false;
72-
}
67+
7368
Mod? foundMod;
7469
DownloadMod? current;
7570
DownloadMod? update;
@@ -131,7 +126,7 @@ class _UpdaterState extends State<Updater> {
131126

132127
child: Row(children: <Widget>[
133128
SizedBox(height: 100),
134-
if (_icons && foundMod != null)
129+
if (Config.icons && foundMod != null)
135130
Padding(
136131
padding: const EdgeInsets.only(right: 14),
137132
child: Image.network(

pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ packages:
1616
source: hosted
1717
version: "3.2.0"
1818
args:
19-
dependency: transitive
19+
dependency: "direct main"
2020
description:
2121
name: args
2222
url: "https://pub.dartlang.org"

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies:
4444
shared_preferences: ^2.0.8
4545
filesystem_picker: ^2.0.0
4646
flutter_svg: ^1.0.3
47+
args: ^2.3.0
4748

4849
dev_dependencies:
4950
flutter_test:

0 commit comments

Comments
 (0)