Adds an autorestart page
This commit is contained in:
parent
239eac82b2
commit
0cf1f6b090
4 changed files with 196 additions and 4 deletions
164
lib/autorestart.dart
Normal file
164
lib/autorestart.dart
Normal file
|
@ -0,0 +1,164 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:servermanager/settings.dart';
|
||||
|
||||
part 'autorestart.g.dart';
|
||||
|
||||
@HiveType(typeId: 3)
|
||||
class AutomaticRestartInfo {
|
||||
@HiveField(0, defaultValue: 0)
|
||||
final int hours;
|
||||
|
||||
@HiveField(1, defaultValue: 0)
|
||||
final int minutes;
|
||||
|
||||
@HiveField(2, defaultValue: 0)
|
||||
final int seconds;
|
||||
|
||||
@HiveField(3, defaultValue: false)
|
||||
final bool enabled;
|
||||
|
||||
const AutomaticRestartInfo(
|
||||
{this.hours = 0,
|
||||
this.minutes = 0,
|
||||
this.seconds = 0,
|
||||
this.enabled = false});
|
||||
}
|
||||
|
||||
class AutoRestartPage extends StatefulWidget {
|
||||
AutoRestartPage({super.key});
|
||||
|
||||
@override
|
||||
AutoRestartState createState() => AutoRestartState();
|
||||
}
|
||||
|
||||
class AutoRestartState extends State<AutoRestartPage> {
|
||||
Settings settings = Settings();
|
||||
bool firstDisplay = true;
|
||||
|
||||
bool enabled = false;
|
||||
int seconds = 0;
|
||||
int minutes = 0;
|
||||
int hours = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (firstDisplay) {
|
||||
var args =
|
||||
ModalRoute.of(context)!.settings.arguments as AutomaticRestartInfo;
|
||||
enabled = args.enabled;
|
||||
seconds = args.seconds;
|
||||
minutes = args.minutes;
|
||||
hours = args.hours;
|
||||
|
||||
firstDisplay = false;
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Automatic Restart"),
|
||||
backgroundColor: Color.fromARGB(255, 100, 0, 0),
|
||||
),
|
||||
body: WillPopScope(
|
||||
onWillPop: () async {
|
||||
Navigator.pop(
|
||||
context,
|
||||
AutomaticRestartInfo(
|
||||
enabled: enabled,
|
||||
hours: hours,
|
||||
minutes: minutes,
|
||||
seconds: seconds));
|
||||
|
||||
return true;
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(children: [
|
||||
SwitchListTile(
|
||||
value: enabled,
|
||||
onChanged: (val) {
|
||||
setState(() {
|
||||
enabled = !enabled;
|
||||
});
|
||||
},
|
||||
title: Text("Enabled"),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(
|
||||
title: Text("Hours"),
|
||||
subtitle: Text("${hours}"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
max: 24,
|
||||
min: 0,
|
||||
value: hours.toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
hours = value.toInt();
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(
|
||||
title: Text("Minutes"),
|
||||
subtitle: Text("${minutes}"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
max: 60,
|
||||
min: 0,
|
||||
value: minutes.toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
minutes = value.toInt();
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 256,
|
||||
child: ListTile(
|
||||
title: Text("Seconds"),
|
||||
subtitle: Text("${seconds}"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
max: 60,
|
||||
min: 0,
|
||||
value: seconds.toDouble(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
seconds = value.toInt();
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
]),
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'dart:io';
|
|||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:servermanager/autorestart.dart';
|
||||
import 'package:servermanager/mod.dart';
|
||||
import 'package:servermanager/pathtools.dart';
|
||||
import 'package:servermanager/settings.dart';
|
||||
|
@ -178,7 +179,13 @@ class GameServerPageState extends State<GameServerPage> {
|
|||
print("Hash: ${hash}");
|
||||
|
||||
// Update the mod instance
|
||||
settings.inst!.mods[index] = M;
|
||||
setState(() {
|
||||
settings.inst!.mods[index] = Mod(
|
||||
mod_hash: hash,
|
||||
mod_id: M.mod_id,
|
||||
mod_pak: name,
|
||||
mod_name: M.mod_name);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,8 +194,21 @@ class GameServerPageState extends State<GameServerPage> {
|
|||
settings.Write();
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Mods have been scanned")));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text("Mods have been scanned and updated.")));
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Configure AutoRestart"),
|
||||
leading: Icon(Icons.timer),
|
||||
onTap: () async {
|
||||
var reply = await Navigator.pushNamed(
|
||||
context, "/server/autorestart",
|
||||
arguments: settings.inst!.timer);
|
||||
|
||||
setState(() {
|
||||
settings.inst!.timer = reply as AutomaticRestartInfo;
|
||||
});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
|
@ -262,6 +282,8 @@ class ModManagerState extends State<ModManager> {
|
|||
arguments: Mod(
|
||||
mod_id: mod.mod_id,
|
||||
mod_name: mod.mod_name,
|
||||
mod_pak: mod.mod_pak,
|
||||
mod_hash: mod.mod_hash,
|
||||
newMod: false));
|
||||
|
||||
if (reply != null) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:servermanager/autorestart.dart';
|
||||
import 'package:servermanager/credentials.dart';
|
||||
import 'package:servermanager/game.dart';
|
||||
import 'package:servermanager/home.dart';
|
||||
|
@ -36,6 +37,7 @@ class MyApp extends StatelessWidget {
|
|||
settings: appSettings,
|
||||
),
|
||||
"/server": (context) => GameServerPage(settings: appSettings),
|
||||
"/server/autorestart": (context) => AutoRestartPage(),
|
||||
"/server/mods": (context) => ModManager(settings: appSettings),
|
||||
"/server/mods/edit": (context) => ModPage(),
|
||||
"/steamcmd/creds": (context) => CredentialsPrompt()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:servermanager/autorestart.dart';
|
||||
import 'package:servermanager/credentials.dart';
|
||||
import 'package:servermanager/mod.dart';
|
||||
|
||||
|
@ -6,9 +7,12 @@ part 'settingsEntry.g.dart';
|
|||
|
||||
@HiveType(typeId: 0)
|
||||
class SettingsEntry {
|
||||
@HiveField(0)
|
||||
@HiveField(0, defaultValue: [])
|
||||
List<Mod> mods = [];
|
||||
|
||||
@HiveField(3)
|
||||
Credentials? steam_creds;
|
||||
|
||||
@HiveField(4, defaultValue: AutomaticRestartInfo())
|
||||
AutomaticRestartInfo timer = AutomaticRestartInfo();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue