コード例 #1
0
ファイル: SleepChecker.cs プロジェクト: Lintharr/pcSleeper
        private void OnTimedSleepCheckerEvent(object source, ElapsedEventArgs e)
        {
            //App has to target x86 for this gamepad checking thing to work, otherwise compiler throws runtime errors.
            GamePadState xboxControllerCurrentState = GamePad.GetState(PlayerIndex.One); // Get the current gamepad state. // Process input only if controller is connected.
            var          idleTime = Win32_IdleHandler.GetIdleTime();

            Logger.LogInfo($@"{nameof(_sleepChecker)} - PC idle time: {TimeHelper.ConvertTicksToTime(idleTime)}.{(xboxControllerCurrentState.IsConnected ? " Game pad is connected!" : "")}");
            if (IsItNightTime() && !xboxControllerCurrentState.IsConnected && idleTime > GetTimeWithTolerance(NightIdleTimeLimit))
            {
                PcManager.MakePcSleep();
            }
        }
コード例 #2
0
        private void OnTimedWakeUpEvent(object source, ElapsedEventArgs e)
        {
            var idleTime = Win32_IdleHandler.GetIdleTime();

            Logger.LogInfo($@"{nameof(_wakeUpChecker)} - PC idle time: {TimeHelper.ConvertTicksToTime(idleTime)}.");

            if (idleTime > TimeHelper.Seconds(50))
            {
                DisplayNotification(8);
                Logger.LogInfo("Displayed Windows notification.");
            }

            if ((DateTime.UtcNow - WakeUpCheckerStartTime) > WakeUpCheckerMaxLifespan)
            {
                Logger.LogInfo($@"{nameof(_wakeUpChecker)} managed to stay up through its lifespan. Disposing...");
                NullifyWakeUpChecker(null, null); //delete it if user has been active longer than max lifespan
            }

            if (idleTime > WakeUpIdleTimeLimit)
            {
                NullifyWakeUpChecker(null, null); //in case it wasn't already disposed of above
                PcManager.MakePcSleep();
            }
        }