From c512934ba2ae346051dabbb4d0d943d0fd4b35cc Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sun, 10 Mar 2024 16:38:09 +0100 Subject: [PATCH] Fix some shutdown logic --- AutoShutdown/AutoShutdown.csproj | 2 +- AutoShutdown/Plogon.cs | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/AutoShutdown/AutoShutdown.csproj b/AutoShutdown/AutoShutdown.csproj index 72fadbb..dfffaf5 100644 --- a/AutoShutdown/AutoShutdown.csproj +++ b/AutoShutdown/AutoShutdown.csproj @@ -57,7 +57,7 @@ - + diff --git a/AutoShutdown/Plogon.cs b/AutoShutdown/Plogon.cs index efdacee..0effa1c 100644 --- a/AutoShutdown/Plogon.cs +++ b/AutoShutdown/Plogon.cs @@ -1,9 +1,12 @@ using System; +using System.Diagnostics; using System.Reflection; +using System.Windows.Forms; using AutoRetainerAPI; using Dalamud.Plugin; using Dalamud.Plugin.Services; using ECommons; +using FFXIVClientStructs.FFXIV.Client.System.Framework; using LLib; namespace AutoShutdown; @@ -15,7 +18,8 @@ public class Plogon : IDalamudPlugin private readonly IPluginLog _pluginLog; private readonly IClientState _clientState; - public Plogon(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog, IClientState clientState) + public Plogon(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog, + IClientState clientState) { ECommonsMain.Init(pluginInterface, this); _autoRetainerApi = new AutoRetainerApi(); @@ -23,13 +27,13 @@ public class Plogon : IDalamudPlugin _pluginLog = pluginLog; _clientState = clientState; - _clientState.Login += SetupShutdown; + _clientState.Logout += SetupShutdown; - framework.RunOnTick(SetupShutdown, TimeSpan.FromSeconds(5)); + framework.RunOnTick(() => SetupShutdown(), TimeSpan.FromSeconds(10)); } private long StartedAt { get; } = Environment.TickCount64; - private long ShutdownAt => StartedAt + TimeSpan.FromDays(2).Ticks; + private long ShutdownAt => StartedAt + (long)TimeSpan.FromDays(2).TotalMilliseconds; private void SetupShutdown() { @@ -43,20 +47,25 @@ public class Plogon : IDalamudPlugin var currentShutdownAt = (long?)shutdownAt.GetValue(null) ?? 0; if (currentShutdownAt == 0) { - _pluginLog.Information($"Setting shutdown date to {new DateTime(ShutdownAt)}"); + _pluginLog.Information( + $"Setting shutdown date to {new DateTime(TimeSpan.FromMilliseconds(ShutdownAt).Ticks)}"); shutdownAt.SetValue(null, ShutdownAt); - forceShutdownAt.SetValue(null, ShutdownAt + TimeSpan.FromMinutes(10).Ticks); + forceShutdownAt.SetValue(null, ShutdownAt + (long)TimeSpan.FromMinutes(10).TotalMilliseconds); } else { - _pluginLog.Information($"Shutdown is already set to {new DateTime(currentShutdownAt)}"); + _pluginLog.Information( + $"Shutdown is already set to {new DateTime(TimeSpan.FromMilliseconds(currentShutdownAt).Ticks)}"); } } + + // move to background using alt+esc + SendKeys.SendWait("%({esc})"); } public void Dispose() { - _clientState.Login -= SetupShutdown; + _clientState.Logout -= SetupShutdown; _reflector.Dispose(); _autoRetainerApi.Dispose(); ECommonsMain.Dispose();