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

Commit

Permalink
feat: fix some theme issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tricked-dev committed Feb 28, 2022
1 parent 235b9f3 commit 010bfe2
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 94 deletions.
101 changes: 20 additions & 81 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main(List<String> args) async {
await Config.initializePreference();
await Future.wait([
flutter_acrylic.Window.initialize(),
_TModInstallerPageState.fetchData(),
fetchData(),
WindowManager.instance.ensureInitialized()
]);

Expand Down Expand Up @@ -74,18 +74,24 @@ class TModInstallerApp extends StatelessWidget {
builder: (context, _) {
final appTheme = context.watch<AppTheme>();
//Quick and dirty way to set the color!
var theme = Config.preferences?.getInt("color");
if (theme != null) {
if (theme == -1) {
var color = Config.preferences?.getInt("color");
if (color != null) {
if (color == -1) {
appTheme.rawColor = systemAccentColor;
} else {
appTheme.rawColor = Colors.accentColors[theme];
appTheme.rawColor = Colors.accentColors[color];
}
}

var theme = Config.preferences?.getInt("theme");
if (theme != null) {
appTheme.rawMode = ThemeMode.values[theme];
}

return FluentApp(
title: 'Tricked mod Installer',
debugShowCheckedModeBanner: false,
themeMode: appTheme.mode,
color: appTheme.color,
darkTheme: ThemeData(
brightness: Brightness.dark,
Expand Down Expand Up @@ -139,87 +145,20 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
super.dispose();
}

static Future<void> fetchData() async {
//TODO save mods somewhere for offline
try {
var repos = Config.preferences?.getStringList("repos");
if (repos != null) {
for (var repo in repos) {
var trimmed = repo.trim();
//Prevent leading commas from erroring shit
if (trimmed == "") continue;
final res = await http.get(Uri.parse(trimmed.startsWith("http")
? trimmed
: "https://tmod.deno.dev/$trimmed.json"));
var data = json.decode(res.body);

mods = [
...mods,
...data["mods"].map((x) {
x["repo"] = data["id"];
x["meta"].removeWhere((k, v) => v == null);
if (x["icon"] == null)
x["icon"] =
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";

return Mod.fromJson(x);
})
];
}
} else {
final response =
await http.get(Uri.parse('https://tmod.deno.dev/std.json'));
var data = json.decode(response.body);

mods = [
...mods,
...data["mods"].map((x) {
x["repo"] = data["id"];
x["meta"].removeWhere((k, v) => v == null);
if (x["icon"] == null)
x["icon"] =
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";
return Mod.fromJson(x);
})
];
}
} catch (_) {
print(_);
mods = [
Mod(
categories: [],
repo: "INVALID",
display: "INVALID REPO DETECTED",
description:
"PLEASE ENSURE THAT ALL REPOS ARE VALID AND WORKING BEFORE ADDING THEM",
id: "INVALID",
downloads: [
DownloadMod(
filename: "INVALID",
mcversions: ["0.0.0"],
version: "0.0.0",
hash: "sha1;null",
url: "")
],
nicknames: [],
conflicts: [],
forgeid: "INVALID",
meta: {},
icon:
"https://cdn-images-1.medium.com/max/1200/1*5-aoK8IBmXve5whBQM90GA.png")
];
}
}

@override
Widget build(BuildContext context) {
final appTheme = context.watch<AppTheme>();

final List<String> lastversions = [
"1.8.9",
"1.12.2",
"1.18.2",
"1.18.1",
"1.17.1",
"1.14.4",
"1.16.5"
"1.16.5",
// "1.15.2",
// "1.14.4",
// "1.13.2",
"1.12.2",
"1.8.9",
];
List<String> versions = Set.of(Set.of(mods
.map((x) => x.downloads.map((x) => x.mcversions))
Expand Down
3 changes: 2 additions & 1 deletion lib/src/screens/launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class _LauncherState extends State<Launcher> {
flutter.SelectableText(
"This will empty the current mod folder and install all mods from this version that you installed",
),
spacer,
FilledButton(
child: Text("Click here!"),
onPressed: () async {
Expand All @@ -83,7 +84,7 @@ class _LauncherState extends State<Launcher> {
style: FluentTheme.of(context).typography.subtitle),
spacer,
flutter.SelectableText(
"Current directory $_modfolder",
"Current directory $_modfolder ${_modfolder == Config.directory ? "(Default)" : ""}",
),
spacer,
TextBox(
Expand Down
1 change: 1 addition & 0 deletions lib/src/screens/mod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class _ModScreenState extends State<ModScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
...[
Text("Repo: ${widget.mod.repo}"),
...r,
FilledButton(
child: const Text("Install Mod"),
Expand Down
26 changes: 23 additions & 3 deletions lib/src/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:tmodinstaller/config.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';
import '../../theme.dart';
import '../utils.dart';

const List<String> accentColorNames = [
'System',
Expand Down Expand Up @@ -93,6 +94,24 @@ class _SettingsState extends State<Settings> {
header: const PageHeader(title: Text('Settings')),
scrollController: widget.controller,
children: [
Text('Theme mode', style: FluentTheme.of(context).typography.subtitle),
spacer,
...List.generate(ThemeMode.values.length, (index) {
final mode = ThemeMode.values[index];
return Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: RadioButton(
checked: appTheme.mode == mode,
onChanged: (value) {
if (value) {
Config.preferences?.setInt("theme", index);
appTheme.mode = mode;
}
},
content: Text('$mode'.replaceAll('ThemeMode.', '')),
),
);
}),
biggerSpacer,
Text('Accent Color',
style: FluentTheme.of(context).typography.subtitle),
Expand All @@ -115,7 +134,7 @@ class _SettingsState extends State<Settings> {
biggerSpacer,
Text("Mod repo's", style: FluentTheme.of(context).typography.subtitle),
const flutter.SelectableText(
"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",
"Repos are split by ',' the available repos are: skyclient,feather,std. Use urls for external ones.\nA restart is required after updating the repos",
),
spacer,
TextBox(
Expand All @@ -131,9 +150,10 @@ class _SettingsState extends State<Settings> {
},
suffix: IconButton(
icon: const Icon(FluentIcons.add_to),
onPressed: () {
onPressed: () async {
Config.preferences?.setStringList("repos", current.split(","));

fetchData();
setState(() {});
// _clearController.clear();
},
),
Expand Down
6 changes: 4 additions & 2 deletions lib/src/screens/updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class _UpdaterState extends State<Updater> {
// child: OutlinedButton(onPressed: () {}, child: Text("Update all")),
// ),
Column(children: [
if (files.length == 0)
const Text("No mods found get back later when you installed some"),
...files.map((mod) {
final style = FluentTheme.of(context);

Expand Down Expand Up @@ -126,8 +128,8 @@ class _UpdaterState extends State<Updater> {
),
if (foundMod == null)
const DefaultTextStyle(
child:
Text("Could not find the origin of this mod"),
child: Text(
"Could not find the origin of this mod, Maybe the repo of this mod is not enabled?"),
style: const TextStyle(),
overflow: TextOverflow.fade,
),
Expand Down
16 changes: 11 additions & 5 deletions lib/src/screens/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ class _VersionPage extends State<VersionPage> {
tabs = List.generate(3, (index) {
late Tab tab;
tab = Tab(
text: Text(index == 1
? "Mod Installer"
: index == 2
? "Mod Updater"
: "Launcher"),
closeIcon: FluentIcons.emi,
icon: Icon(index == 0
? FluentIcons.rocket
: index == 1
? FluentIcons.download
: FluentIcons.library),
text: Text(index == 0
? "Launcher"
: index == 1
? "Mod Installer"
: "Mod Manager"),
// _handleTabClosed(tab);
// },
);
Expand Down
73 changes: 73 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,76 @@ String getModFolder(String mcv) {
var version = versions.firstWhereOrNull((element) => element.version == mcv);
return version?.moddir ?? Config.directory;
}

Future<void> fetchData() async {
mods = [];
//TODO save mods somewhere for offline
try {
var repos = Config.preferences?.getStringList("repos");
if (repos != null) {
for (var repo in repos) {
var trimmed = repo.trim();
//Prevent leading commas from erroring shit
if (trimmed == "") continue;
final res = await http.get(Uri.parse(trimmed.startsWith("http")
? trimmed
: "https://tmod.deno.dev/$trimmed.json"));
var data = json.decode(res.body);

mods = [
...mods,
...data["mods"].map((x) {
x["repo"] = data["id"];
x["meta"].removeWhere((k, v) => v == null);
if (x["icon"] == null)
x["icon"] =
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";

return Mod.fromJson(x);
})
];
}
} else {
final response =
await http.get(Uri.parse('https://tmod.deno.dev/std.json'));
var data = json.decode(response.body);

mods = [
...mods,
...data["mods"].map((x) {
x["repo"] = data["id"];
x["meta"].removeWhere((k, v) => v == null);
if (x["icon"] == null)
x["icon"] =
"https://raw.githubusercontent.com/Tricked-dev/tmodinstaller/master/linux/debian/usr/share/icons/hicolor/256x256/apps/tmodinstaller.png";
return Mod.fromJson(x);
})
];
}
} catch (_) {
print(_);
mods = [
Mod(
categories: [],
repo: "INVALID",
display: "INVALID REPO DETECTED",
description:
"PLEASE ENSURE THAT ALL REPOS ARE VALID AND WORKING BEFORE ADDING THEM",
id: "INVALID",
downloads: [
DownloadMod(
filename: "INVALID",
mcversions: ["0.0.0"],
version: "0.0.0",
hash: "sha1;null",
url: "")
],
nicknames: [],
conflicts: [],
forgeid: "INVALID",
meta: {},
icon:
"https://cdn-images-1.medium.com/max/1200/1*5-aoK8IBmXve5whBQM90GA.png")
];
}
}
8 changes: 6 additions & 2 deletions lib/theme.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 @@ -32,6 +32,10 @@ class AppTheme extends ChangeNotifier {
notifyListeners();
}

set rawMode(ThemeMode mode) {
_mode = mode;
}

PaneDisplayMode _displayMode = PaneDisplayMode.auto;
PaneDisplayMode get displayMode => _displayMode;
set displayMode(PaneDisplayMode displayMode) {
Expand Down

0 comments on commit 010bfe2

Please sign in to comment.