slight clean up and minor spelling mistake

This commit is contained in:
2025-09-26 03:29:28 +09:00
parent 6bb379ebad
commit 864a2e6677
2 changed files with 21 additions and 22 deletions

View File

@@ -4,9 +4,7 @@ using LightlessSync.LightlessConfiguration;
using LightlessSync.Services.Mediator; using LightlessSync.Services.Mediator;
using LightlessSync.Utils; using LightlessSync.Utils;
using LightlessSync.WebAPI; using LightlessSync.WebAPI;
using LightlessSync.WebAPI.SignalR;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -16,7 +14,6 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
private readonly ILogger<BroadcastService> _logger; private readonly ILogger<BroadcastService> _logger;
private readonly ApiController _apiController; private readonly ApiController _apiController;
private readonly LightlessMediator _mediator; private readonly LightlessMediator _mediator;
private readonly HubFactory _hubFactory;
private readonly LightlessConfigService _config; private readonly LightlessConfigService _config;
private readonly DalamudUtilService _dalamudUtil; private readonly DalamudUtilService _dalamudUtil;
public LightlessMediator Mediator => _mediator; public LightlessMediator Mediator => _mediator;
@@ -29,35 +26,37 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
private TimeSpan? _remainingTtl = null; private TimeSpan? _remainingTtl = null;
private DateTime _lastTtlCheck = DateTime.MinValue; private DateTime _lastTtlCheck = DateTime.MinValue;
private DateTime _lastForcedDisableTime = 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? RemainingTtl => _remainingTtl;
public TimeSpan? RemainingCooldown public TimeSpan? RemainingCooldown
{ {
get get
{ {
var elapsed = DateTime.UtcNow - _lastForcedDisableTime; var elapsed = DateTime.UtcNow - _lastForcedDisableTime;
if (elapsed >= DisableCooldown) return null; if (elapsed >= _disableCooldown) return null;
return DisableCooldown - elapsed; return _disableCooldown - elapsed;
} }
} }
public BroadcastService(ILogger<BroadcastService> logger, LightlessMediator mediator, HubFactory hubFactory, LightlessConfigService config, DalamudUtilService dalamudUtil, ApiController apiController)
public BroadcastService(ILogger<BroadcastService> logger, LightlessMediator mediator, LightlessConfigService config, DalamudUtilService dalamudUtil, ApiController apiController)
{ {
_logger = logger; _logger = logger;
_mediator = mediator; _mediator = mediator;
_hubFactory = hubFactory;
_config = config; _config = config;
_dalamudUtil = dalamudUtil; _dalamudUtil = dalamudUtil;
_apiController = apiController; _apiController = apiController;
} }
private async Task RequireConnectionAsync(string context, Func<Task> action) private async Task RequireConnectionAsync(string context, Func<Task> action)
{ {
if (!_apiController.IsConnected) if (!_apiController.IsConnected)
{ {
_logger.LogDebug($"{context} skipped, not connected"); _logger.LogDebug(context + " skipped, not connected");
return; return;
} }
await action().ConfigureAwait(false); await action().ConfigureAwait(false);
} }
public async Task StartAsync(CancellationToken cancellationToken) public async Task StartAsync(CancellationToken cancellationToken)
{ {
_mediator.Subscribe<EnableBroadcastMessage>(this, OnEnableBroadcast); _mediator.Subscribe<EnableBroadcastMessage>(this, OnEnableBroadcast);
@@ -65,7 +64,7 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
_mediator.Subscribe<PriorityFrameworkUpdateMessage>(this, OnTick); _mediator.Subscribe<PriorityFrameworkUpdateMessage>(this, OnTick);
_apiController.OnConnected += () => _ = CheckLightfinderSupportAsync(cancellationToken); _apiController.OnConnected += () => _ = CheckLightfinderSupportAsync(cancellationToken);
_ = CheckLightfinderSupportAsync(cancellationToken); //_ = CheckLightfinderSupportAsync(cancellationToken);
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)
@@ -86,13 +85,12 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
return; return;
var hub = _hubFactory.GetOrCreate(CancellationToken.None);
var dummy = "0".PadLeft(64, '0'); var dummy = "0".PadLeft(64, '0');
await hub.InvokeAsync<BroadcastStatusInfoDto?>("IsUserBroadcasting", dummy, cancellationToken); await _apiController.IsUserBroadcasting(dummy).ConfigureAwait(false);
await hub.InvokeAsync("SetBroadcastStatus", dummy, true, null, cancellationToken); await _apiController.SetBroadcastStatus(dummy, true, null).ConfigureAwait(false);
await hub.InvokeAsync<TimeSpan?>("GetBroadcastTtl", dummy, cancellationToken); await _apiController.GetBroadcastTtl(dummy).ConfigureAwait(false);
await hub.InvokeAsync<Dictionary<string, BroadcastStatusInfoDto?>>("AreUsersBroadcasting", new[] { dummy }, cancellationToken); await _apiController.AreUsersBroadcasting([dummy]).ConfigureAwait(false);
IsLightFinderAvailable = true; IsLightFinderAvailable = true;
_logger.LogInformation("Lightfinder is available."); _logger.LogInformation("Lightfinder is available.");
@@ -119,6 +117,7 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
_config.Current.BroadcastEnabled = false; _config.Current.BroadcastEnabled = false;
_config.Current.BroadcastTtl = DateTime.MinValue; _config.Current.BroadcastTtl = DateTime.MinValue;
_config.Save(); _config.Save();
_mediator.Publish(new BroadcastStatusChangedMessage(false, null)); _mediator.Publish(new BroadcastStatusChangedMessage(false, null));
} }
} }
@@ -151,13 +150,13 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
_config.Save(); _config.Save();
_mediator.Publish(new BroadcastStatusChangedMessage(false, null)); _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; return;
} }
_waitingForTtlFetch = true; _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) if (ttl is { } remaining && remaining > TimeSpan.Zero)
{ {
@@ -325,8 +324,8 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
_syncedOnStartup = true; _syncedOnStartup = true;
try try
{ {
var hashedCid = (await _dalamudUtil.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256(); string hashedCid = (await _dalamudUtil.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256();
var ttl = await GetBroadcastTtlAsync(hashedCid).ConfigureAwait(false); TimeSpan? ttl = await GetBroadcastTtlAsync(hashedCid).ConfigureAwait(false);
if (ttl is { } if (ttl is { }
remaining && remaining > TimeSpan.Zero) remaining && remaining > TimeSpan.Zero)
{ {
@@ -357,8 +356,8 @@ public class BroadcastService : IHostedService, IMediatorSubscriber
return; return;
} }
var expiry = _config.Current.BroadcastTtl; DateTime expiry = _config.Current.BroadcastTtl;
var remaining = expiry - DateTime.UtcNow; TimeSpan remaining = expiry - DateTime.UtcNow;
_remainingTtl = remaining > TimeSpan.Zero ? remaining : null; _remainingTtl = remaining > TimeSpan.Zero ? remaining : null;
if (_remainingTtl == null) if (_remainingTtl == null)
{ {

View File

@@ -167,7 +167,7 @@ public partial class IntroUi : WindowMediatorSubscriberBase
} }
else 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. " + "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."); "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."); UiSharedService.TextWrapped("Note: The initial scan, depending on the amount of mods you have, might take a while. Please wait until it is completed.");