From ff107016f75e72270be0e47a8cc211c3289fd7f9 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Fri, 4 Feb 2022 23:31:36 -0500 Subject: [PATCH] fix: defer saving config --- ChatTwo/Plugin.cs | 11 +++++++---- ChatTwo/Ui/Settings.cs | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChatTwo/Plugin.cs b/ChatTwo/Plugin.cs index 0ff6280..5c05e58 100755 --- a/ChatTwo/Plugin.cs +++ b/ChatTwo/Plugin.cs @@ -52,9 +52,6 @@ public sealed class Plugin : IDalamudPlugin { [PluginService] internal PartyList PartyList { get; init; } - [PluginService] - internal SigScanner SigScanner { get; init; } - [PluginService] internal TargetManager TargetManager { get; init; } @@ -65,11 +62,13 @@ public sealed class Plugin : IDalamudPlugin { internal Store Store { get; } internal PluginUi Ui { get; } + internal int DeferredSaveFrames = -1; + #pragma warning disable CS8618 public Plugin() { LanguageChanged(this.Interface!.UiLanguage); - this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); + this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration(); this.Config.Migrate(); this.Common = new XivCommonBase(); this.TextureCache = new TextureCache(this.DataManager!); @@ -111,6 +110,10 @@ public sealed class Plugin : IDalamudPlugin { }; private void FrameworkUpdate(Framework framework) { + if (this.DeferredSaveFrames >= 0 && this.DeferredSaveFrames-- == 0) { + this.SaveConfig(); + } + if (!this.Config.HideChat) { return; } diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index 08f47e2..caae27c 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -129,7 +129,9 @@ internal sealed class Settings : IUiComponent { config.UpdateFrom(this.Mutable); - this.Ui.Plugin.SaveConfig(); + // save after 60 frames have passed, which should hopefully not + // commit any changes that cause a crash + this.Ui.Plugin.DeferredSaveFrames = 60; this.Ui.Plugin.Store.FilterAllTabs(false);