// entrypoint private void Countdown_Load(object sender, EventArgs e) { ExceptionHandler.LogEvent("[Countdown] Start stopwatch"); // Setup clock stopwatch = new Stopwatch(); stopwatch.Start(); ExceptionHandler.LogEvent("[Countdown] Prepare UI"); // Set trayIcon icon to the opposite of the selected theme bool lighttheme; if (SettingsProvider.SettingsLoaded) { if (SettingsProvider.Settings.TrayIconTheme == "Light") { lighttheme = true; } else if (SettingsProvider.Settings.TrayIconTheme == "Dark") { lighttheme = false; } else { lighttheme = WindowsAPIs.GetWindowsLightTheme(); } } else { lighttheme = WindowsAPIs.GetWindowsLightTheme(); } // When the dark theme is selected we are using the light icon to generate contrast (and vise versa), you wouldn't want a white icon on a white background. notifyIcon.Icon = lighttheme ? Properties.Resources.icon_dark : Properties.Resources.icon_light; // Setup UI titleLabel.Text = Action + " Timer"; if (!UI) { ignoreClose = true; // Disable close dialogs and ignore closing from form TopMost = false; ShowInTaskbar = false; WindowState = FormWindowState.Minimized; timerUIHideMenuItem.Enabled = false; timerUIShowMenuItem.Enabled = true; notifyIcon.BalloonTipText = "Timer started. The power action will be executed in " + CountdownTimeSpan.Hours + " hours, " + CountdownTimeSpan.Minutes + " minutes and " + CountdownTimeSpan.Seconds + " seconds."; notifyIcon.ShowBalloonTip(10000); Hide(); } if (Forced) { ignoreClose = true; contextMenuStrip.Enabled = false; } ExceptionHandler.LogEvent("[Countdown] Set UI"); UpdateUI(CountdownTimeSpan); if (PreventSystemSleep) { ExceptionHandler.LogEvent("[Countdown] Preventing sleep"); ExecutionState.SetThreadExecutionState(ExecutionState.EXECUTION_STATE.ES_CONTINUOUS | ExecutionState.EXECUTION_STATE.ES_SYSTEM_REQUIRED); } // give the system some coffee so it stays awake when tired using some fancy EXECUTION_STATE flags }
// entrypoint private void Countdown_Load(object sender, EventArgs e) { ExceptionHandler.LogEvent("[Countdown] Starting stopwatch"); // Setup clock stopwatch = new Stopwatch(); stopwatch.Start(); ExceptionHandler.LogEvent("[Countdown] Preparing UI..."); // Set custom background color / transparency if (SettingsProvider.Settings.DisableAnimations) { if (SettingsProvider.Settings.BackgroundColor == Color.Transparent) { BackColor = Color.Black; TransparencyKey = Color.Black; FormBorderStyle = FormBorderStyle.None; } else { BackColor = SettingsProvider.Settings.BackgroundColor; } } // Set trayIcon icon to the opposite of the selected theme bool lighttheme; if (SettingsProvider.Settings.TrayIconTheme == "Light") { lighttheme = true; } else if (SettingsProvider.Settings.TrayIconTheme == "Dark") { lighttheme = false; } else { lighttheme = WindowsAPIs.GetWindowsLightTheme(); } // When the dark theme is selected we are using the light icon to generate contrast (and vise versa), you wouldn't want a white icon on a white background. notifyIcon.Icon = lighttheme ? Properties.Resources.icon_dark : Properties.Resources.icon_light; // Load password and set the lock state if (!String.IsNullOrEmpty(Password)) { ExceptionHandler.LogEvent("[Countdown] A password has been detected"); ChangeLockState("locked"); } // Setup UI titleLabel.Text = Action + " Timer"; TopMost = !SettingsProvider.Settings.DisableAlwaysOnTop; if (!UI) { ignoreClose = true; // Disable close dialogs and ignore closing from form TopMost = false; ShowInTaskbar = false; WindowState = FormWindowState.Minimized; timerUIHideMenuItem.Enabled = false; timerUIShowMenuItem.Enabled = true; notifyIcon.BalloonTipText = "Timer started. The power action will be executed in " + CountdownTimeSpan.Hours + " hours, " + CountdownTimeSpan.Minutes + " minutes and " + CountdownTimeSpan.Seconds + " seconds."; notifyIcon.ShowBalloonTip(10000); Hide(); } if (Forced) { ignoreClose = true; contextMenuStrip.Enabled = false; } if (!UserLaunch) // disable restart app menu button because it would also keep the CLI args so the countdown would restart so it's basically useless { appRestartMenuItem.Enabled = false; } ExceptionHandler.LogEvent("[Countdown] Prepared UI"); ExceptionHandler.LogEvent("[Countdown] Updating UI"); UpdateUI(CountdownTimeSpan); if (PreventSystemSleep) { ExceptionHandler.LogEvent("[Countdown] Executing sleep prevention by setting the EXECUTION_STATE flags"); ExecutionState.SetThreadExecutionState(ExecutionState.EXECUTION_STATE.ES_CONTINUOUS | ExecutionState.EXECUTION_STATE.ES_SYSTEM_REQUIRED); } // give the system some coffee so it stays awake when tired using some fancy EXECUTION_STATE flags ExceptionHandler.LogEvent("[Countdown] Entering countdown sequence..."); }