From e64893855edb2fb222f646e622ffdfde6c3471b2 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Mon, 10 May 2021 07:10:25 -0700 Subject: [PATCH] Fix Current User for macOS. --- Agent/Services/DeviceInformationServiceMac.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Agent/Services/DeviceInformationServiceMac.cs b/Agent/Services/DeviceInformationServiceMac.cs index f9b2cd3fa..3328d7fb8 100644 --- a/Agent/Services/DeviceInformationServiceMac.cs +++ b/Agent/Services/DeviceInformationServiceMac.cs @@ -29,7 +29,7 @@ public async Task CreateDevice(string deviceId, string orgId) var (usedStorage, totalStorage) = GetSystemDriveInfo(); var (usedMemory, totalMemory) = GetMemoryInGB(); - device.CurrentUser = Environment.UserName; + device.CurrentUser = GetCurrentUser(); device.Drives = GetAllDrives(); device.UsedStorage = usedStorage; device.TotalStorage = totalStorage; @@ -56,7 +56,8 @@ public async Task CreateDevice(string deviceId, string orgId) cpuPercentStrings .Split(Environment.NewLine) .ToList() - .ForEach(x => { + .ForEach(x => + { if (double.TryParse(x, out var result)) { cpuPercent += result; @@ -94,7 +95,8 @@ public async Task CreateDevice(string deviceId, string orgId) memPercentStrings .Split(Environment.NewLine) .ToList() - .ForEach(x => { + .ForEach(x => + { if (double.TryParse(x, out var result)) { usedMemPercent += result; @@ -104,12 +106,18 @@ public async Task CreateDevice(string deviceId, string orgId) usedMemPercent = usedMemPercent / 4 / 100; usedGB = usedMemPercent * totalGB; - return (usedGB,totalGB); + return (usedGB, totalGB); } catch { return (0, 0); } } + + private string GetCurrentUser() + { + var users = _processInvoker.InvokeProcessOutput("users", ""); + return users?.Split()?.FirstOrDefault()?.Trim(); + } } }