Fix some shutdown logic
This commit is contained in:
parent
3c7e5fe8c9
commit
c512934ba2
@ -57,7 +57,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoRetainerAPI\AutoRetainerAPI\AutoRetainerAPI.csproj"/>
|
||||
<ProjectReference Include="..\ECommons\ECommons\ECommons.csproj"/>
|
||||
<ProjectReference Include="..\LLib\LLib.csproj" />
|
||||
<ProjectReference Include="..\LLib\LLib.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="RenameLatestZip" AfterTargets="PackagePlugin" Condition="'$(Configuration)' == 'Release'">
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user