diff --git a/Server/Components/Devices/DeviceCard.razor.cs b/Server/Components/Devices/DeviceCard.razor.cs index 9ce69b8d4..6bbb7fef2 100644 --- a/Server/Components/Devices/DeviceCard.razor.cs +++ b/Server/Components/Devices/DeviceCard.razor.cs @@ -329,7 +329,7 @@ private async Task WakeDevice() if (result.IsSuccess) { ToastService.ShowToast2( - $"Wake command sent to {result.Value} peer devices.", + $"Wake command sent to peer devices.", ToastType.Success); } else diff --git a/Server/Components/Devices/DevicesFrame.razor.cs b/Server/Components/Devices/DevicesFrame.razor.cs index 559648461..66cfe24f0 100644 --- a/Server/Components/Devices/DevicesFrame.razor.cs +++ b/Server/Components/Devices/DevicesFrame.razor.cs @@ -358,7 +358,7 @@ private async Task WakeDevices() if (result.IsSuccess) { ToastService.ShowToast2( - $"Wake commands sent to {result.Value} peer devices.", + $"Wake commands sent to peer devices.", ToastType.Success); } else diff --git a/Server/Hubs/CircuitConnection.cs b/Server/Hubs/CircuitConnection.cs index 59d3e7c7b..73155ac01 100644 --- a/Server/Hubs/CircuitConnection.cs +++ b/Server/Hubs/CircuitConnection.cs @@ -61,16 +61,14 @@ public interface ICircuitConnection /// Peer devices are those in the same group or the same public IP. /// /// - /// The number of peer devices that broadcasted the WOL packet. - Task> WakeDevice(Device device); + Task WakeDevice(Device device); /// /// Sends a Wake-On-LAN request for the specified device to its peer devices. /// Peer devices are those in the same group or the same public IP. /// /// - /// The number of peer devices that broadcasted the WOL packet. - Task> WakeDevices(Device[] devices); + Task WakeDevices(Device[] devices); } public class CircuitConnection : CircuitHandler, ICircuitConnection @@ -447,13 +445,13 @@ public Task UploadFiles(List fileIDs, string transferID, string[] device return Task.CompletedTask; } - public async Task> WakeDevice(Device device) + public async Task WakeDevice(Device device) { try { if (!_dataService.DoesUserHaveAccessToDevice(device.ID, User.Id)) { - return Result.Fail("Unauthorized.") ; + return Result.Fail("Unauthorized.") ; } var availableDevices = _serviceSessionCache @@ -465,16 +463,16 @@ public async Task> WakeDevice(Device device) await SendWakeCommand(device, availableDevices); - return Result.Ok(availableDevices.Length); + return Result.Ok(); } catch (Exception ex) { _logger.LogError(ex, "Error waking device {deviceId}.", device.ID); - return Result.Fail(ex); + return Result.Fail(ex); } } - public async Task> WakeDevices(Device[] devices) + public async Task WakeDevices(Device[] devices) { try { @@ -498,8 +496,6 @@ public async Task> WakeDevices(Device[] devices) { var group = devicesByGroupId.GetOrAdd(device.DeviceGroupID, key => new()); group.Add(device); - // We only need it added to one group. - continue; } if (!string.IsNullOrWhiteSpace(device.PublicIP)) @@ -509,32 +505,27 @@ public async Task> WakeDevices(Device[] devices) } } - - var peerCount = 0; - foreach (var deviceToWake in filteredDevices) { if (!string.IsNullOrWhiteSpace(deviceToWake.DeviceGroupID) && devicesByGroupId.TryGetValue(deviceToWake.DeviceGroupID, out var groupList)) { await SendWakeCommand(deviceToWake, groupList); - peerCount += groupList.Count; } if (!string.IsNullOrWhiteSpace(deviceToWake.PublicIP) && devicesByPublicIp.TryGetValue(deviceToWake.PublicIP, out var ipList)) { await SendWakeCommand(deviceToWake, ipList); - peerCount += ipList.Count; } } - return Result.Ok(peerCount); + return Result.Ok(); } catch (Exception ex) { _logger.LogError(ex, "Error while waking devices."); - return Result.Fail(ex); + return Result.Fail(ex); } } @@ -604,6 +595,15 @@ private async Task SendWakeCommand(Device deviceToWake, IEnumerable peer { if (_serviceSessionCache.TryGetConnectionId(peerDevice.ID, out var connectionId)) { + _logger.LogInformation( + "Sending wake command for device {deviceName} ({deviceId}) to " + + "peer device {peerDeviceName} ({peerDeviceId}). " + + "Sender: {username}.", + deviceToWake.DeviceName, + deviceToWake.ID, + peerDevice.DeviceName, + peerDevice.ID, + User.UserName); await _agentHubContext.Clients.Client(connectionId).SendAsync("WakeDevice", mac); } }