private void SystemMonitor_SessionSwitched() { var message = text.Get(TextKey.LockScreen_UserSessionMessage); var title = text.Get(TextKey.LockScreen_Title); var continueOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionContinueOption) }; var terminateOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionTerminateOption) }; logger.Warn("Detected user session switch!"); if (!sessionLocked) { sessionLocked = true; var result = ShowLockScreen(message, title, new[] { continueOption, terminateOption }); if (result.OptionId == terminateOption.Id) { logger.Info("Attempting to shutdown as requested by the user..."); TryRequestShutdown(); } sessionLocked = false; } else { logger.Info("Lock screen is already active."); } }
private void ApplicationMonitor_TerminationFailed(IEnumerable <RunningApplication> applications) { var applicationList = string.Join(Environment.NewLine, applications.Select(a => $"- {a.Name}")); var message = $"{text.Get(TextKey.LockScreen_Message)}{Environment.NewLine}{Environment.NewLine}{applicationList}"; var title = text.Get(TextKey.LockScreen_Title); var hasQuitPassword = !string.IsNullOrEmpty(Settings.Security.QuitPasswordHash); var allowOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_AllowOption) }; var terminateOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_TerminateOption) }; var lockScreen = uiFactory.CreateLockScreen(message, title, new [] { allowOption, terminateOption }); var result = default(LockScreenResult); logger.Warn("Showing lock screen due to failed termination of blacklisted application(s)!"); PauseActivators(); lockScreen.Show(); for (var unlocked = false; !unlocked;) { result = lockScreen.WaitForResult(); if (hasQuitPassword) { var passwordHash = hashAlgorithm.GenerateHashFor(result.Password); var isCorrect = Settings.Security.QuitPasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase); if (isCorrect) { logger.Info("The user entered the correct unlock password."); unlocked = true; } else { logger.Info("The user entered the wrong unlock password."); messageBox.Show(TextKey.MessageBox_InvalidUnlockPassword, TextKey.MessageBox_InvalidUnlockPasswordTitle, icon: MessageBoxIcon.Warning, parent: lockScreen); } } else { logger.Warn($"No unlock password is defined, allowing user to resume session!"); unlocked = true; } } lockScreen.Close(); ResumeActivators(); logger.Info("Closed lock screen."); if (result.OptionId == allowOption.Id) { logger.Info($"The blacklisted application(s) {string.Join(", ", applications.Select(a => $"'{a.Name}'"))} will be temporarily allowed."); } else if (result.OptionId == terminateOption.Id) { logger.Info("Attempting to shutdown as requested by the user..."); TryRequestShutdown(); } }
private void ApplicationMonitor_TerminationFailed(IEnumerable <RunningApplication> applications) { var applicationList = string.Join(Environment.NewLine, applications.Select(a => $"- {a.Name}")); var message = $"{text.Get(TextKey.LockScreen_ApplicationsMessage)}{Environment.NewLine}{Environment.NewLine}{applicationList}"; var title = text.Get(TextKey.LockScreen_Title); var allowOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_ApplicationsAllowOption) }; var terminateOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_ApplicationsTerminateOption) }; logger.Warn("Detected termination failure of blacklisted application(s)!"); var result = ShowLockScreen(message, title, new[] { allowOption, terminateOption }); if (result.OptionId == allowOption.Id) { logger.Info($"The blacklisted application(s) {string.Join(", ", applications.Select(a => $"'{a.Name}'"))} will be temporarily allowed."); } else if (result.OptionId == terminateOption.Id) { logger.Info("Attempting to shutdown as requested by the user..."); TryRequestShutdown(); } }
private void SystemMonitor_SessionSwitched() { var allow = !Settings.Service.IgnoreService && (!Settings.Service.DisableUserLock || !Settings.Service.DisableUserSwitch); var message = text.Get(TextKey.LockScreen_UserSessionMessage); var title = text.Get(TextKey.LockScreen_Title); var continueOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionContinueOption) }; var terminateOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionTerminateOption) }; if (allow) { logger.Info("Detected user session switch, but user lock and/or user switch are allowed."); } else { logger.Warn("Detected user session switch!"); if (!sessionLocked) { sessionLocked = true; var result = ShowLockScreen(message, title, new[] { continueOption, terminateOption }); if (result.OptionId == terminateOption.Id) { logger.Info("Attempting to shutdown as requested by the user..."); TryRequestShutdown(); } sessionLocked = false; } else { logger.Info("Lock screen is already active."); } } }