Compare commits

...

2 commits

Author SHA1 Message Date
erik
a13d30f0b2 feat: auto-check for updates 30s after startup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 13:13:35 +00:00
erik
57a6946e6b feat: add CheckAndInstallAsync convenience method to UpdateManager
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 13:11:27 +00:00
3 changed files with 45 additions and 0 deletions

View file

@ -66,6 +66,7 @@ namespace MosswartMassacre
private static Timer vitalsTimer;
private static System.Windows.Forms.Timer commandTimer;
private static Timer characterStatsTimer;
private static Timer _updateCheckTimer;
private static readonly Queue<string> pendingCommands = new Queue<string>();
private static RareTracker _staticRareTracker;
public static bool RareMetaEnabled
@ -198,6 +199,12 @@ namespace MosswartMassacre
commandTimer.Dispose();
commandTimer = null;
}
if (_updateCheckTimer != null)
{
_updateCheckTimer.Stop();
_updateCheckTimer.Dispose();
_updateCheckTimer = null;
}
// Initialize kill tracker (owns the 1-sec stats timer)
_killTracker = new KillTracker(
@ -296,6 +303,17 @@ namespace MosswartMassacre
}
}
// Auto-update: check for updates 30s after startup
_updateCheckTimer = new Timer(30000);
_updateCheckTimer.AutoReset = false;
_updateCheckTimer.Elapsed += (s, ev) =>
{
Task.Run(() => UpdateManager.CheckAndInstallAsync());
_updateCheckTimer?.Dispose();
_updateCheckTimer = null;
};
_updateCheckTimer.Start();
}
catch (Exception ex)
{
@ -361,6 +379,13 @@ namespace MosswartMassacre
characterStatsTimer = null;
}
if (_updateCheckTimer != null)
{
_updateCheckTimer.Stop();
_updateCheckTimer.Dispose();
_updateCheckTimer = null;
}
// Dispose quest manager
if (questManager != null)
{

View file

@ -206,6 +206,26 @@ namespace MosswartMassacre
}
}
/// <summary>
/// Check for update and auto-install if available. Used by startup auto-update.
/// </summary>
public static async Task CheckAndInstallAsync()
{
try
{
bool checkOk = await CheckForUpdateAsync();
if (checkOk && updateAvailable)
{
PluginCore.WriteToChat("[Update] Auto-installing update...");
await DownloadAndInstallUpdateAsync();
}
}
catch (Exception ex)
{
PluginCore.WriteToChat($"[Update] Auto-update failed: {ex.Message}");
}
}
private static string GetLocalDllPath()
{
// Get the path to the current DLL