discovery fix
This commit is contained in:
@@ -67,34 +67,45 @@ public class PrinterDiscoveryBackgroundTask
|
||||
|
||||
private async Task DiscoverAndNotifyAsync()
|
||||
{
|
||||
_printServer.EnterDiscoveryLock();
|
||||
List<DiscoveredPrinter> printers;
|
||||
HashSet<string> currentIps;
|
||||
bool configChanged;
|
||||
|
||||
await _printServer.EnterDiscoveryLockAsync();
|
||||
try
|
||||
{
|
||||
var printers = await _discoveryService.DiscoverPrintersAsync(_discoveryTimeout);
|
||||
printers = await _discoveryService.DiscoverPrintersAsync(_discoveryTimeout);
|
||||
currentIps = printers.Select(p => p.IPAddress).ToHashSet();
|
||||
configChanged = HasConfigurationChanged(currentIps);
|
||||
|
||||
var currentIps = printers.Select(p => p.IPAddress).ToHashSet();
|
||||
|
||||
foreach (string currentIp in currentIps)
|
||||
if (configChanged)
|
||||
{
|
||||
_printServer.RegisterPrinter(currentIp);
|
||||
}
|
||||
|
||||
if (HasConfigurationChanged(currentIps))
|
||||
{
|
||||
_logger.LogInformation("Discovered printer configuration changed: {Count} printer(s)", printers.Count);
|
||||
_lastDiscoveredPrinterIps = currentIps;
|
||||
_lastDiscoveredPrinters = printers;
|
||||
await _receiver.OnPrintersDiscoveredAsync(printers.AsReadOnly());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to discover printers");
|
||||
return; // Exit early on error
|
||||
}
|
||||
finally
|
||||
{
|
||||
_printServer.ExitDiscoveryLock();
|
||||
}
|
||||
|
||||
// Register printers AFTER releasing the lock
|
||||
foreach (string currentIp in currentIps)
|
||||
{
|
||||
_logger.LogDebug("Registering discovered printer with IP: {IP}", currentIp);
|
||||
_printServer.RegisterPrinter(currentIp);
|
||||
}
|
||||
|
||||
if (configChanged)
|
||||
{
|
||||
_logger.LogInformation("Discovered printer configuration changed: {Count} printer(s)", printers.Count);
|
||||
await _receiver.OnPrintersDiscoveredAsync(printers.AsReadOnly());
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasConfigurationChanged(HashSet<string> currentIps)
|
||||
|
||||
@@ -1 +1 @@
|
||||
aHR0cDovL2xvY2FsaG9zdDo1MDAyOzY1YzM2MDYyZDM2ZTRjZmVlNmVjZjIyODtvWTVpcjViQi9pMXlSeFdpQ2FRTE1QdkFsS0dBaVVjNy8yK0IyczhXcUJzPQ==
|
||||
aHR0cHM6Ly9hcGkuZGV2Lmdhc3Ryb2phbWVzLmNoOzY4ODc1MjY2MTcxMjgxN2RlMjcxNTlmMjtGTEVEL1phQ2F5a0NrdEpCOHZzN1lqVFNyaStleGdKVWIva21WWk1lUHBNPQ==
|
||||
Reference in New Issue
Block a user