Remotely/Desktop.Shared/Services/DesktopEnvironment.cs
2024-07-16 09:25:15 -07:00

44 lines
910 B
C#

using Remotely.Desktop.Shared.Native.Linux;
using System.Security.Principal;
namespace Desktop.Shared.Services;
public interface IDesktopEnvironment
{
bool IsElevated { get; }
bool IsDebug { get; }
}
internal class DesktopEnvironment : IDesktopEnvironment
{
public bool IsDebug
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
public bool IsElevated
{
get
{
if (OperatingSystem.IsWindows())
{
using var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
if (OperatingSystem.IsLinux())
{
return Libc.geteuid() == 0;
}
return false;
}
}
}