Makes settings into a singleton

This commit is contained in:
Zontreck 2023-11-03 01:57:24 -07:00
parent 46f8e55d70
commit 64f5e3c267
2 changed files with 38 additions and 30 deletions

View file

@ -11,40 +11,41 @@ class Proton extends StatefulWidget {
ProtonState createState() => ProtonState(settings: settings);
}
Future<void> runProton(String command, List<String> argx) async {
Settings settings = Settings();
Directory dir =
Directory(settings.game_path + Platform.pathSeparator + "pfx");
if (dir.existsSync()) {
await dir.delete(recursive: true);
}
await dir.create(recursive: true);
Map<String, String> env = Map.from(Platform.environment);
env["STEAM_COMPAT_CLIENT_INSTALL_PATH"] = "~/.steam";
env["STEAM_COMPAT_DATA_PATH"] = dir.path;
try {
List<String> args = ["run", command];
args.addAll(argx);
ProcessResult res = await Process.run(
"proton", args, // Run arbitrary command with arguments
environment: env,
);
print('Exit code: ${res.exitCode}');
print('stdout: ${res.stdout}');
print('stderr: ${res.stderr}');
} catch (e) {
print('Error executing command: $e');
}
}
class ProtonState extends State<Proton> {
Settings settings;
ProtonState({required this.settings});
Future<void> runProton(String command, List<String> argx) async {
Directory dir =
Directory(settings.game_path + Platform.pathSeparator + "pfx");
if (dir.existsSync()) {
await dir.delete(recursive: true);
}
await dir.create(recursive: true);
Map<String, String> env = Map.from(Platform.environment);
env["STEAM_COMPAT_CLIENT_INSTALL_PATH"] = "~/.steam";
env["STEAM_COMPAT_DATA_PATH"] = dir.path;
try {
List<String> args = ["run", command];
args.addAll(argx);
ProcessResult res = await Process.run(
"proton", args, // Run arbitrary command with arguments
environment: env,
);
print('Exit code: ${res.exitCode}');
print('stdout: ${res.stdout}');
print('stderr: ${res.stderr}');
} catch (e) {
print('Error executing command: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(

View file

@ -6,6 +6,13 @@ import 'package:servermanager/mod.dart';
import 'package:servermanager/steamcmd.dart';
class Settings {
Settings._();
static final Settings Instance = Settings._();
factory Settings() {
return Instance;
}
void Read() {
if (!isValid()) return;
var box = Hive.box("settings");