fix: allow configurable refresh frequency

This commit is contained in:
Anna 2023-11-25 12:33:35 -05:00
parent 0c52c1a41a
commit 16d0082248
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 22 additions and 3 deletions

View File

@ -4,12 +4,16 @@ namespace EorzeaVotes.Config;
[Serializable]
internal class Configuration : IPluginConfiguration {
internal const int MinFreq = 60;
internal const int MaxFreq = 3_600;
public int Version { get; set; } = 1;
public string? UserId;
public string? ApiKey;
public bool OpenWhenNew = true;
public int CheckFrequency = 300;
public bool OnBoarded;
public Gender? Gender = null;

View File

@ -53,7 +53,7 @@ public class Plugin : IDalamudPlugin {
private Commands Commands { get; }
private bool _checkNow = true;
private int _checkSeconds = 300;
private int _checkSeconds;
private Stopwatch Stopwatch { get; } = Stopwatch.StartNew();
public Plugin() {
@ -91,12 +91,15 @@ public class Plugin : IDalamudPlugin {
return;
}
if (!this._checkNow && this.Stopwatch.Elapsed < TimeSpan.FromSeconds(this._checkSeconds)) {
var wait = this._checkSeconds > 0
? this._checkSeconds
: Math.Clamp(this.Config.CheckFrequency, Configuration.MinFreq, Configuration.MaxFreq);
if (!this._checkNow && this.Stopwatch.Elapsed < TimeSpan.FromSeconds(wait)) {
return;
}
this._checkNow = false;
this._checkSeconds = 300;
this._checkSeconds = 0;
this.Stopwatch.Restart();
var safeToOpen = !this.DutyState.IsDutyStarted

View File

@ -1,4 +1,5 @@
using Dalamud.Interface.Utility;
using EorzeaVotes.Config;
using EorzeaVotes.Utilities;
using ImGuiNET;
@ -27,6 +28,17 @@ internal class SettingsTab {
ImGui.TextUnformatted("The window will not open until you are not busy in most cases (not in combat, not in instance, etc.).");
}
anyChanged |= ImGuiHelper.VerticalInput(
"Check for new questions every",
label => ImGui.SliderInt(
label,
ref this.Plugin.Config.CheckFrequency,
Configuration.MinFreq,
Configuration.MaxFreq,
"%i second(s)"
)
);
ImGuiHelpers.CenteredText("Optional questions");
ImGui.Spacing();