diff --git a/OpenLyricsClient/Backend/Collector/Token/Provider/Musixmatch/MusixmatchTokenCollector.cs b/OpenLyricsClient/Backend/Collector/Token/Provider/Musixmatch/MusixmatchTokenCollector.cs index 8f2d219..4fb10ec 100644 --- a/OpenLyricsClient/Backend/Collector/Token/Provider/Musixmatch/MusixmatchTokenCollector.cs +++ b/OpenLyricsClient/Backend/Collector/Token/Provider/Musixmatch/MusixmatchTokenCollector.cs @@ -34,7 +34,9 @@ public async Task CollectToken() { bool settingsChanged = false; - try + return; + + /*try { if (!DataValidator.ValidateData(Core.INSTANCE.SettingManager.Settings.MusixMatchToken)) return; @@ -75,12 +77,12 @@ public async Task CollectToken() } if (settingsChanged) - Core.INSTANCE.SettingManager.WriteSettings(false); + Core.INSTANCE.SettingManager.WriteSettings(false);*/ } public MusixMatchToken GetToken() { - List tokens = Core.INSTANCE.SettingManager.Settings.MusixMatchToken; + /*List tokens = Core.INSTANCE.SettingManager.Settings.MusixMatchToken; if (tokens.Count == 0) return null; @@ -91,9 +93,9 @@ public MusixMatchToken GetToken() if (token.Usage <= 0) { Core.INSTANCE.SettingManager.Settings.MusixMatchToken.Remove(token); - } + }*/ - return token; + return null; } } } diff --git a/OpenLyricsClient/Backend/Core.cs b/OpenLyricsClient/Backend/Core.cs index 898831c..cc07965 100644 --- a/OpenLyricsClient/Backend/Core.cs +++ b/OpenLyricsClient/Backend/Core.cs @@ -14,6 +14,7 @@ using OpenLyricsClient.Backend.Handler.Song; using OpenLyricsClient.Backend.Helper; using OpenLyricsClient.Backend.Settings; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; using TaskRegister = OpenLyricsClient.Backend.Overwrite.TaskRegister; @@ -106,6 +107,8 @@ public Core() this._songHandler = songHandler; _loaded = true; + + SettingsHandler.TriggerGlobal(); } private async Task TickTask() diff --git a/OpenLyricsClient/Backend/Events/EventArgs/SettingsChangedEventArgs.cs b/OpenLyricsClient/Backend/Events/EventArgs/SettingsChangedEventArgs.cs index e131b4a..b1544f9 100644 --- a/OpenLyricsClient/Backend/Events/EventArgs/SettingsChangedEventArgs.cs +++ b/OpenLyricsClient/Backend/Events/EventArgs/SettingsChangedEventArgs.cs @@ -4,16 +4,18 @@ namespace OpenLyricsClient.Backend.Events.EventArgs; public class SettingsChangedEventArgs : System.EventArgs { - private Settings.Settings _settings; + private Object _section; + private string _field; - public SettingsChangedEventArgs(Settings.Settings settings) + public Object Section { - _settings = settings; + get => _section; + set => _section = value; } - public Settings.Settings Settings + public string Field { - get => _settings; - set => _settings = value; + get => _field; + set => _field = value; } } \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Handler/Services/ServiceHandler.cs b/OpenLyricsClient/Backend/Handler/Services/ServiceHandler.cs index b047797..5da6362 100644 --- a/OpenLyricsClient/Backend/Handler/Services/ServiceHandler.cs +++ b/OpenLyricsClient/Backend/Handler/Services/ServiceHandler.cs @@ -4,7 +4,6 @@ using OpenLyricsClient.Backend.Debugger; using OpenLyricsClient.Backend.Handler.Services.Services; using OpenLyricsClient.Backend.Handler.Services.Services.Spotify; -using OpenLyricsClient.Backend.Handler.Services.Services.Tidal; using OpenLyricsClient.Backend.Utils; namespace OpenLyricsClient.Backend.Handler.Services diff --git a/OpenLyricsClient/Backend/Handler/Services/Services/Spotify/SpotifyService.cs b/OpenLyricsClient/Backend/Handler/Services/Services/Spotify/SpotifyService.cs index 372cbf8..7f21c36 100644 --- a/OpenLyricsClient/Backend/Handler/Services/Services/Spotify/SpotifyService.cs +++ b/OpenLyricsClient/Backend/Handler/Services/Services/Spotify/SpotifyService.cs @@ -8,6 +8,7 @@ using DevBase.Generics; using Microsoft.Extensions.Configuration; using OpenLyricsClient.Backend.Debugger; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Other; using OpenLyricsClient.Backend.Utils; @@ -47,26 +48,25 @@ private async Task RefreshToken() await this._refreshTokenSuspensionToken.WaitForRelease(); await Task.Delay(1000); - if (Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected) - { - if (Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken != null) - { - long now = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - long settings = Core.INSTANCE.SettingManager.Settings.SpotifyAccess.SpotifyExpireTime; + if (IsConnected()) + continue; + + long now = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + long settings = Core.INSTANCE.SettingsHandler.Settings() + .GetValue("SpotifyExpireTime"); - if (now > settings) - { - await RefreshTokenRequest(); - this._debugger.Write("Refreshed Spotify Token", DebugType.DEBUG); - } - } + if (now > settings) + { + await RefreshTokenRequest(); + this._debugger.Write("Refreshed Spotify Token", DebugType.DEBUG); } } } public bool IsConnected() { - return Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected && Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken != null; + return Core.INSTANCE.SettingsHandler.Settings().GetValue("IsSpotifyConnected") + && Core.INSTANCE.SettingsHandler.Settings().GetValue("AccessToken") != null; } public async Task TestConnection() @@ -74,7 +74,7 @@ public async Task TestConnection() if (!IsConnected()) return false; - if (!DataValidator.ValidateData(Core.INSTANCE.SettingManager.Settings.SpotifyAccess)) + if (!DataValidator.ValidateData(GetAccessToken())) return false; try @@ -149,7 +149,7 @@ public string GetAccessToken() // await RefreshTokenRequest(); // // }).Wait(Core.INSTANCE.CancellationTokenSource.Token); - return Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken; + return Core.INSTANCE.SettingsHandler.Settings().GetValue("AccessToken"); } private async Task RefreshTokenRequest() @@ -160,15 +160,22 @@ private async Task RefreshTokenRequest() new DevBase.Api.Apis.OpenLyricsClient.OpenLyricsClient(); JsonOpenLyricsClientAccess access = - await api.GetAccessToken(Core.INSTANCE.SettingManager.Settings.SpotifyAccess.RefreshToken); - + await api.GetAccessToken(Core.INSTANCE.SettingsHandler.Settings().GetValue("RefreshToken")); + SpotifyStatistics statistics = await GetStatistics(access.AccessToken); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("Statistics", statistics); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("AccessToken", access.AccessToken); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("SpotifyExpireTime", DateTimeOffset.Now.AddHours(1).ToUnixTimeMilliseconds()); - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.Statistics = statistics; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken = access.AccessToken; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.SpotifyExpireTime = - DateTimeOffset.Now.AddHours(1).ToUnixTimeMilliseconds(); - Core.INSTANCE.SettingManager.WriteSettings(); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "Statistics"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "AccessToken"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "SpotifyExpireTime"); } catch (Exception e) { @@ -208,52 +215,37 @@ public async Task StartAuthorization() if (!DataValidator.ValidateData(token)) return; - string t = token.RefreshToken; + String t = token.RefreshToken; if (token.RefreshToken.EndsWith("&")) t = token.RefreshToken.Substring(0, token.RefreshToken.Length - 1); SpotifyClient client = new SpotifyClient(token.AccessToken); - - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.UserData = await client.UserProfile.Current(); - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.Statistics = - await this.GetStatistics(token.AccessToken); - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken = token.AccessToken; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.RefreshToken = t; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.SpotifyExpireTime = - DateTimeOffset.Now.AddHours(1).ToUnixTimeMilliseconds(); - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected = true; - Core.INSTANCE.SettingManager.WriteSettings(); + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("UserData", await client.UserProfile.Current()); - /* - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - ProcessStartInfo processStartInfo = new ProcessStartInfo(url); - processStartInfo.UseShellExecute = true; - Process.Start(processStartInfo); - } - - Listener.Listener l = new Listener.Listener("http://localhost:8080/", "/callback", "code"); - - string token = string.Empty; - bool running = false; - while (!l.Finished && !running) - { - if (l.Response != null) - { - token = l.Response; - running = true; - } - } - - - /*BearerAccessRefreshToken bearerAccessRefresh = await _userAccountsService.RequestAccessRefreshToken(token); - - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.RefreshToken = bearerAccessRefresh.RefreshToken; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.BearerAccess = bearerAccessRefresh; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected = true; - Core.INSTANCE.SettingManager.WriteSettings();*/ + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("Statistics", await this.GetStatistics(token.AccessToken)); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("AccessToken", token.AccessToken); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("RefreshToken", t); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("SpotifyExpireTime", DateTimeOffset.Now.AddHours(1).ToUnixTimeMilliseconds()); + + Core.INSTANCE.SettingsHandler.Settings() + .SetValue("IsSpotifyConnected", true); + + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "UserData"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "Statistics"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "AccessToken"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "RefreshToken"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "SpotifyExpireTime"); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "IsSpotifyConnected"); } string IService.ServiceName() diff --git a/OpenLyricsClient/Backend/Handler/Services/Services/Tidal/TidalService.cs b/OpenLyricsClient/Backend/Handler/Services/Services/Tidal/TidalService.cs deleted file mode 100644 index 57ff6d5..0000000 --- a/OpenLyricsClient/Backend/Handler/Services/Services/Tidal/TidalService.cs +++ /dev/null @@ -1,167 +0,0 @@ -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using DevBase.Api.Apis.Tidal; -using DevBase.Api.Apis.Tidal.Structure.Json; -using DevBase.Async.Task; -using OpenLyricsClient.Backend.Debugger; -using OpenLyricsClient.Backend.Structure; -using OpenLyricsClient.Backend.Structure.Enum; -using OpenLyricsClient.Backend.Utils; - -namespace OpenLyricsClient.Backend.Handler.Services.Services.Tidal -{ - public class TidalService : IService - { - - private bool _disposed; - - private Debugger _debugger; - - private TaskSuspensionToken _refreshTokenSuspensionToken; - - private TidalAccess _tidalAccess; - private TidalClient _tidalClient; - - public TidalService() - { - this._debugger = new Debugger(this); - - this._disposed = false; - - this._tidalClient = new TidalClient(); - - Core.INSTANCE.TaskRegister.Register( - out _refreshTokenSuspensionToken, - new Task(async () => await RefreshToken(), Core.INSTANCE.CancellationTokenSource.Token, TaskCreationOptions.None), - EnumRegisterTypes.TIDAL_REFRESHTOKEN); - } - - private async Task RefreshToken() - { - while (!this._disposed) - { - await this._refreshTokenSuspensionToken.WaitForRelease(); - await Task.Delay(2000); - - if (Core.INSTANCE.SettingManager.Settings.TidalAccess.IsTidalConnected) - { - if (DataValidator.ValidateData(Core.INSTANCE.SettingManager.Settings.TidalAccess)) - { - long savedTime = Core.INSTANCE.SettingManager.Settings.TidalAccess.ExpirationDate; - long currentTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - - if (currentTime > savedTime) - { - JsonTidalAccountRefreshAccess refresh = - await this._tidalClient.RefreshToken(Core.INSTANCE.SettingManager.Settings.TidalAccess.RefreshToken); - - if (!DataValidator.ValidateData(refresh)) - continue; - - Core.INSTANCE.SettingManager.Settings.TidalAccess.AccessToken = refresh.AccessToken; - Core.INSTANCE.SettingManager.Settings.TidalAccess.ExpirationDate = DateTimeOffset.Now.Add(TimeSpan.FromSeconds(refresh.ExpiresIn)) - .ToUnixTimeMilliseconds(); ; - Core.INSTANCE.SettingManager.WriteSettings(); - - this._debugger.Write("Refreshed Tidal!", DebugType.INFO); - } - } - } - } - } - - public async Task StartAuthorization() - { - JsonTidalAuthDevice authDevice = await this._tidalClient.RegisterDevice(); - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - ProcessStartInfo processStartInfo = new ProcessStartInfo("https://" + authDevice.VerificationUriComplete); - processStartInfo.UseShellExecute = true; - Process.Start(processStartInfo); - } - - DateTimeOffset expires = DateTimeOffset.Now.Add(TimeSpan.FromSeconds(authDevice.ExpiresIn)); - bool authorized = false; - - while (!authorized) - { - await Task.Delay(authDevice.Interval * 1000); - - if (DateTimeOffset.Now > expires) - { - //Give user some feedback - return; - } - - JsonTidalAccountAccess accountAccess = await this._tidalClient.GetTokenFrom(authDevice); - - if (accountAccess == null) - continue; - - TidalAccess access = new TidalAccess(); - access.AccessToken = accountAccess.AccessToken; - access.RefreshToken = accountAccess.RefreshToken; - access.ExpirationDate = DateTimeOffset.Now.Add(TimeSpan.FromSeconds(accountAccess.ExpiresIn)) - .ToUnixTimeMilliseconds(); - access.IsTidalConnected = true; - access.UserID = accountAccess.User.UserId; - - Core.INSTANCE.SettingManager.Settings.TidalAccess = access; - Core.INSTANCE.SettingManager.WriteSettings(); - - authorized = true; - } - } - - public string GetAccessToken() - { - return Core.INSTANCE.SettingManager.Settings.TidalAccess.AccessToken; - } - - public bool IsConnected() - { - return Core.INSTANCE.SettingManager.Settings.TidalAccess != null && Core.INSTANCE.SettingManager.Settings.TidalAccess.IsTidalConnected; - } - - public async Task TestConnection() - { - if (!IsConnected()) - return false; - - JsonTidalSession session = - await this._tidalClient.Login(Core.INSTANCE.SettingManager.Settings.TidalAccess.AccessToken); - - if (!DataValidator.ValidateData(session)) - return false; - - JsonTidalSearchResult result = await this._tidalClient.Search(session, "Never gonna give you up"); - - return DataValidator.ValidateData(result); - } - - public string ServiceName() - { - return "Tidal"; - } - - public string ProcessName() - { - return "TIDAL"; - } - - public TidalClient TidalClient - { - get => _tidalClient; - } - - public void Dispose() - { - this._disposed = true; - - Core.INSTANCE.TaskRegister.Kill(EnumRegisterTypes.TIDAL_REFRESHTOKEN); - } - } -} diff --git a/OpenLyricsClient/Backend/Handler/Song/SongHandler.cs b/OpenLyricsClient/Backend/Handler/Song/SongHandler.cs index f524b9c..8896f0d 100644 --- a/OpenLyricsClient/Backend/Handler/Song/SongHandler.cs +++ b/OpenLyricsClient/Backend/Handler/Song/SongHandler.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices.ComTypes; using System.Threading.Tasks; using Avalonia.Threading; using DevBase.Async.Task; @@ -13,7 +12,6 @@ using OpenLyricsClient.Backend.Handler.Lyrics; using OpenLyricsClient.Backend.Handler.Song.SongProvider; using OpenLyricsClient.Backend.Handler.Song.SongProvider.Spotify; -using OpenLyricsClient.Backend.Handler.Song.SongProvider.Tidal; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Song; using OpenLyricsClient.Backend.Utils; diff --git a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Spotify/SpotifySongProvider.cs b/OpenLyricsClient/Backend/Handler/Song/SongProvider/Spotify/SpotifySongProvider.cs index 71b8cde..004df2c 100644 --- a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Spotify/SpotifySongProvider.cs +++ b/OpenLyricsClient/Backend/Handler/Song/SongProvider/Spotify/SpotifySongProvider.cs @@ -30,8 +30,6 @@ public SpotifySongProvider() this._debugger = new Debugger(this); this._disposed = false; - this._spotifyClient = new SpotifyClient(Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken); - this._service = Core.INSTANCE.ServiceHandler.GetServiceByName("Spotify"); Core.INSTANCE.TaskRegister.Register( @@ -174,14 +172,7 @@ private async Task UpdateSongDataTask() private SpotifyClient GetPlayerApi() { - if (this._accessToken != Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken) - { - this._spotifyClient = - new SpotifyClient(Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken); - this._accessToken = Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken; - } - - return this._spotifyClient; + return new SpotifyClient(Core.INSTANCE.ServiceHandler.GetServiceByName("Spotify").GetAccessToken()); } public void Dispose() diff --git a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalDataMerger.cs b/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalDataMerger.cs deleted file mode 100644 index 29ca220..0000000 --- a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalDataMerger.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using DevBase.Api.Apis.Tidal.Structure.Json; -using OpenLyricsClient.Backend.Structure.Enum; -using OpenLyricsClient.Backend.Structure.Song; -using OpenLyricsClient.Backend.Utils; - -namespace OpenLyricsClient.Backend.Handler.Song.SongProvider.Tidal -{ - public class TidalDataMerger - { - public static Structure.Song.Song ValidateUpdatePlayBack(Structure.Song.Song song, JsonTidalTrack track) - { - if (!DataValidator.ValidateData(song)) - return song; - - if (!DataValidator.ValidateData(song.SongMetadata.Name, song.SongMetadata.Album, song.SongMetadata.Artists)) - return song; - - if (!DataValidator.ValidateData(track)) - return song; - - if (!DataValidator.ValidateData(track.Title, track.Album, track.Artists)) - return song; - - return UpdatePlayBack(song, track); - } - - public static Structure.Song.Song UpdatePlayBack(Structure.Song.Song song, JsonTidalTrack track) - { - song.SongMetadata = SongMetadata.ToSongMetadata( - track.Title, - track.Album.Title, - DataConverter.TidalArtistsToString(track.Artists), - TimeSpan.FromSeconds(track.Duration).Milliseconds); - - return song; - } - - public static Structure.Song.Song ValidateConvertAndMerge(JsonTidalTrack track) - { - if (!DataValidator.ValidateData(track)) - return null; - - if (!DataValidator.ValidateData(track.Title, track.Artists, track.Duration, track.Album)) - return null; - - return ConvertAndMerge(track); - } - - public static Structure.Song.Song ConvertAndMerge(JsonTidalTrack track) - { - Structure.Song.Song song = new Structure.Song.Song( - DataOrigin.TIDAL, - track, - track.Title, - track.Album.Title, - DataConverter.TidalArtistsToString(track.Artists), - TimeSpan.FromSeconds(track.Duration).Milliseconds); - song.ProgressMs = 0; - song.Time = -1; - song.TimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - song.Lyrics = null; - song.CurrentLyricPart = null; - song.State = SongState.SEARCHING_LYRICS; - return song; - } - } -} diff --git a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalProgressListener.cs b/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalProgressListener.cs deleted file mode 100644 index 9ba55eb..0000000 --- a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalProgressListener.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System.Diagnostics; -using System.Threading; -using System.Threading.Tasks; -using DevBase.Async.Task; -using OpenLyricsClient.Backend.Debugger; -using OpenLyricsClient.Backend.Structure.Enum; -using OpenLyricsClient.Backend.Utils; -using Squalr.Engine.DataTypes; -using Squalr.Engine.OS; -using Squalr.Engine.Scanning.Scanners; -using Squalr.Engine.Scanning.Scanners.Constraints; -using Squalr.Engine.Scanning.Snapshots; -using Squalr.Engine.Snapshots; - -namespace OpenLyricsClient.Backend.Handler.Song.SongProvider.Tidal -{ - public class TidalProgressListener - { - private Process _process; - private ulong? _progressAddress; - - private Stopwatch _progressTime; - - private TaskSuspensionToken _findAddressSuspensionToken; - private bool _disposed; - - private Debugger _debugger; - - private int _retryTimes; - private CancellationTokenSource _tokenSource; - - public TidalProgressListener() - { - this._debugger = new Debugger(this); - - this._progressTime = new Stopwatch(); - - this._disposed = false; - - this._retryTimes = 0; - - this._tokenSource = new CancellationTokenSource(); - - Core.INSTANCE.TaskRegister.Register( - out this._findAddressSuspensionToken, - new Task(async t => await Listener(), - Core.INSTANCE.CancellationTokenSource.Token), EnumRegisterTypes.TIDALPROGRESSLISTENER_FINDADDRESS); - } - - private async Task Listener() - { - while (!this._disposed) - { - await this._findAddressSuspensionToken.WaitForRelease(); - await Task.Delay(500); - - if (!DataValidator.ValidateData(this._process)) - { - this._process = TidalUtils.FindTidalProcess(); - continue; - } - - Process currentProcess = this._process; - Process tidalProcess = TidalUtils.FindTidalProcess(); - - if (currentProcess != tidalProcess) - { - this._process = tidalProcess; - await FindAddress(); - } else if (this._progressAddress == null || this._retryTimes == 0) - { - await FindAddress(); - } - } - } - - private async Task FindAddress() - { - if (!TidalUtils.IsTidalRunning()) - return; - - Process tidalProcess = TidalUtils.FindTidalProcess(); - - if (tidalProcess == null) - return; - - if (this._progressTime == null) - return; - - if (this._retryTimes > 8) - { - this._debugger.Write("Too many failed search attempts", DebugType.ERROR); - return; - } - - this._debugger.Write("Trying to find a new address", DebugType.DEBUG); - _retryTimes++; - - Processes.Default.OpenedProcess = tidalProcess; - - Snapshot snapshot = SnapshotManager.GetSnapshot(Snapshot.SnapshotRetrievalMode.FromSettings); - snapshot.ElementDataType = DataType.Double; - - ScanConstraintCollection scanConstraint = new ScanConstraintCollection(); - - double upper = (this._progressTime.ElapsedMilliseconds + 6875) / 1000D; - double lower = (this._progressTime.ElapsedMilliseconds - 1000) / 1000D; - - scanConstraint.AddConstraint(new ScanConstraint(ScanConstraint.ConstraintType.LessThanOrEqual, upper)); - scanConstraint.AddConstraint(new ScanConstraint(ScanConstraint.ConstraintType.GreaterThanOrEqual, lower)); - - snapshot = await ManualScanner.Scan(snapshot, DataType.Double, scanConstraint, null, out var scanCts); - - this._debugger.Write("Found " + snapshot.ElementCount + " Elements", DebugType.DEBUG); - - if (snapshot.ElementCount == 0) - { - this._debugger.Write("Address could not be found", DebugType.ERROR); - Stop(); - } - else if (snapshot.ElementCount <= 8) - { - this._progressAddress = snapshot[0].BaseAddress; - this._debugger.Write("Found address " + $"0x{this._progressAddress.Value:X}", DebugType.INFO); - } - } - - public void Start() - { - this._retryTimes = 0; - this._progressTime.Restart(); - } - - public void Stop() - { - this._retryTimes = 0; - this._progressTime.Stop(); - } - - public ulong? ProgressAddress - { - get => _progressAddress; - set => _progressAddress = value; - } - } -} diff --git a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalSongProvider.cs b/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalSongProvider.cs deleted file mode 100644 index 2613010..0000000 --- a/OpenLyricsClient/Backend/Handler/Song/SongProvider/Tidal/TidalSongProvider.cs +++ /dev/null @@ -1,261 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading.Tasks; -using DevBase.Api.Apis.Tidal; -using DevBase.Api.Apis.Tidal.Structure.Json; -using DevBase.Async.Task; -using DevBase.Generics; -using DevBase.Typography; -using OpenLyricsClient.Backend.Debugger; -using OpenLyricsClient.Backend.Handler.Services.Services; -using OpenLyricsClient.Backend.Structure; -using OpenLyricsClient.Backend.Structure.Enum; -using OpenLyricsClient.Backend.Utils; -using Squalr.Engine.Memory; - -namespace OpenLyricsClient.Backend.Handler.Song.SongProvider.Tidal -{ - class TidalSongProvider : ISongProvider - { - private Structure.Song.Song _currentSong; - private TidalProgressListener _tidalProgressListener; - - private IService _tidalService; - - private TaskSuspensionToken _loginTaskSuspensionToken; - private TaskSuspensionToken _updateCurrentTrackSuspensionToken; - private TaskSuspensionToken _updateTimeSuspensionToken; - - private bool _disposed; - - private Debugger _debugger; - - private long _startTime; - - private JsonTidalSession _session; - private TidalClient _tidalClient; - - private Process _tidalProcess; - - public TidalSongProvider() - { - this._debugger = new Debugger(this); - - this._disposed = false; - - this._tidalService = Core.INSTANCE.ServiceHandler.GetServiceByName("Tidal"); - this._tidalClient = new TidalClient(); - - this._tidalProgressListener = new TidalProgressListener(); - - this._startTime = 0; - - Core.INSTANCE.TaskRegister.Register( - out _loginTaskSuspensionToken, - new Task(async () => await LoginTask(), Core.INSTANCE.CancellationTokenSource.Token, TaskCreationOptions.LongRunning), - EnumRegisterTypes.TIDALSONGPROVIDER_LOGIN); - - Core.INSTANCE.TaskRegister.Register( - out _updateCurrentTrackSuspensionToken, - new Task(async () => await UpdateCurrentTrack(), Core.INSTANCE.CancellationTokenSource.Token, TaskCreationOptions.LongRunning), - EnumRegisterTypes.TIDALSONGPROVIDER_UPDATECURRENTTRACK); - - Core.INSTANCE.TaskRegister.Register( - out this._updateTimeSuspensionToken, - new Task(async () => await UpdateTimeTask(), Core.INSTANCE.CancellationTokenSource.Token, TaskCreationOptions.LongRunning), - EnumRegisterTypes.TIDALSONGPROVIDER_UPDATETIME); - } - - private async Task UpdateTimeTask() - { - while (!this._disposed) - { - await this._updateTimeSuspensionToken.WaitForRelease(); - - await Task.Delay(100); - - if (!DataValidator.ValidateData(this._currentSong)) - continue; - - if (!DataValidator.ValidateData(this._tidalProgressListener)) - continue; - - if (!DataValidator.ValidateData(this._tidalProgressListener.ProgressAddress)) - continue; - - if (!this._tidalProgressListener.ProgressAddress.HasValue) - continue; - - var value = Reader.Default.Read(this._tidalProgressListener.ProgressAddress.Value, out var success); - - //long currentTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - //long diff = currentTime - this._startTime; - - //if (diff > 0) - //{ - // this._currentSong.Time = diff; - //} - } - } - - private async Task LoginTask() - { - while (!this._disposed) - { - await this._loginTaskSuspensionToken.WaitForRelease(); - - TidalAccess tidalAccess = Core.INSTANCE.SettingManager.Settings.TidalAccess; - - if (!DataValidator.ValidateData(tidalAccess)) - continue; - - if (!this._tidalService.IsConnected()) - continue; - - if (tidalAccess.AccessToken.Equals("null")) - tidalAccess = Core.INSTANCE.SettingManager.Settings.TidalAccess; - - if (this._session == null) - { - JsonTidalSession session = - await this._tidalClient.Login(Core.INSTANCE.SettingManager.Settings.TidalAccess.AccessToken); - - if (!DataValidator.ValidateData(session)) - continue; - - this._session = session; - - if (!Core.IsLoaded()) - continue; - - Core.INSTANCE.SettingManager.Settings.TidalAccess.IsTidalConnected = true; - Core.INSTANCE.SettingManager.WriteSettings(); - - this._debugger.Write("Logged into Tidal!", DebugType.INFO); - } - - await Task.Delay(5000); - } - } - - private async Task UpdateCurrentTrack() - { - while (!this._disposed) - { - await this._updateCurrentTrackSuspensionToken.WaitForRelease(); - - await Task.Delay(500); - - JsonTidalTrack tidalTrack = await FindTidalTrack(); - - if (!TidalUtils.IsTidalRunning()) - continue; - - this._currentSong = TidalDataMerger.ValidateUpdatePlayBack(this._currentSong, tidalTrack); - } - } - - public async Task UpdateCurrentPlaybackTrack() - { - if (!this._tidalService.IsConnected()) - return null; - - if (!TidalUtils.IsTidalRunning()) - return null; - - JsonTidalTrack tidalTrack = await FindTidalTrack(); - - if (!DataValidator.ValidateData(tidalTrack)) - return null; - - this._currentSong = TidalDataMerger.ValidateConvertAndMerge(tidalTrack); - - this._startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - - this._tidalProgressListener.Start(); - - return this._currentSong; - } - - private async Task FindTidalTrack() - { - if (!TidalUtils.IsTidalRunning()) - return null; - - Process tidalProcess = TidalUtils.FindTidalProcess(); - - if (!DataValidator.ValidateData(tidalProcess)) - return null; - - if (!DataValidator.ValidateData(this._session)) - return null; - - if (!tidalProcess.MainWindowTitle.Contains("-")) - return null; - - string title = tidalProcess.MainWindowTitle.Split('-')[0].Trim(); - string artists = tidalProcess.MainWindowTitle.Split('-')[1].Trim().Replace(",", " /"); - - JsonTidalSearchResult searchResult = - await this._tidalClient.Search(this._session, title + " " + artists); - - if (!DataValidator.ValidateData(searchResult)) - return null; - - List tracks = searchResult.Items; - - for (int i = 0; i < tracks.Count; i++) - { - JsonTidalTrack currentTrack = tracks[i]; - - if (currentTrack.Title.ToLower().Equals(title.ToLower()) && - ArtistsMatch(currentTrack.Artists, artists)) - { - return currentTrack; - } - } - - return new JsonTidalTrack(); - } - - private bool ArtistsMatch(List artistsAsList, string artistsAsString) - { - int matches = 0; - - AList list = new AString(artistsAsString.Replace(" /", System.Environment.NewLine)).AsList(); - - for (int i = 0; i < artistsAsList.Count; i++) - { - JsonTidalArtist artist = artistsAsList[i]; - - for (int j = 0; j < list.Length; j++) - { - string name = list.Get(j).Trim(); - - if (artist.Name.ToLower().Equals(name.ToLower())) - matches++; - } - } - - return matches == artistsAsList.Count; - } - - public Structure.Song.Song GetCurrentSong() - { - return this._currentSong; - } - - public EnumSongProvider GetEnum() - { - return EnumSongProvider.TIDAL; - } - - public void Dispose() - { - this._disposed = true; - - Core.INSTANCE.TaskRegister.Kill(EnumRegisterTypes.TIDALSONGPROVIDER_LOGIN, EnumRegisterTypes.TIDALSONGPROVIDER_UPDATECURRENTTRACK, EnumRegisterTypes.TIDALSONGPROVIDER_UPDATETIME); - } - } -} diff --git a/OpenLyricsClient/Backend/Romanization/Romanization.cs b/OpenLyricsClient/Backend/Romanization/Romanization.cs index 83b9e9b..92fb54d 100644 --- a/OpenLyricsClient/Backend/Romanization/Romanization.cs +++ b/OpenLyricsClient/Backend/Romanization/Romanization.cs @@ -37,7 +37,7 @@ public async Task Romanize(string text) //if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Count == 0) // return text; - if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.JAPANESE_TO_ROMANJI) && DataValidator.ValidateData(this._kawazuConverter)) + /*if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.JAPANESE_TO_ROMANJI) && DataValidator.ValidateData(this._kawazuConverter)) { if (Utilities.HasJapanese(text)) { @@ -62,6 +62,7 @@ public async Task Romanize(string text) return this._russiaConverter.Process(text); } } + */ return text; } diff --git a/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs b/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs new file mode 100644 index 0000000..6016087 --- /dev/null +++ b/OpenLyricsClient/Backend/Settings/Sections/Connection/Spotify/SpotifySection.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using OpenLyricsClient.Backend.Structure; +using OpenLyricsClient.Backend.Structure.Enum; +using OpenLyricsClient.Backend.Structure.Other; +using OpenLyricsClient.Backend.Utils; +using SpotifyAPI.Web; +using SimpleArtist = SpotifyAPI.Web.SimpleArtist; +using SimpleTrack = SpotifyAPI.Web.SimpleTrack; + +namespace OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; + +public class SpotifySection : ISettingSection +{ + private FileInfo _file; + private JObject _data; + + public SpotifySection(string filePath) + { + this._file = new FileInfo(filePath); + } + + public async Task WriteToDisk() + { + await File.WriteAllTextAsync(this._file.FullName, this._data.ToString()); + } + + public async Task ReadFromDisk() + { + if (!this._file.Exists) + { + this._data = Defaults(); + await WriteToDisk(); + return; + } + + await using FileStream stream = this._file.OpenRead(); + using StreamReader reader = new StreamReader(stream); + + this._data = JObject.Parse(reader.ReadToEnd()); + + await stream.FlushAsync(); + + stream.Close(); + reader.Close(); + } + + public T GetValue(string field) + { + return (T)this._data[field].ToObject(); + } + + public async Task SetValue(string field, T value) + { + this._data[field] = JToken.FromObject(value); + await WriteToDisk(); + } + + public JObject Defaults() + { + PrivateUser privateUser = new PrivateUser + { + Country = string.Empty, + Email = string.Empty, + Followers = null, + Href = string.Empty, + Id = string.Empty, + Images = null, + Product = string.Empty, + Type = "", + Uri = "", + DisplayName = "" + }; + + SpotifyStatistics statistics = new SpotifyStatistics + { + TopTracks = null, + TopArtists = null + }; + + SpotifyAccess spotifyAccess = new SpotifyAccess + { + AccessToken = "null", + IsSpotifyConnected = false, + RefreshToken = string.Empty, + SpotifyExpireTime = (int)DateTimeOffset.Now.ToUnixTimeMilliseconds(), + UserData = privateUser, + Statistics = statistics + }; + + return new JsonDeserializer().Serialize(spotifyAccess); + } +} \ No newline at end of file diff --git a/OpenLyricsClient/Backend/Settings/SettingManager.cs b/OpenLyricsClient/Backend/Settings/SettingManager.cs index 1e64397..aa74d6f 100644 --- a/OpenLyricsClient/Backend/Settings/SettingManager.cs +++ b/OpenLyricsClient/Backend/Settings/SettingManager.cs @@ -27,7 +27,7 @@ public class SettingManager private const string SETTING_FILE_NAME = "settings.json"; - public event SettingsChangedEventHandler SettingsChanged; + //public event SettingsChangedEventHandler SettingsChanged; public SettingManager(string workingFolder) { @@ -153,9 +153,6 @@ public void WriteSettings(Settings settings, bool fireEvent = true) string json = JsonConvert.SerializeObject(settings, Formatting.Indented); File.WriteAllText(this._settingsFilePath.FileInfo.FullName, json); - - if (fireEvent) - SettingsChangedEvent(new SettingsChangedEventArgs(settings)); } public void WriteSettings(bool fireEvent = true) @@ -182,21 +179,17 @@ private Settings ReadSettings() return JsonConvert.DeserializeObject(content); } - public Settings Settings + /*public Settings Settings { get => _settings; set => _settings = value; - } + }*/ public string WorkingDirectory { get => _workingDirectory; } - protected virtual void SettingsChangedEvent(SettingsChangedEventArgs settingsChangedEventArgs) - { - SettingsChangedEventHandler settingsChangedEventHandler = SettingsChanged; - settingsChangedEventHandler?.Invoke(this, settingsChangedEventArgs); - } + } } diff --git a/OpenLyricsClient/Backend/Settings/SettingsHandler.cs b/OpenLyricsClient/Backend/Settings/SettingsHandler.cs index 8e3d234..b59e18b 100644 --- a/OpenLyricsClient/Backend/Settings/SettingsHandler.cs +++ b/OpenLyricsClient/Backend/Settings/SettingsHandler.cs @@ -1,6 +1,10 @@ using System.Threading.Tasks; +using Avalonia.Threading; using DevBase.Generics; +using OpenLyricsClient.Backend.Events.EventArgs; +using OpenLyricsClient.Backend.Events.EventHandler; using OpenLyricsClient.Backend.Settings.Sections; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; @@ -10,12 +14,17 @@ public class SettingsHandler { private AList _sections; + public event SettingsChangedEventHandler SettingsChanged; + public SettingsHandler(string workingDirectory) { this._sections = new AList(); this._sections.Add(new LyricsSection(string.Format("{0}{1}", workingDirectory, "Lyrics Preferences.json"))); + + this._sections.Add(new SpotifySection(string.Format("{0}{1}", + workingDirectory, "Spotify Access.json"))); Task.Factory.StartNew(Initialize).GetAwaiter().GetResult(); } @@ -29,4 +38,33 @@ public async Task Initialize() { return (T)this._sections.GetAsList().Find(s => s is T); } + + public async Task TriggerEvent(T section, string field) + { + await Dispatcher.UIThread.InvokeAsync(() => + { + SettingsChangedEventArgs args = new SettingsChangedEventArgs + { + Section = section, + Field = field + }; + + SettingsChangedEventHandler settingsChangedEventHandler = SettingsChanged; + settingsChangedEventHandler?.Invoke(this, args); + }); + } + + public async Task TriggerGlobal() + { + this._sections.ForEach(s => + { + using (var enumerator = s.Defaults().GetEnumerator()) + { + while (enumerator.MoveNext()) + { + TriggerEvent(s, enumerator.Current.Key.ToString()); + } + } + }); + } } \ No newline at end of file diff --git a/OpenLyricsClient/Frontend/Models/Custom/LyricsScrollerViewModel.cs b/OpenLyricsClient/Frontend/Models/Custom/LyricsScrollerViewModel.cs index 066821b..39a32d8 100644 --- a/OpenLyricsClient/Frontend/Models/Custom/LyricsScrollerViewModel.cs +++ b/OpenLyricsClient/Frontend/Models/Custom/LyricsScrollerViewModel.cs @@ -16,6 +16,7 @@ using OpenLyricsClient.Backend.Events; using OpenLyricsClient.Backend.Events.EventArgs; using OpenLyricsClient.Backend.Helper; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Lyrics; using OpenLyricsClient.Backend.Structure.Song; @@ -57,7 +58,7 @@ public LyricsScrollerViewModel() Core.INSTANCE.TickHandler += OnLyricsSyncTickHandler; Core.INSTANCE.TickHandler += OnLyricsSyncPercentageTickHandler; - Core.INSTANCE.SettingManager.SettingsChanged += (sender, args) => + Core.INSTANCE.SettingsHandler.SettingsChanged += (sender, args) => { this.CurrentLyricParts = null; @@ -211,7 +212,7 @@ public SolidColorBrush UiBackground { get { - if (Core.INSTANCE.SettingManager.Settings?.DisplayPreferences?.ArtworkBackground == true) + if (Core.INSTANCE.SettingsHandler.Settings()?.GetValue("Artwork Background") == true) return App.Current.FindResource("PrimaryThemeColorBrush") as SolidColorBrush; return App.Current.FindResource("PrimaryBackgroundBrush") as SolidColorBrush; diff --git a/OpenLyricsClient/Frontend/Models/Elements/LyricsCard.cs b/OpenLyricsClient/Frontend/Models/Elements/LyricsCard.cs index 7fc021c..f4b155a 100644 --- a/OpenLyricsClient/Frontend/Models/Elements/LyricsCard.cs +++ b/OpenLyricsClient/Frontend/Models/Elements/LyricsCard.cs @@ -11,6 +11,8 @@ using Avalonia.Media; using Avalonia.Threading; using OpenLyricsClient.Backend; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Lyrics; using OpenLyricsClient.Backend.Utils; @@ -83,7 +85,7 @@ public LyricsCard() this._ignoreEvents = false; this.BlurSigma = 0; - this.LyricDisplayMode = Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode; + this.LyricDisplayMode = Core.INSTANCE.SettingsHandler.Settings().GetValue("Selection Mode"); Core.INSTANCE.SongHandler.SongChanged += (s, args) => { @@ -117,7 +119,7 @@ public LyricsCard() }); }; - Core.INSTANCE.SettingManager.SettingsChanged += (sender, args) => + Core.INSTANCE.SettingsHandler.SettingsChanged += (sender, args) => { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedLineBrush")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("UnSelectedLineBrush")); @@ -313,7 +315,7 @@ public SolidColorBrush SelectedLineBrush if (this._ignoreEvents) return App.Current.FindResource("PrimaryThemeColorBrush") as SolidColorBrush; - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("SelectedLineFontColorBrush") as SolidColorBrush; return App.Current.FindResource("PrimaryThemeColorBrush") as SolidColorBrush; @@ -327,7 +329,7 @@ public SolidColorBrush UnSelectedLineBrush if (this._ignoreEvents) return SolidColorBrush.Parse("#646464"); - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("UnSelectedLineFontColorBrush") as SolidColorBrush; return SolidColorBrush.Parse("#646464"); @@ -357,7 +359,10 @@ public override void Render(DrawingContext context) this._greyBlock.Foreground = this.UnSelectedLineBrush; this._presenterBlock.Foreground = this.SelectedLineBrush; - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode == EnumLyricsDisplayMode.FADE && !this._ignoreEvents || + EnumLyricsDisplayMode displayMode = Core.INSTANCE.SettingsHandler.Settings() + .GetValue("Selection Mode"); + + if (displayMode == EnumLyricsDisplayMode.FADE && !this._ignoreEvents || LyricDisplayMode == EnumLyricsDisplayMode.FADE && this._ignoreEvents) { this._presenterBlock.Foreground = this.UnSelectedLineBrush; @@ -387,14 +392,13 @@ public override void Render(DrawingContext context) this._presenterBlock.Foreground = new SolidColorBrush(newColor); } } - else if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode == EnumLyricsDisplayMode.KARAOKE && !this._ignoreEvents || + else if (displayMode == EnumLyricsDisplayMode.KARAOKE && !this._ignoreEvents || LyricDisplayMode == EnumLyricsDisplayMode.KARAOKE && this._ignoreEvents) { - this._greyBlock.Foreground = this.UnSelectedLineBrush; this._presenterBlock.Foreground = this.SelectedLineBrush; - this._border.Opacity = Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground ? 0.1 : 1.0; + this._border.Opacity = Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background") ? 0.1 : 1.0; this._viewbox.IsVisible = true; this._presenterBlock.MaxWidth = this._greyBlock.TextLayout.Size.Width; diff --git a/OpenLyricsClient/Frontend/Models/Elements/NoteAnimation.cs b/OpenLyricsClient/Frontend/Models/Elements/NoteAnimation.cs index fc6e1e8..221d704 100644 --- a/OpenLyricsClient/Frontend/Models/Elements/NoteAnimation.cs +++ b/OpenLyricsClient/Frontend/Models/Elements/NoteAnimation.cs @@ -9,6 +9,8 @@ using Avalonia.Media; using DevBase.Generics; using OpenLyricsClient.Backend; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Utils; @@ -37,7 +39,7 @@ public NoteAnimation() FontWeight = FontWeight.Bold; this._current = false; - Core.INSTANCE.SettingManager.SettingsChanged += (sender, args) => + Core.INSTANCE.SettingsHandler.SettingsChanged += (sender, args) => { OnPropertyChanged("SelectedLineBrush"); OnPropertyChanged("UnSelectedLineBrush"); @@ -120,14 +122,14 @@ public override void Render(DrawingContext context) } }*/ - this._border.Opacity = Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground ? 0.1 : 1.0; + this._border.Opacity = Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background") ? 0.1 : 1.0; this.Foreground = ((SolidColorBrush)this.SelectedLineBrush); if (this._current) { double realSize = (this.GetBounds("♪").Width * 3) + (3 * 8) + 8; - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode == EnumLyricsDisplayMode.FADE) + if (Core.INSTANCE.SettingsHandler.Settings()?.GetValue("Selection Mode") == EnumLyricsDisplayMode.FADE) { this._viewbox.IsVisible = false; this._border.Width = 0; @@ -205,7 +207,7 @@ public SolidColorBrush SelectedLineBrush { get { - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("SelectedLineFontColorBrush") as SolidColorBrush; return App.Current.FindResource("PrimaryThemeColorBrush") as SolidColorBrush; @@ -216,7 +218,7 @@ public SolidColorBrush UnSelectedLineBrush { get { - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("UnSelectedLineFontColorBrush") as SolidColorBrush; return SolidColorBrush.Parse("#646464"); diff --git a/OpenLyricsClient/Frontend/Models/Pages/LyricsPageViewModel.cs b/OpenLyricsClient/Frontend/Models/Pages/LyricsPageViewModel.cs index 59b1aeb..3cd45a3 100644 --- a/OpenLyricsClient/Frontend/Models/Pages/LyricsPageViewModel.cs +++ b/OpenLyricsClient/Frontend/Models/Pages/LyricsPageViewModel.cs @@ -16,6 +16,7 @@ using OpenLyricsClient.Backend.Events.EventArgs; using OpenLyricsClient.Backend.Handler.Services.Services.Spotify; using OpenLyricsClient.Backend.Handler.Song.SongProvider; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Artwork; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Song; @@ -51,7 +52,7 @@ public LyricsPageViewModel() NextSongCommand = ReactiveCommand.CreateFromTask(()=>SkipSong(EnumPlayback.NEXT_TRACK)); Core.INSTANCE.SongHandler.SongChanged += SongHandlerOnSongChanged; - Core.INSTANCE.SettingManager.SettingsChanged += SettingManagerOnSettingsChanged; + Core.INSTANCE.SettingsHandler.SettingsChanged += SettingManagerOnSettingsChanged; Core.INSTANCE.ArtworkHandler.ArtworkAppliedHandler += ArtworkHandlerOnArtworkAppliedHandler; Core.INSTANCE.LyricHandler.LyricsFound += LyricHandlerOnLyricsFound; Core.INSTANCE.SongHandler.SongUpdated += SongHandlerOnSongUpdated; @@ -215,7 +216,7 @@ public SolidColorBrush SelectedColor { get { - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("PrimaryThemeFontColorBrush") as SolidColorBrush; return App.Current.FindResource("PrimaryThemeFontColorBrush") as SolidColorBrush; @@ -226,7 +227,7 @@ public SolidColorBrush UnSelectedColor { get { - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("SecondaryThemeColorBrush") as SolidColorBrush; return App.Current.FindResource("SecondaryThemeColorBrush") as SolidColorBrush; @@ -237,7 +238,7 @@ public SolidColorBrush UiBackground { get { - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("PrimaryThemeColorBrush") as SolidColorBrush; return App.Current.FindResource("PrimaryBackgroundBrush") as SolidColorBrush; @@ -248,7 +249,7 @@ public SolidColorBrush UiForeground { get { - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + if (Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Artwork Background")) return App.Current.FindResource("PrimaryFontColorBrush") as SolidColorBrush; return App.Current.FindResource("PrimaryFontColorBrush") as SolidColorBrush; diff --git a/OpenLyricsClient/Frontend/Models/Pages/Settings/Providers/SettingsSpotifyViewModel.cs b/OpenLyricsClient/Frontend/Models/Pages/Settings/Providers/SettingsSpotifyViewModel.cs index 3697e04..830b42f 100644 --- a/OpenLyricsClient/Frontend/Models/Pages/Settings/Providers/SettingsSpotifyViewModel.cs +++ b/OpenLyricsClient/Frontend/Models/Pages/Settings/Providers/SettingsSpotifyViewModel.cs @@ -12,9 +12,11 @@ using DevBase.Web; using OpenLyricsClient.Backend; using OpenLyricsClient.Backend.Events.EventArgs; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; using OpenLyricsClient.Frontend.Structure; using ReactiveUI; using SharpDX.DirectInput; +using SpotifyAPI.Web; using Squalr.Engine.Utils.Extensions; namespace OpenLyricsClient.Frontend.Models.Pages.Settings.Providers; @@ -28,16 +30,16 @@ public class SettingsSpotifyViewModel : ViewModelBase, INotifyPropertyChanged public SettingsSpotifyViewModel() { - Core.INSTANCE.SettingManager.SettingsChanged += SettingManagerOnSettingsChanged; + Core.INSTANCE.SettingsHandler.SettingsChanged += SettingManagerOnSettingsChanged; - DisconnectFromSpotify = ReactiveCommand.Create(DisconnectSpotify); + DisconnectFromSpotify = ReactiveCommand.CreateFromTask(DisconnectSpotify); ConnectToSpotify = ReactiveCommand.CreateFromTask(StartSpotifyAuthFlow); } - private void DisconnectSpotify() + private async Task DisconnectSpotify() { - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected = false; - Core.INSTANCE.SettingManager.WriteSettings(); + Core.INSTANCE.SettingsHandler.Settings().SetValue("IsSpotifyConnected", false); + await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(SpotifySection), "IsSpotifyConnected"); } private async Task StartSpotifyAuthFlow() @@ -58,6 +60,9 @@ private async Task StartSpotifyAuthFlow() private void SettingManagerOnSettingsChanged(object sender, SettingsChangedEventArgs settingschangedeventargs) { + if (settingschangedeventargs.Section != typeof(SpotifySection)) + return; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("UserGreeting")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("UserFollower")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("UserPlan")); @@ -86,7 +91,7 @@ public string UserGreeting break; } - stringBuilder.Append(string.Format(" {0}!", Core.INSTANCE?.SettingManager?.Settings?.SpotifyAccess?.UserData?.DisplayName!)); + stringBuilder.Append(string.Format(" {0}!", Core.INSTANCE?.SettingsHandler?.Settings()?.GetValue("UserData")?.DisplayName)); return stringBuilder.ToString(); } @@ -96,7 +101,7 @@ public string UserFollower { get { - int? follower = Core.INSTANCE?.SettingManager?.Settings?.SpotifyAccess?.UserData?.Followers?.Total!; + int? follower = Core.INSTANCE?.SettingsHandler?.Settings()?.GetValue("UserData")?.Followers?.Total; return string.Format("{0} follower", follower); } } @@ -105,7 +110,7 @@ public string UserPlan { get { - string? product = Core.INSTANCE?.SettingManager?.Settings?.SpotifyAccess?.UserData?.Product; + string? product = Core.INSTANCE?.SettingsHandler?.Settings()?.GetValue("UserData")?.Product; if (product.IsNullOrEmpty()) return string.Empty; diff --git a/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsLyricsViewModel.cs b/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsLyricsViewModel.cs index eb59f88..185f493 100644 --- a/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsLyricsViewModel.cs +++ b/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsLyricsViewModel.cs @@ -32,24 +32,28 @@ private void SwitchToKaraoke() { Core.INSTANCE.SettingsHandler.Settings()? .SetValue("Selection Mode", EnumLyricsDisplayMode.KARAOKE); + Core.INSTANCE.SettingsHandler.TriggerEvent(this, "Selection Mode"); } private void SwitchToFade() { Core.INSTANCE.SettingsHandler.Settings()? .SetValue("Selection Mode", EnumLyricsDisplayMode.FADE); + Core.INSTANCE.SettingsHandler.TriggerEvent(this, "Selection Mode"); } private void ToggleArtworkBackground() { Core.INSTANCE.SettingsHandler.Settings()? .SetValue("Artwork Background", !UseArtworkBackground); + Core.INSTANCE.SettingsHandler.TriggerEvent(this, "Artwork Background"); } private void ToggleLyricsBlur() { Core.INSTANCE.SettingsHandler.Settings()? .SetValue("Blur Lyrics", !IsBlurred); + Core.INSTANCE.SettingsHandler.TriggerEvent(this, "Blur Lyrics"); } public bool IsKaraoke diff --git a/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsRomanizationViewModel.cs b/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsRomanizationViewModel.cs index a716cf6..8614f74 100644 --- a/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsRomanizationViewModel.cs +++ b/OpenLyricsClient/Frontend/Models/Pages/Settings/SettingsRomanizationViewModel.cs @@ -26,7 +26,7 @@ public SettingsRomanizationViewModel() private void CheckOrUncheckAndWrite(RomanizeSelection selection) { - if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(selection)) + /*if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(selection)) { Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Remove(selection); } @@ -35,11 +35,11 @@ private void CheckOrUncheckAndWrite(RomanizeSelection selection) Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Add(selection); } - Core.INSTANCE.SettingManager.WriteSettings(); + Core.INSTANCE.SettingManager.WriteSettings();*/ } private bool IsAvailable(RomanizeSelection selection) => - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(selection); + true; private void Japanese() { diff --git a/OpenLyricsClient/Frontend/Models/Pages/SettingsPageViewModel.cs b/OpenLyricsClient/Frontend/Models/Pages/SettingsPageViewModel.cs index 46048bf..b0b721d 100644 --- a/OpenLyricsClient/Frontend/Models/Pages/SettingsPageViewModel.cs +++ b/OpenLyricsClient/Frontend/Models/Pages/SettingsPageViewModel.cs @@ -10,73 +10,4 @@ namespace OpenLyricsClient.Frontend.Models.Pages; -public class SettingsPageViewModel : INotifyPropertyChanged -{ - private ObservableCollection _lyricsSelectionMode; - - public ReactiveCommand ConnectToSpotify { get; } - public ReactiveCommand DisconnectFromSpotify { get; } - - private bool _spotifyConnected; - - public SettingsPageViewModel() - { - DisconnectFromSpotify = ReactiveCommand.Create(DisconnectSpotify); - ConnectToSpotify = ReactiveCommand.CreateFromTask(StartSpotifyAuthFlow); - - /*Task.Factory.StartNew(async () => - { - while (!Core.IsDisposed()) - { - await Task.Delay(500); - SpotifyConnected = Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected; - } - });*/ - } - - public void DisconnectSpotify() - { - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected = false; - Core.INSTANCE.SettingManager.WriteSettings(); - } - - public async Task StartSpotifyAuthFlow() - { - Core.INSTANCE.ServiceHandler.AuthorizeService("Spotify"); - - /*long untilTime = DateTimeOffset.Now.AddMinutes(5).ToUnixTimeMilliseconds(); - - while (!Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected && - DateTimeOffset.Now.ToUnixTimeMilliseconds() < untilTime) - { - await Task.Delay(500); - SpotifyConnected = Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected; - }*/ - } - - - public bool SpotifyConnected - { - get { return _spotifyConnected; } - set - { - this._spotifyConnected = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpotifyConnected")); - } - } - - public event PropertyChangedEventHandler? PropertyChanged; - - protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - protected bool SetField(ref T field, T value, [CallerMemberName] string? propertyName = null) - { - if (EqualityComparer.Default.Equals(field, value)) return false; - field = value; - OnPropertyChanged(propertyName); - return true; - } -} \ No newline at end of file +public class SettingsPageViewModel { } \ No newline at end of file diff --git a/OpenLyricsClient/Frontend/View/Custom/LyricsScroller.axaml.cs b/OpenLyricsClient/Frontend/View/Custom/LyricsScroller.axaml.cs index 3eeaac7..ddf3198 100644 --- a/OpenLyricsClient/Frontend/View/Custom/LyricsScroller.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Custom/LyricsScroller.axaml.cs @@ -16,6 +16,7 @@ using OpenLyricsClient.Backend; using OpenLyricsClient.Backend.Events.EventArgs; using OpenLyricsClient.Backend.Events.EventHandler; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Lyrics; using OpenLyricsClient.Backend.Utils; @@ -282,7 +283,7 @@ private void SetCurrentPosition(int selectedLine) } }*/ - bool useBlur = Core.INSTANCE.SettingManager.Settings.DisplayPreferences.LyricsBlur; + bool useBlur = Core.INSTANCE.SettingsHandler.Settings()!.GetValue("Blur Lyrics"); if (i == selectedLine) { diff --git a/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml b/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml index 9105166..78f515c 100644 --- a/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml +++ b/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml @@ -68,7 +68,6 @@ diff --git a/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs b/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs index 1900adc..0b7fa33 100644 --- a/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs @@ -14,6 +14,7 @@ using Material.Styles; using OpenLyricsClient.Backend; using OpenLyricsClient.Backend.Events.EventHandler; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Utils; using OpenLyricsClient.Frontend.Models.Pages; using OpenLyricsClient.Frontend.View.Windows; @@ -65,8 +66,7 @@ public LyricsPage() SolidColorBrush primaryBackColor = App.Current.FindResource("PrimaryBackgroundBrush") as SolidColorBrush; - if (Core.INSTANCE!.SettingManager!.Settings?.DisplayPreferences != null && - Core.INSTANCE!.SettingManager!.Settings!.DisplayPreferences!.ArtworkBackground!) + if (Core.INSTANCE.SettingsHandler.Settings()?.GetValue("Artwork Background") == true) primaryBackColor = App.Current.FindResource("SecondaryThemeColorBrush") as SolidColorBrush; Border border = new Border(); @@ -122,8 +122,8 @@ private void DataContextOnPropertyChanged(object? sender, PropertyChangedEventAr if (e.PropertyName.Equals("UiBackground")) { SolidColorBrush primaryBackColor = App.Current.FindResource("PrimaryBackgroundBrush") as SolidColorBrush; - - if (Core.INSTANCE.SettingManager.Settings.DisplayPreferences.ArtworkBackground) + + if (Core.INSTANCE.SettingsHandler.Settings()?.GetValue("Artwork Background") == true) primaryBackColor = App.Current.FindResource("SecondaryThemeColorBrush") as SolidColorBrush; this._artworkBorder.BorderBrush = primaryBackColor; diff --git a/OpenLyricsClient/Frontend/View/Pages/Settings/Providers/SettingsSpotify.axaml.cs b/OpenLyricsClient/Frontend/View/Pages/Settings/Providers/SettingsSpotify.axaml.cs index 79940c2..2b1c66c 100644 --- a/OpenLyricsClient/Frontend/View/Pages/Settings/Providers/SettingsSpotify.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Pages/Settings/Providers/SettingsSpotify.axaml.cs @@ -15,6 +15,9 @@ using MusixmatchClientLib.Web.ResponseData; using OpenLyricsClient.Backend; using OpenLyricsClient.Backend.Events.EventArgs; +using OpenLyricsClient.Backend.Settings.Sections.Connection.Spotify; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; +using OpenLyricsClient.Backend.Structure.Other; using OpenLyricsClient.Frontend.Models.Elements; using OpenLyricsClient.Frontend.Structure; using SpotifyAPI.Web; @@ -61,7 +64,7 @@ public SettingsSpotify() border.BorderBrush = primaryBackColor; border.CornerRadius = new CornerRadius(8); - Core.INSTANCE.SettingManager.SettingsChanged += SettingManagerOnSettingsChanged; + Core.INSTANCE.SettingsHandler.SettingsChanged += SettingsHandlerOnSettingsChanged; //image.Source = new Bitmap("C:\\Users\\alexa\\Desktop\\ab6775700000ee85216a8ba62f36357fee22d1d5.jpg"); ProfileImageUpdate(); @@ -74,7 +77,7 @@ public SettingsSpotify() this._topTracks = this.Get(nameof(LST_TopTracks)); } - private void SettingManagerOnSettingsChanged(object sender, SettingsChangedEventArgs settingschangedeventargs) + private void SettingsHandlerOnSettingsChanged(object sender, SettingsChangedEventArgs settingschangedeventargs) { ProfileImageUpdate(); LoadStats(); @@ -85,7 +88,7 @@ private void ProfileImageUpdate() Task.Factory.StartNew(async() => { Request request = - new Request(Core.INSTANCE?.SettingManager?.Settings?.SpotifyAccess?.UserData?.Images[0]?.Url!); + new Request(Core.INSTANCE?.SettingsHandler?.Settings()?.GetValue("UserData")?.Images[0]?.Url!); ResponseData responseData = await request.GetResponseAsync(); MemoryStream ms = new MemoryStream(responseData.Content); @@ -98,7 +101,7 @@ private void LoadStats() { Task.Factory.StartNew(async () => { - SimpleArtist[] artists = Core.INSTANCE?.SettingManager?.Settings?.SpotifyAccess?.Statistics?.TopArtists!; + SimpleArtist[] artists = Core.INSTANCE?.SettingsHandler.Settings()?.GetValue("Statistics").TopArtists; AList elements = new AList(); @@ -125,7 +128,7 @@ private void LoadStats() Task.Factory.StartNew(async () => { - SimpleTrack[] tracks = Core.INSTANCE?.SettingManager?.Settings?.SpotifyAccess?.Statistics?.TopTracks!; + SimpleTrack[] tracks = Core.INSTANCE?.SettingsHandler.Settings()?.GetValue("Statistics").TopTracks; AList elements = new AList(); diff --git a/OpenLyricsClient/Frontend/View/Pages/SettingsPage.axaml.cs b/OpenLyricsClient/Frontend/View/Pages/SettingsPage.axaml.cs index 5cdb174..b860260 100644 --- a/OpenLyricsClient/Frontend/View/Pages/SettingsPage.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Pages/SettingsPage.axaml.cs @@ -70,45 +70,8 @@ public SettingsPage() this._oldIndex = this._currentIndex; } }; - - /*Task.Factory.StartNew(async () => - { - while (!Core.IsDisposed()) - { - await Task.Delay(500); - - await Dispatcher.UIThread.InvokeAsync(() => - { - this._connectToSpotify.IsEnabled = !Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected; - this._disconnectFromSpotify.IsEnabled = Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected; - - if (Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected) - { - this._txtSpotify.Text = "Welcome " + Core.INSTANCE.SettingManager.Settings.SpotifyAccess.UserData.DisplayName; - } - else - { - this._txtSpotify.Text = "Connect with Spotify"; - } - this._japaneseToRomanji.IsChecked = - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection - .JAPANESE_TO_ROMANJI); - - this._koreanToRomanji.IsChecked = - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection - .KOREAN_TO_ROMANJI); - - this._russiaToLatin.IsChecked = - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection - .RUSSIA_TO_LATIN); - - }); - } - });*/ - this._loaded = true; - } private void InitializeComponent() @@ -121,110 +84,6 @@ private void InputElement_OnPointerPressed(object? sender, PointerPressedEventAr MainWindow.Instance.BeginMoveDrag(e); } - /*private void BTN_ConnectSpotify_OnClick(object? sender, RoutedEventArgs e) - { - Core.INSTANCE.ServiceHandler.AuthorizeService("Spotify"); - } - - private void BTN_DisconnectSpotify_OnClick(object? sender, RoutedEventArgs e) - { - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.IsSpotifyConnected = false; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.AccessToken = ""; - Core.INSTANCE.SettingManager.Settings.SpotifyAccess.RefreshToken = ""; - Core.INSTANCE.SettingManager.WriteSettings(); - } - - private void BTN_ClearCache_OnClick(object? sender, RoutedEventArgs e) - { - Core.INSTANCE.CacheManager.ClearCache(); - } - - private void BTN_RefreshLyrics_OnClick(object? sender, RoutedEventArgs e) - { - Core.INSTANCE.SongHandler.RequestNewSong(); - } - - private void CHK_JapaneseToRomanji_OnChecked(object? sender, RoutedEventArgs e) - { - if (!this._loaded) - return; - - if (!this._japaneseToRomanji.IsChecked.HasValue) - return; - - if (!Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.JAPANESE_TO_ROMANJI)) - { - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Add(RomanizeSelection.JAPANESE_TO_ROMANJI); - Core.INSTANCE.SettingManager.WriteSettings(); - } - } - - private void CHK_JapaneseToRomanji_OnUnchecked(object? sender, RoutedEventArgs e) - { - if (!this._loaded) - return; - - if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.JAPANESE_TO_ROMANJI)) - { - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Remove(RomanizeSelection.JAPANESE_TO_ROMANJI); - Core.INSTANCE.SettingManager.WriteSettings(); - } - } - - private void CHK_KoreanToRomanji_OnChecked(object? sender, RoutedEventArgs e) - { - if (!this._loaded) - return; - - if (!this._koreanToRomanji.IsChecked.HasValue) - return; - - if (!Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.KOREAN_TO_ROMANJI)) - { - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Add(RomanizeSelection.KOREAN_TO_ROMANJI); - Core.INSTANCE.SettingManager.WriteSettings(); - } - } - - private void CHK_KoreanToRomanji_OnUnchecked(object? sender, RoutedEventArgs e) - { - if (!this._loaded) - return; - - if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.KOREAN_TO_ROMANJI)) - { - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Remove(RomanizeSelection.KOREAN_TO_ROMANJI); - Core.INSTANCE.SettingManager.WriteSettings(); - } - } - - private void CHK_RussiaToLatin_OnChecked(object? sender, RoutedEventArgs e) - { - if (!this._loaded) - return; - - if (!this._russiaToLatin.IsChecked.HasValue) - return; - - if (!Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.RUSSIA_TO_LATIN)) - { - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Add(RomanizeSelection.RUSSIA_TO_LATIN); - Core.INSTANCE.SettingManager.WriteSettings(); - } - } - - private void CHK_RussiaToLatin_OnUnchecked(object? sender, RoutedEventArgs e) - { - if (!this._loaded) - return; - - if (Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Contains(RomanizeSelection.RUSSIA_TO_LATIN)) - { - Core.INSTANCE.SettingManager.Settings.RomanizeSelection.Remove(RomanizeSelection.RUSSIA_TO_LATIN); - Core.INSTANCE.SettingManager.WriteSettings(); - } - }*/ - private void UnselectAll() { this._buttonList.ForEach(b => @@ -261,27 +120,5 @@ private void BTN_Spotify_OnClick(object? sender, RoutedEventArgs e) private void BTN_Cache_OnClick(object? sender, RoutedEventArgs e) { SelectPage(3); - - /*try - { - if (Core.INSTANCE.ServiceHandler.GetServiceByName("Spotify").IsConnected()) - { - Task.Factory.StartNew(async () => - { - Song currentSong = Core.INSTANCE.SongHandler.CurrentSong; - - DevBase.Api.Apis.OpenLyricsClient.OpenLyricsClient api = - new DevBase.Api.Apis.OpenLyricsClient.OpenLyricsClient(); - api - await api.SubmitAiSync(currentSong.SongMetadata.Name, currentSong.SongMetadata.Album, - currentSong.SongMetadata.MaxTime, "large-v2", currentSong.SongMetadata.Artists); - - }); - } - } - catch (Exception exception) - { - Debug.WriteLine(exception.Message); - }*/ } } \ No newline at end of file diff --git a/OpenLyricsClient/Frontend/View/Pages/SubPages/ScrollPreviewSubPage.axaml.cs b/OpenLyricsClient/Frontend/View/Pages/SubPages/ScrollPreviewSubPage.axaml.cs index 259884c..beefeec 100644 --- a/OpenLyricsClient/Frontend/View/Pages/SubPages/ScrollPreviewSubPage.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Pages/SubPages/ScrollPreviewSubPage.axaml.cs @@ -10,6 +10,7 @@ using Avalonia.Threading; using DynamicData; using OpenLyricsClient.Backend; +using OpenLyricsClient.Backend.Settings.Sections.Lyrics; using OpenLyricsClient.Backend.Structure.Enum; using OpenLyricsClient.Backend.Structure.Lyrics; using OpenLyricsClient.Backend.Utils; @@ -64,7 +65,7 @@ public ScrollPreviewSubPage() this._currentSecond = 0; this._currentPercentage = 0; - this.LyricDisplayMode = Core.INSTANCE.SettingManager.Settings.DisplayPreferences.DisplayMode; + this.LyricDisplayMode = Core.INSTANCE.SettingsHandler.Settings().GetValue("Selection Mode"); this._uiThreadRenderTimer = new UiThreadRenderTimer(60); this._uiThreadRenderTimer.Tick += delegate(TimeSpan span)