Skip to content

Commit

Permalink
Fix Current User for macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 10, 2021
1 parent 41fd335 commit e648938
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Agent/Services/DeviceInformationServiceMac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<Device> 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;
Expand All @@ -56,7 +56,8 @@ public async Task<Device> CreateDevice(string deviceId, string orgId)
cpuPercentStrings
.Split(Environment.NewLine)
.ToList()
.ForEach(x => {
.ForEach(x =>
{
if (double.TryParse(x, out var result))
{
cpuPercent += result;
Expand Down Expand Up @@ -94,7 +95,8 @@ public async Task<Device> CreateDevice(string deviceId, string orgId)
memPercentStrings
.Split(Environment.NewLine)
.ToList()
.ForEach(x => {
.ForEach(x =>
{
if (double.TryParse(x, out var result))
{
usedMemPercent += result;
Expand All @@ -104,12 +106,18 @@ public async Task<Device> 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();
}
}
}

0 comments on commit e648938

Please sign in to comment.