Skip to content

Commit

Permalink
Fixed some bugs regarding to the new setting implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed Apr 25, 2023
1 parent 08b779e commit d5f064f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public async Task<MusixMatchToken> GetToken()
return null;

MusixMatchToken token = tokens[new Random().Next(0, tokens.Count)];

Core.INSTANCE.SettingsHandler.Settings<TokenSection>()?.RemoveUsage(token);
token.Usage--;

if (token.Usage <= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private async Task RefreshToken()
await this._refreshTokenSuspensionToken.WaitForRelease();
await Task.Delay(1000);

if (IsConnected())
if (!IsConnected())
continue;

long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
Expand Down
23 changes: 23 additions & 0 deletions OpenLyricsClient/Backend/Settings/Sections/Tokens/TokenSection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using DevBase.Api.Serializer;
Expand Down Expand Up @@ -63,6 +64,28 @@ public async Task RemoveToken(MusixMatchToken token)

await SetValue("Tokens", tokens);
}

public async Task RemoveUsage(MusixMatchToken token)
{
List<MusixMatchToken> tokens = GetValue<List<MusixMatchToken>>("Tokens");

for (int i = 0; i < tokens.Capacity; i++)
{
MusixMatchToken currentToken = tokens[i];
if (currentToken.Token.SequenceEqual(token.Token))
{
MusixMatchToken newToken = new MusixMatchToken
{
Token = currentToken.Token,
ExpirationDate = currentToken.ExpirationDate,
Usage = (short)(currentToken.Usage - 1)
};

await RemoveToken(token);
await AddToken(newToken);
}
}
}

public T GetValue<T>(string field)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenLyricsClient/Frontend/Models/Elements/NoteAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public override void Render(DrawingContext context)
{
double realSize = (this.GetBounds("").Width * 3) + (3 * 8) + 8;

if (Core.INSTANCE.SettingsHandler.Settings<SpotifySection>()?.GetValue<EnumLyricsDisplayMode>("Selection Mode") == EnumLyricsDisplayMode.FADE)
if (Core.INSTANCE.SettingsHandler.Settings<LyricsSection>()?.GetValue<EnumLyricsDisplayMode>("Selection Mode") == EnumLyricsDisplayMode.FADE)
{
this._viewbox.IsVisible = false;
this._border.Width = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public string Artists

public bool AiBadge
{
get => Core.INSTANCE?.SongHandler?.CurrentSong?.Lyrics?.LyricProvider.SequenceEqual("OpenLyricsClient") == true;
get => Core.INSTANCE?.SongHandler?.CurrentSong?.Lyrics?.LyricProvider?.SequenceEqual("OpenLyricsClient") == true;
}

public string Artists
Expand Down

0 comments on commit d5f064f

Please sign in to comment.