/// <summary>Checks whether we support awake state prolonging for the current platform.</summary>
    public static async Task <SleepInhibitor?> CreateAsync(CoinJoinManager coinJoinManager)
    {
        Func <Task <IPowerSavingInhibitorTask> >?taskFactory = null;

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
            // Either we have systemd or not.
            bool isSystemd = await LinuxInhibitorTask.IsSystemdInhibitSupportedAsync().ConfigureAwait(false);

            if (!isSystemd)
            {
                return(null);
            }

            GraphicalEnvironment gui = GraphicalEnvironment.Other;

            // Specialization for GNOME.
            if (await LinuxInhibitorTask.IsMateSessionInhibitSupportedAsync().ConfigureAwait(false))
            {
                gui = GraphicalEnvironment.Mate;
            }
            else if (await LinuxInhibitorTask.IsGnomeSessionInhibitSupportedAsync().ConfigureAwait(false))
            {
                gui = GraphicalEnvironment.Gnome;
            }

            taskFactory = () => Task.FromResult <IPowerSavingInhibitorTask>(LinuxInhibitorTask.Create(InhibitWhat.Idle, Timeout, Reason, gui));
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            taskFactory = () => Task.FromResult <IPowerSavingInhibitorTask>(WindowsPowerAvailabilityTask.Create(Reason));
        }

        return(new SleepInhibitor(coinJoinManager, taskFactory));
    }
Esempio n. 2
0
        public async Task TestAvailabilityAsync()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                bool isAvailable = await LinuxInhibitorTask.IsSystemdInhibitSupportedAsync();

                Assert.True(isAvailable);
            }
        }