Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        private System.Windows.Forms.Keys HotkeyKey = System.Windows.Forms.Keys.K;     //TODO: Config

        #endregion Fields & Properties

        internal SleeperContext()
        {
            Logger.LogInfo("App starting.");
            if (PcManager.IsAppAlreadyRunning())
            {
                return;
            }

            PcManager.TryToInstallThisApp();
            _sleepChecker  = new SleepChecker();
            _wakeUpChecker = new WakeUpChecker(DisplayNotification, ChangeTrayIcon);
            InitializeTrayIcon();
            InitializeHotKeyHook();
        }
Esempio n. 3
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();
            }
        }