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

Commit 010bfe2

Browse files
committed
feat: fix some theme issues
1 parent 235b9f3 commit 010bfe2

File tree

8 files changed

+140
-94
lines changed

8 files changed

+140
-94
lines changed

lib/main.dart

+20-81
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void main(List<String> args) async {
3636
await Config.initializePreference();
3737
await Future.wait([
3838
flutter_acrylic.Window.initialize(),
39-
_TModInstallerPageState.fetchData(),
39+
fetchData(),
4040
WindowManager.instance.ensureInitialized()
4141
]);
4242

@@ -74,18 +74,24 @@ class TModInstallerApp extends StatelessWidget {
7474
builder: (context, _) {
7575
final appTheme = context.watch<AppTheme>();
7676
//Quick and dirty way to set the color!
77-
var theme = Config.preferences?.getInt("color");
78-
if (theme != null) {
79-
if (theme == -1) {
77+
var color = Config.preferences?.getInt("color");
78+
if (color != null) {
79+
if (color == -1) {
8080
appTheme.rawColor = systemAccentColor;
8181
} else {
82-
appTheme.rawColor = Colors.accentColors[theme];
82+
appTheme.rawColor = Colors.accentColors[color];
8383
}
8484
}
8585

86+
var theme = Config.preferences?.getInt("theme");
87+
if (theme != null) {
88+
appTheme.rawMode = ThemeMode.values[theme];
89+
}
90+
8691
return FluentApp(
8792
title: 'Tricked mod Installer',
8893
debugShowCheckedModeBanner: false,
94+
themeMode: appTheme.mode,
8995
color: appTheme.color,
9096
darkTheme: ThemeData(
9197
brightness: Brightness.dark,
@@ -139,87 +145,20 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
139145
super.dispose();
140146
}
141147

142-
static Future<void> fetchData() async {
143-
//TODO save mods somewhere for offline
144-
try {
145-
var repos = Config.preferences?.getStringList("repos");
146-
if (repos != null) {
147-
for (var repo in repos) {
148-
var trimmed = repo.trim();
149-
//Prevent leading commas from erroring shit
150-
if (trimmed == "") continue;
151-
final res = await http.get(Uri.parse(trimmed.startsWith("http")
152-
? trimmed
153-
: "https://tmod.deno.dev/$trimmed.json"));
154-
var data = json.decode(res.body);
155-
156-
mods = [
157-
...mods,
158-
...data["mods"].map((x) {
159-
x["repo"] = data["id"];
160-
x["meta"].removeWhere((k, v) => v == null);
161-
if (x["icon"] == null)
162-
x["icon"] =
163-
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";
164-
165-
return Mod.fromJson(x);
166-
})
167-
];
168-
}
169-
} else {
170-
final response =
171-
await http.get(Uri.parse('https://tmod.deno.dev/std.json'));
172-
var data = json.decode(response.body);
173-
174-
mods = [
175-
...mods,
176-
...data["mods"].map((x) {
177-
x["repo"] = data["id"];
178-
x["meta"].removeWhere((k, v) => v == null);
179-
if (x["icon"] == null)
180-
x["icon"] =
181-
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";
182-
return Mod.fromJson(x);
183-
})
184-
];
185-
}
186-
} catch (_) {
187-
print(_);
188-
mods = [
189-
Mod(
190-
categories: [],
191-
repo: "INVALID",
192-
display: "INVALID REPO DETECTED",
193-
description:
194-
"PLEASE ENSURE THAT ALL REPOS ARE VALID AND WORKING BEFORE ADDING THEM",
195-
id: "INVALID",
196-
downloads: [
197-
DownloadMod(
198-
filename: "INVALID",
199-
mcversions: ["0.0.0"],
200-
version: "0.0.0",
201-
hash: "sha1;null",
202-
url: "")
203-
],
204-
nicknames: [],
205-
conflicts: [],
206-
forgeid: "INVALID",
207-
meta: {},
208-
icon:
209-
"https://cdn-images-1.medium.com/max/1200/1*5-aoK8IBmXve5whBQM90GA.png")
210-
];
211-
}
212-
}
213-
214148
@override
215149
Widget build(BuildContext context) {
216150
final appTheme = context.watch<AppTheme>();
151+
217152
final List<String> lastversions = [
218-
"1.8.9",
219-
"1.12.2",
153+
"1.18.2",
154+
"1.18.1",
220155
"1.17.1",
221-
"1.14.4",
222-
"1.16.5"
156+
"1.16.5",
157+
// "1.15.2",
158+
// "1.14.4",
159+
// "1.13.2",
160+
"1.12.2",
161+
"1.8.9",
223162
];
224163
List<String> versions = Set.of(Set.of(mods
225164
.map((x) => x.downloads.map((x) => x.mcversions))

lib/src/screens/launcher.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class _LauncherState extends State<Launcher> {
6363
flutter.SelectableText(
6464
"This will empty the current mod folder and install all mods from this version that you installed",
6565
),
66+
spacer,
6667
FilledButton(
6768
child: Text("Click here!"),
6869
onPressed: () async {
@@ -83,7 +84,7 @@ class _LauncherState extends State<Launcher> {
8384
style: FluentTheme.of(context).typography.subtitle),
8485
spacer,
8586
flutter.SelectableText(
86-
"Current directory $_modfolder",
87+
"Current directory $_modfolder ${_modfolder == Config.directory ? "(Default)" : ""}",
8788
),
8889
spacer,
8990
TextBox(

lib/src/screens/mod.dart

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class _ModScreenState extends State<ModScreen> {
152152
crossAxisAlignment: CrossAxisAlignment.start,
153153
children: <Widget>[
154154
...[
155+
Text("Repo: ${widget.mod.repo}"),
155156
...r,
156157
FilledButton(
157158
child: const Text("Install Mod"),

lib/src/screens/settings.dart

+23-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:tmodinstaller/config.dart';
1515
import 'package:url_launcher/url_launcher.dart';
1616
import 'dart:io';
1717
import '../../theme.dart';
18+
import '../utils.dart';
1819

1920
const List<String> accentColorNames = [
2021
'System',
@@ -93,6 +94,24 @@ class _SettingsState extends State<Settings> {
9394
header: const PageHeader(title: Text('Settings')),
9495
scrollController: widget.controller,
9596
children: [
97+
Text('Theme mode', style: FluentTheme.of(context).typography.subtitle),
98+
spacer,
99+
...List.generate(ThemeMode.values.length, (index) {
100+
final mode = ThemeMode.values[index];
101+
return Padding(
102+
padding: const EdgeInsets.only(bottom: 8.0),
103+
child: RadioButton(
104+
checked: appTheme.mode == mode,
105+
onChanged: (value) {
106+
if (value) {
107+
Config.preferences?.setInt("theme", index);
108+
appTheme.mode = mode;
109+
}
110+
},
111+
content: Text('$mode'.replaceAll('ThemeMode.', '')),
112+
),
113+
);
114+
}),
96115
biggerSpacer,
97116
Text('Accent Color',
98117
style: FluentTheme.of(context).typography.subtitle),
@@ -115,7 +134,7 @@ class _SettingsState extends State<Settings> {
115134
biggerSpacer,
116135
Text("Mod repo's", style: FluentTheme.of(context).typography.subtitle),
117136
const flutter.SelectableText(
118-
"Repos are split by ',' the default repos are https://tmod.deno.dev/std.json,https://tmod.deno.dev/skyclient.json,https://tmod.deno.dev/feather.json\nA restart is required after updating the repos",
137+
"Repos are split by ',' the available repos are: skyclient,feather,std. Use urls for external ones.\nA restart is required after updating the repos",
119138
),
120139
spacer,
121140
TextBox(
@@ -131,9 +150,10 @@ class _SettingsState extends State<Settings> {
131150
},
132151
suffix: IconButton(
133152
icon: const Icon(FluentIcons.add_to),
134-
onPressed: () {
153+
onPressed: () async {
135154
Config.preferences?.setStringList("repos", current.split(","));
136-
155+
fetchData();
156+
setState(() {});
137157
// _clearController.clear();
138158
},
139159
),

lib/src/screens/updater.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class _UpdaterState extends State<Updater> {
5555
// child: OutlinedButton(onPressed: () {}, child: Text("Update all")),
5656
// ),
5757
Column(children: [
58+
if (files.length == 0)
59+
const Text("No mods found get back later when you installed some"),
5860
...files.map((mod) {
5961
final style = FluentTheme.of(context);
6062

@@ -126,8 +128,8 @@ class _UpdaterState extends State<Updater> {
126128
),
127129
if (foundMod == null)
128130
const DefaultTextStyle(
129-
child:
130-
Text("Could not find the origin of this mod"),
131+
child: Text(
132+
"Could not find the origin of this mod, Maybe the repo of this mod is not enabled?"),
131133
style: const TextStyle(),
132134
overflow: TextOverflow.fade,
133135
),

lib/src/screens/version.dart

+11-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ class _VersionPage extends State<VersionPage> {
4949
tabs = List.generate(3, (index) {
5050
late Tab tab;
5151
tab = Tab(
52-
text: Text(index == 1
53-
? "Mod Installer"
54-
: index == 2
55-
? "Mod Updater"
56-
: "Launcher"),
52+
closeIcon: FluentIcons.emi,
53+
icon: Icon(index == 0
54+
? FluentIcons.rocket
55+
: index == 1
56+
? FluentIcons.download
57+
: FluentIcons.library),
58+
text: Text(index == 0
59+
? "Launcher"
60+
: index == 1
61+
? "Mod Installer"
62+
: "Mod Manager"),
5763
// _handleTabClosed(tab);
5864
// },
5965
);

lib/src/utils.dart

+73
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,76 @@ String getModFolder(String mcv) {
8585
var version = versions.firstWhereOrNull((element) => element.version == mcv);
8686
return version?.moddir ?? Config.directory;
8787
}
88+
89+
Future<void> fetchData() async {
90+
mods = [];
91+
//TODO save mods somewhere for offline
92+
try {
93+
var repos = Config.preferences?.getStringList("repos");
94+
if (repos != null) {
95+
for (var repo in repos) {
96+
var trimmed = repo.trim();
97+
//Prevent leading commas from erroring shit
98+
if (trimmed == "") continue;
99+
final res = await http.get(Uri.parse(trimmed.startsWith("http")
100+
? trimmed
101+
: "https://tmod.deno.dev/$trimmed.json"));
102+
var data = json.decode(res.body);
103+
104+
mods = [
105+
...mods,
106+
...data["mods"].map((x) {
107+
x["repo"] = data["id"];
108+
x["meta"].removeWhere((k, v) => v == null);
109+
if (x["icon"] == null)
110+
x["icon"] =
111+
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";
112+
113+
return Mod.fromJson(x);
114+
})
115+
];
116+
}
117+
} else {
118+
final response =
119+
await http.get(Uri.parse('https://tmod.deno.dev/std.json'));
120+
var data = json.decode(response.body);
121+
122+
mods = [
123+
...mods,
124+
...data["mods"].map((x) {
125+
x["repo"] = data["id"];
126+
x["meta"].removeWhere((k, v) => v == null);
127+
if (x["icon"] == null)
128+
x["icon"] =
129+
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";
130+
return Mod.fromJson(x);
131+
})
132+
];
133+
}
134+
} catch (_) {
135+
print(_);
136+
mods = [
137+
Mod(
138+
categories: [],
139+
repo: "INVALID",
140+
display: "INVALID REPO DETECTED",
141+
description:
142+
"PLEASE ENSURE THAT ALL REPOS ARE VALID AND WORKING BEFORE ADDING THEM",
143+
id: "INVALID",
144+
downloads: [
145+
DownloadMod(
146+
filename: "INVALID",
147+
mcversions: ["0.0.0"],
148+
version: "0.0.0",
149+
hash: "sha1;null",
150+
url: "")
151+
],
152+
nicknames: [],
153+
conflicts: [],
154+
forgeid: "INVALID",
155+
meta: {},
156+
icon:
157+
"https://cdn-images-1.medium.com/max/1200/1*5-aoK8IBmXve5whBQM90GA.png")
158+
];
159+
}
160+
}

lib/theme.dart

+6-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

@@ -32,6 +32,10 @@ class AppTheme extends ChangeNotifier {
3232
notifyListeners();
3333
}
3434

35+
set rawMode(ThemeMode mode) {
36+
_mode = mode;
37+
}
38+
3539
PaneDisplayMode _displayMode = PaneDisplayMode.auto;
3640
PaneDisplayMode get displayMode => _displayMode;
3741
set displayMode(PaneDisplayMode displayMode) {

0 commit comments

Comments
 (0)