From 864a2e66771c1a7d5ad452abe39cf02ae8bf540c Mon Sep 17 00:00:00 2001 From: azyges Date: Fri, 26 Sep 2025 03:29:28 +0900 Subject: [PATCH] slight clean up and minor spelling mistake --- LightlessSync/Services/BroadcastService.cs | 41 +++++++++++----------- LightlessSync/UI/IntroUI.cs | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/LightlessSync/Services/BroadcastService.cs b/LightlessSync/Services/BroadcastService.cs index 09a9674..6d6409e 100644 --- a/LightlessSync/Services/BroadcastService.cs +++ b/LightlessSync/Services/BroadcastService.cs @@ -4,9 +4,7 @@ using LightlessSync.LightlessConfiguration; using LightlessSync.Services.Mediator; using LightlessSync.Utils; using LightlessSync.WebAPI; -using LightlessSync.WebAPI.SignalR; using Microsoft.AspNetCore.SignalR; -using Microsoft.AspNetCore.SignalR.Client; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -16,7 +14,6 @@ public class BroadcastService : IHostedService, IMediatorSubscriber private readonly ILogger _logger; private readonly ApiController _apiController; private readonly LightlessMediator _mediator; - private readonly HubFactory _hubFactory; private readonly LightlessConfigService _config; private readonly DalamudUtilService _dalamudUtil; public LightlessMediator Mediator => _mediator; @@ -29,35 +26,37 @@ public class BroadcastService : IHostedService, IMediatorSubscriber private TimeSpan? _remainingTtl = null; private DateTime _lastTtlCheck = DateTime.MinValue; private DateTime _lastForcedDisableTime = DateTime.MinValue; - private static readonly TimeSpan DisableCooldown = TimeSpan.FromSeconds(5); + private static readonly TimeSpan _disableCooldown = TimeSpan.FromSeconds(5); public TimeSpan? RemainingTtl => _remainingTtl; public TimeSpan? RemainingCooldown { get { var elapsed = DateTime.UtcNow - _lastForcedDisableTime; - if (elapsed >= DisableCooldown) return null; - return DisableCooldown - elapsed; + if (elapsed >= _disableCooldown) return null; + return _disableCooldown - elapsed; } } - public BroadcastService(ILogger logger, LightlessMediator mediator, HubFactory hubFactory, LightlessConfigService config, DalamudUtilService dalamudUtil, ApiController apiController) + + public BroadcastService(ILogger logger, LightlessMediator mediator, LightlessConfigService config, DalamudUtilService dalamudUtil, ApiController apiController) { _logger = logger; _mediator = mediator; - _hubFactory = hubFactory; _config = config; _dalamudUtil = dalamudUtil; _apiController = apiController; } + private async Task RequireConnectionAsync(string context, Func action) { if (!_apiController.IsConnected) { - _logger.LogDebug($"{context} skipped, not connected"); + _logger.LogDebug(context + " skipped, not connected"); return; } await action().ConfigureAwait(false); } + public async Task StartAsync(CancellationToken cancellationToken) { _mediator.Subscribe(this, OnEnableBroadcast); @@ -65,7 +64,7 @@ public class BroadcastService : IHostedService, IMediatorSubscriber _mediator.Subscribe(this, OnTick); _apiController.OnConnected += () => _ = CheckLightfinderSupportAsync(cancellationToken); - _ = CheckLightfinderSupportAsync(cancellationToken); + //_ = CheckLightfinderSupportAsync(cancellationToken); } public Task StopAsync(CancellationToken cancellationToken) @@ -86,13 +85,12 @@ public class BroadcastService : IHostedService, IMediatorSubscriber if (cancellationToken.IsCancellationRequested) return; - var hub = _hubFactory.GetOrCreate(CancellationToken.None); var dummy = "0".PadLeft(64, '0'); - await hub.InvokeAsync("IsUserBroadcasting", dummy, cancellationToken); - await hub.InvokeAsync("SetBroadcastStatus", dummy, true, null, cancellationToken); - await hub.InvokeAsync("GetBroadcastTtl", dummy, cancellationToken); - await hub.InvokeAsync>("AreUsersBroadcasting", new[] { dummy }, cancellationToken); + await _apiController.IsUserBroadcasting(dummy).ConfigureAwait(false); + await _apiController.SetBroadcastStatus(dummy, true, null).ConfigureAwait(false); + await _apiController.GetBroadcastTtl(dummy).ConfigureAwait(false); + await _apiController.AreUsersBroadcasting([dummy]).ConfigureAwait(false); IsLightFinderAvailable = true; _logger.LogInformation("Lightfinder is available."); @@ -119,6 +117,7 @@ public class BroadcastService : IHostedService, IMediatorSubscriber _config.Current.BroadcastEnabled = false; _config.Current.BroadcastTtl = DateTime.MinValue; _config.Save(); + _mediator.Publish(new BroadcastStatusChangedMessage(false, null)); } } @@ -151,13 +150,13 @@ public class BroadcastService : IHostedService, IMediatorSubscriber _config.Save(); _mediator.Publish(new BroadcastStatusChangedMessage(false, null)); - Mediator.Publish(new EventMessage(new Services.Events.Event(nameof(BroadcastService), Services.Events.EventSeverity.Informational,$"Disabled Lightfinder for Player: {msg.HashedCid}"))); + Mediator.Publish(new EventMessage(new Services.Events.Event(nameof(BroadcastService), Services.Events.EventSeverity.Informational, $"Disabled Lightfinder for Player: {msg.HashedCid}"))); return; } _waitingForTtlFetch = true; - var ttl = await GetBroadcastTtlAsync(msg.HashedCid).ConfigureAwait(false); + TimeSpan? ttl = await GetBroadcastTtlAsync(msg.HashedCid).ConfigureAwait(false); if (ttl is { } remaining && remaining > TimeSpan.Zero) { @@ -325,8 +324,8 @@ public class BroadcastService : IHostedService, IMediatorSubscriber _syncedOnStartup = true; try { - var hashedCid = (await _dalamudUtil.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256(); - var ttl = await GetBroadcastTtlAsync(hashedCid).ConfigureAwait(false); + string hashedCid = (await _dalamudUtil.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256(); + TimeSpan? ttl = await GetBroadcastTtlAsync(hashedCid).ConfigureAwait(false); if (ttl is { } remaining && remaining > TimeSpan.Zero) { @@ -357,8 +356,8 @@ public class BroadcastService : IHostedService, IMediatorSubscriber return; } - var expiry = _config.Current.BroadcastTtl; - var remaining = expiry - DateTime.UtcNow; + DateTime expiry = _config.Current.BroadcastTtl; + TimeSpan remaining = expiry - DateTime.UtcNow; _remainingTtl = remaining > TimeSpan.Zero ? remaining : null; if (_remainingTtl == null) { diff --git a/LightlessSync/UI/IntroUI.cs b/LightlessSync/UI/IntroUI.cs index bc32128..470cadb 100644 --- a/LightlessSync/UI/IntroUI.cs +++ b/LightlessSync/UI/IntroUI.cs @@ -167,7 +167,7 @@ public partial class IntroUi : WindowMediatorSubscriberBase } else { - UiSharedService.TextWrapped("To not unnecessary download files already present on your computer, Lightless Sync will have to scan your Penumbra mod directory. " + + UiSharedService.TextWrapped("To not unnecessarily download files already present on your computer, Lightless Sync will have to scan your Penumbra mod directory. " + "Additionally, a local storage folder must be set where Lightless Sync will download other character files to. " + "Once the storage folder is set and the scan complete, this page will automatically forward to registration at a service."); UiSharedService.TextWrapped("Note: The initial scan, depending on the amount of mods you have, might take a while. Please wait until it is completed.");