From d64a34605c8a1c7bc1739d5074c28986c5c87ea2 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 23 Nov 2024 16:00:04 -0700 Subject: [PATCH] Send a webhook alert when restart is required for mod list changes --- lib/consts.dart | 2 +- lib/packets/ClientPackets.dart | 10 ++++++++++ lib/pages/ModManager.dart | 9 +++++++++ lib/pages/home.dart | 4 ++-- lib/structs/settings.dart | 2 ++ pubspec.yaml | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/consts.dart b/lib/consts.dart index ded7f88..2081a39 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -1,3 +1,3 @@ class Consts { - static const VERSION = "1.1.112324.1308"; + static const VERSION = "1.1.112324.1559"; } diff --git a/lib/packets/ClientPackets.dart b/lib/packets/ClientPackets.dart index 29e55b2..108bb4b 100644 --- a/lib/packets/ClientPackets.dart +++ b/lib/packets/ClientPackets.dart @@ -353,6 +353,16 @@ class C2SUploadSettingsPacket implements IPacket { if (!performRestart) { return PacketResponse.nil; + } else { + // Send a webhook with all the mods listed + String modListText = ""; + for (var entry in settings.inst!.mods) { + modListText += "${entry.mod_name}\n"; + } + + modListText = modListText.trim(); + DiscordHookHelper.sendWebHook(settings.inst!.discord, + DiscordHookProps.INACTIVE, "Mod List Updated", modListText); } // Check if server is running, if not, stop immediately diff --git a/lib/pages/ModManager.dart b/lib/pages/ModManager.dart index 4a767ae..ac3754f 100644 --- a/lib/pages/ModManager.dart +++ b/lib/pages/ModManager.dart @@ -55,6 +55,8 @@ class ModManagerState extends State { i++; } while (i < end - oldIndex); settings.inst!.mods[end] = item; + + settings.restartRequired = true; } else if (oldIndex > newIndex) { //From bottom to top Mod item = settings.inst!.mods[oldIndex]; @@ -62,6 +64,8 @@ class ModManagerState extends State { settings.inst!.mods[i] = settings.inst!.mods[i - 1]; } settings.inst!.mods[newIndex] = item; + + settings.restartRequired = true; } setState(() { settings.Write(); @@ -92,11 +96,14 @@ class ModManagerState extends State { if (MERA.delete) { setState(() { settings.inst!.mods.removeAt(idx); + settings.restartRequired = true; }); return; } setState(() { settings.inst!.mods[idx] = MERA.mod!; + + settings.restartRequired = true; }); } }, @@ -117,6 +124,8 @@ class ModManagerState extends State { setState(() { settings.inst!.mods.add(MERA.mod!); + + settings.restartRequired = true; }); } }, diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 55790a9..d51d3d3 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -141,7 +141,7 @@ class HomePageState extends State { }, ), SwitchListTile( - value: requireRestart, + value: requireRestart || settings.restartRequired, onChanged: (V) { setState(() { requireRestart = V; @@ -149,7 +149,7 @@ class HomePageState extends State { }, title: Text("Perform Restart"), subtitle: Text( - "Whether a immediate server restart should be performed in combination with this wrapper settings update"), + "Whether a immediate server restart should be performed in combination with this wrapper settings update${settings.restartRequired ? "\n** A RESTART IS REQUIRED DUE TO MOD LIST CHANGES" : ""}"), ) ], )), diff --git a/lib/structs/settings.dart b/lib/structs/settings.dart index f1f15cb..6e298f2 100644 --- a/lib/structs/settings.dart +++ b/lib/structs/settings.dart @@ -45,6 +45,8 @@ class Settings { StateMachine subsys = StateMachine(); + bool restartRequired = false; + factory Settings() { return Instance; } diff --git a/pubspec.yaml b/pubspec.yaml index 285e743..4ed6ef1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.112324+1308 +version: 1.1.112324+1559 environment: sdk: ">=3.1.4 <4.0.0"