Add a 2fa toggle

This commit is contained in:
zontreck 2023-11-08 15:20:40 -07:00
parent fce8632639
commit 54f90c7cdb
3 changed files with 31 additions and 13 deletions

View file

@ -4,15 +4,21 @@ part 'credentials.g.dart';
@HiveType(typeId: 1)
class Credentials {
@HiveField(0)
@HiveField(0, defaultValue: "")
String username;
@HiveField(1)
@HiveField(1, defaultValue: "")
String password;
@HiveField(2)
@HiveField(2, defaultValue: "")
String secret;
@HiveField(3, defaultValue: false)
bool has_2fa = false;
Credentials(
{required this.username, required this.password, required this.secret});
{required this.username,
required this.password,
required this.secret,
required this.has_2fa});
}

View file

@ -13,9 +13,12 @@ Future<void> doDownloadMods(String modsFolder) async {
Settings settings = Settings();
// Now, invoke SteamCmd to download the workshop mods. This is an authenticated action, and does require Scmd2fa
var result = await Process.run(settings.getSteamCmd2FA(),
["--raw", "--secret", settings.inst!.steam_creds!.secret]);
var code = result.stdout as String;
String code = "";
if (settings.inst!.steam_creds!.has_2fa) {
var result = await Process.run(settings.getSteamCmd2FA(),
["--raw", "--secret", settings.inst!.steam_creds!.secret]);
code = result.stdout as String;
}
// Build download command
List<String> manifest = [
@ -26,7 +29,7 @@ Future<void> doDownloadMods(String modsFolder) async {
"+login",
settings.inst!.steam_creds!.username,
settings.inst!.steam_creds!.password,
code.trim()
if (settings.inst!.steam_creds!.has_2fa) code.trim()
];
for (Mod M in settings.inst!.mods) {
manifest.add("+workshop_download_item");
@ -41,7 +44,7 @@ Future<void> doDownloadMods(String modsFolder) async {
//print(
// "Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}");
result = await Process.run(settings.getSteamCmd(), manifest);
var result = await Process.run(settings.getSteamCmd(), manifest);
print(result.stdout);
}

View file

@ -67,7 +67,8 @@ class SteamCMDState extends State<SteamCMD> {
if (Platform.isWindows) {
// Download zip file
final path = "${settings.steamcmd_path}${Platform.pathSeparator}windows.zip";
final path =
"${settings.steamcmd_path}${Platform.pathSeparator}windows.zip";
final reply = await dio.download(windows, path);
final bytes = File(path).readAsBytesSync();
@ -91,7 +92,8 @@ class SteamCMDState extends State<SteamCMD> {
await Process.start("steamcmd.exe", ["+quit"]);
} else {
// Download tgz file
final path = "${settings.steamcmd_path}${Platform.pathSeparator}linux.tgz";
final path =
"${settings.steamcmd_path}${Platform.pathSeparator}linux.tgz";
final reply = await dio.download(linux, path);
final bytes = File(path).readAsBytesSync();
@ -175,6 +177,7 @@ class CredentialsPrompt extends StatelessWidget {
TextEditingController password = TextEditingController();
TextEditingController secret = TextEditingController();
bool initialInitDone = false;
bool z2fa = false;
@override
Widget build(BuildContext context) {
@ -268,7 +271,12 @@ class CredentialsPrompt extends StatelessWidget {
"2FA Shared Secret Code (Do Not Share With Others!)"),
))
],
)
),
SwitchListTile(
value: z2fa,
onChanged: (value) {
z2fa = value;
})
],
)),
onWillPop: () async {
@ -277,7 +285,8 @@ class CredentialsPrompt extends StatelessWidget {
Credentials(
username: username.text,
password: password.text,
secret: secret.text));
secret: secret.text,
has_2fa: z2fa));
return true;
},
));