From 94232564d4d063886f33fbb029d8e9f2cef6276d Mon Sep 17 00:00:00 2001 From: AlexanderDotH Date: Thu, 27 Apr 2023 20:39:34 +0200 Subject: [PATCH] Fixed a bug --- .../Backend/Settings/ISettingSection.cs | 1 + .../Settings/Sections/Account/AccountSection.cs | 12 ++++++++++++ .../Connection/Spotify/SpotifySection.cs | 11 +++++++++++ .../Settings/Sections/Lyrics/LyricsSection.cs | 10 ++++++++++ .../Romanization/RomanizationSection.cs | 10 ++++++++++ .../Settings/Sections/Tokens/TokenSection.cs | 10 ++++++++++ .../Backend/Settings/SettingsHandler.cs | 17 ++++++++--------- 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/OpenLyricsClient/Backend/Settings/ISettingSection.cs b/OpenLyricsClient/Backend/Settings/ISettingSection.cs index 7fb9a40..908ab9b 100644 --- a/OpenLyricsClient/Backend/Settings/ISettingSection.cs +++ b/OpenLyricsClient/Backend/Settings/ISettingSection.cs @@ -10,4 +10,5 @@ public interface ISettingSection T GetValue(string field); Task SetValue(string field, T value); JObject Defaults(); + string[] GetFields(); } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/Sections/Account/AccountSection.cs b/OpenLyricsClient/Backend/Settings/Sections/Account/AccountSection.cs index 1dcb992..e67a324 100644 --- a/OpenLyricsClient/Backend/Settings/Sections/Account/AccountSection.cs +++ b/OpenLyricsClient/Backend/Settings/Sections/Account/AccountSection.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using DevBase.Api.Apis.OpenLyricsClient.Structure.Json; +using DevBase.Generics; using Newtonsoft.Json.Linq; using OpenLyricsClient.Backend; using OpenLyricsClient.Backend.Settings; @@ -76,4 +78,14 @@ public JObject Defaults() return new JsonDeserializer().Serialize(structure); } + + public string[] GetFields() + { + AList fields = new AList(); + + foreach (var pair in this._data) + fields.Add(pair.Key); + + return fields.GetAsArray(); + } } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs b/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs index b15f93e..16bb1d7 100644 --- a/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs +++ b/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using DevBase.Generics; using Newtonsoft.Json.Linq; using OpenLyricsClient.Backend.Structure; using OpenLyricsClient.Backend.Structure.Enum; @@ -96,4 +97,14 @@ public JObject Defaults() return new JsonDeserializer().Serialize(spotifyAccess); } + + public string[] GetFields() + { + AList fields = new AList(); + + foreach (var pair in this._data) + fields.Add(pair.Key); + + return fields.GetAsArray(); + } } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/Sections/Lyrics/LyricsSection.cs b/OpenLyricsClient/Backend/Settings/Sections/Lyrics/LyricsSection.cs index 8b7f890..c734d2f 100644 --- a/OpenLyricsClient/Backend/Settings/Sections/Lyrics/LyricsSection.cs +++ b/OpenLyricsClient/Backend/Settings/Sections/Lyrics/LyricsSection.cs @@ -68,4 +68,14 @@ public JObject Defaults() return new JsonDeserializer().Serialize(structure); } + + public string[] GetFields() + { + AList fields = new AList(); + + foreach (var pair in this._data) + fields.Add(pair.Key); + + return fields.GetAsArray(); + } } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/Sections/Romanization/RomanizationSection.cs b/OpenLyricsClient/Backend/Settings/Sections/Romanization/RomanizationSection.cs index bd34028..ea6fc9a 100644 --- a/OpenLyricsClient/Backend/Settings/Sections/Romanization/RomanizationSection.cs +++ b/OpenLyricsClient/Backend/Settings/Sections/Romanization/RomanizationSection.cs @@ -97,4 +97,14 @@ public JObject Defaults() return new JsonDeserializer().Serialize(structure); } + + public string[] GetFields() + { + AList fields = new AList(); + + foreach (var pair in this._data) + fields.Add(pair.Key); + + return fields.GetAsArray(); + } } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/Sections/Tokens/TokenSection.cs b/OpenLyricsClient/Backend/Settings/Sections/Tokens/TokenSection.cs index bb0445e..720d207 100644 --- a/OpenLyricsClient/Backend/Settings/Sections/Tokens/TokenSection.cs +++ b/OpenLyricsClient/Backend/Settings/Sections/Tokens/TokenSection.cs @@ -104,4 +104,14 @@ public JObject Defaults() return new JsonDeserializer().Serialize(structure); } + + public string[] GetFields() + { + AList fields = new AList(); + + foreach (var pair in this._data) + fields.Add(pair.Key); + + return fields.GetAsArray(); + } } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/SettingsHandler.cs b/OpenLyricsClient/Backend/Settings/SettingsHandler.cs index f8a028e..3cda66b 100644 --- a/OpenLyricsClient/Backend/Settings/SettingsHandler.cs +++ b/OpenLyricsClient/Backend/Settings/SettingsHandler.cs @@ -67,15 +67,14 @@ await Dispatcher.UIThread.InvokeAsync(() => public async Task TriggerGlobal() { - this._sections.ForEach(s => + for (int i = 0; i < this._sections.Length; i++) { - using (var enumerator = s.Defaults().GetEnumerator()) - { - while (enumerator.MoveNext()) - { - TriggerEvent(s, enumerator.Current.Key.ToString()); - } - } - }); + ISettingSection section = this._sections.Get(i); + + string[] fields = section.GetFields(); + + for (int j = 0; j < fields.Length; j++) + await TriggerEvent(section, fields[j]); + } } } \ No newline at end of file