From be49058e8cca7c40aa393ae27eca8b0cae67dbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 7 Aug 2017 09:42:12 +0200 Subject: [PATCH] Split keyboard and mouse interceptor to separate operations to avoid mouse lagg during startup / shutdown. --- SafeExamBrowser.Contracts/I18n/TextKey.cs | 4 ++ ...ion.cs => KeyboardInterceptorOperation.cs} | 17 +++--- .../Operations/MouseInterceptorOperation.cs | 52 +++++++++++++++++++ ...ation.cs => RuntimeControllerOperation.cs} | 4 +- SafeExamBrowser.Core/I18n/Text.xml | 4 ++ .../SafeExamBrowser.Core.csproj | 5 +- SafeExamBrowser/CompositionRoot.cs | 5 +- 7 files changed, 76 insertions(+), 15 deletions(-) rename SafeExamBrowser.Core/Behaviour/Operations/{DeviceInterceptionOperation.cs => KeyboardInterceptorOperation.cs} (71%) create mode 100644 SafeExamBrowser.Core/Behaviour/Operations/MouseInterceptorOperation.cs rename SafeExamBrowser.Core/Behaviour/Operations/{EventControllerOperation.cs => RuntimeControllerOperation.cs} (88%) diff --git a/SafeExamBrowser.Contracts/I18n/TextKey.cs b/SafeExamBrowser.Contracts/I18n/TextKey.cs index 7cca4c62..234b28fb 100644 --- a/SafeExamBrowser.Contracts/I18n/TextKey.cs +++ b/SafeExamBrowser.Contracts/I18n/TextKey.cs @@ -29,8 +29,12 @@ namespace SafeExamBrowser.Contracts.I18n SplashScreen_RestoreWorkingArea, SplashScreen_ShutdownProcedure, SplashScreen_StartEventHandling, + SplashScreen_StartKeyboardInterception, + SplashScreen_StartMouseInterception, SplashScreen_StartupProcedure, SplashScreen_StopEventHandling, + SplashScreen_StopKeyboardInterception, + SplashScreen_StopMouseInterception, SplashScreen_StopProcessMonitoring, SplashScreen_StopWindowMonitoring, SplashScreen_TerminateBrowser, diff --git a/SafeExamBrowser.Core/Behaviour/Operations/DeviceInterceptionOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/KeyboardInterceptorOperation.cs similarity index 71% rename from SafeExamBrowser.Core/Behaviour/Operations/DeviceInterceptionOperation.cs rename to SafeExamBrowser.Core/Behaviour/Operations/KeyboardInterceptorOperation.cs index 79ba4663..b91b1352 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/DeviceInterceptionOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/KeyboardInterceptorOperation.cs @@ -7,6 +7,7 @@ */ using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface; @@ -14,40 +15,38 @@ using SafeExamBrowser.Contracts.WindowsApi; namespace SafeExamBrowser.Core.Behaviour.Operations { - public class DeviceInterceptionOperation : IOperation + public class KeyboardInterceptorOperation : IOperation { private IKeyboardInterceptor keyboardInterceptor; private ILogger logger; - private IMouseInterceptor mouseInterceptor; private INativeMethods nativeMethods; public ISplashScreen SplashScreen { private get; set; } - public DeviceInterceptionOperation( + public KeyboardInterceptorOperation( IKeyboardInterceptor keyboardInterceptor, ILogger logger, - IMouseInterceptor mouseInterceptor, INativeMethods nativeMethods) { this.keyboardInterceptor = keyboardInterceptor; this.logger = logger; - this.mouseInterceptor = mouseInterceptor; this.nativeMethods = nativeMethods; } public void Perform() { - logger.Info("Starting keyboard and mouse interception..."); + logger.Info("Starting keyboard interception..."); + SplashScreen.UpdateText(TextKey.SplashScreen_StartKeyboardInterception); nativeMethods.RegisterKeyboardHook(keyboardInterceptor); - nativeMethods.RegisterMouseHook(mouseInterceptor); + } public void Revert() { - logger.Info("Stopping keyboard and mouse interception..."); + logger.Info("Stopping keyboard interception..."); + SplashScreen.UpdateText(TextKey.SplashScreen_StopKeyboardInterception); - nativeMethods.DeregisterMouseHook(mouseInterceptor); nativeMethods.DeregisterKeyboardHook(keyboardInterceptor); } } diff --git a/SafeExamBrowser.Core/Behaviour/Operations/MouseInterceptorOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/MouseInterceptorOperation.cs new file mode 100644 index 00000000..7db13822 --- /dev/null +++ b/SafeExamBrowser.Core/Behaviour/Operations/MouseInterceptorOperation.cs @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.WindowsApi; + +namespace SafeExamBrowser.Core.Behaviour.Operations +{ + public class MouseInterceptorOperation : IOperation + { + private ILogger logger; + private IMouseInterceptor mouseInterceptor; + private INativeMethods nativeMethods; + + public ISplashScreen SplashScreen { private get; set; } + + public MouseInterceptorOperation( + ILogger logger, + IMouseInterceptor mouseInterceptor, + INativeMethods nativeMethods) + { + this.logger = logger; + this.mouseInterceptor = mouseInterceptor; + this.nativeMethods = nativeMethods; + } + + public void Perform() + { + logger.Info("Starting mouse interception..."); + SplashScreen.UpdateText(TextKey.SplashScreen_StartMouseInterception); + + nativeMethods.RegisterMouseHook(mouseInterceptor); + } + + public void Revert() + { + logger.Info("Stopping mouse interception..."); + SplashScreen.UpdateText(TextKey.SplashScreen_StopMouseInterception); + + nativeMethods.DeregisterMouseHook(mouseInterceptor); + } + } +} diff --git a/SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs similarity index 88% rename from SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs rename to SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs index c5bfeea3..7eca6b59 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs @@ -13,14 +13,14 @@ using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.Core.Behaviour.Operations { - public class EventControllerOperation : IOperation + public class RuntimeControllerOperation : IOperation { private ILogger logger; private IRuntimeController controller; public ISplashScreen SplashScreen { private get; set; } - public EventControllerOperation(IRuntimeController controller, ILogger logger) + public RuntimeControllerOperation(IRuntimeController controller, ILogger logger) { this.controller = controller; this.logger = logger; diff --git a/SafeExamBrowser.Core/I18n/Text.xml b/SafeExamBrowser.Core/I18n/Text.xml index 61400cf4..af3d7330 100644 --- a/SafeExamBrowser.Core/I18n/Text.xml +++ b/SafeExamBrowser.Core/I18n/Text.xml @@ -14,8 +14,12 @@ Restoring working area Initiating shutdown procedure Starting event handling + Starting keyboard interception + Starting mouse interception Initiating startup procedure Stopping event handling + Stopping keyboard interception + Stopping mouse interception Stopping process monitoring Stopping window monitoring Terminating browser diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index 874d383b..1525377d 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -58,10 +58,11 @@ - + + - + diff --git a/SafeExamBrowser/CompositionRoot.cs b/SafeExamBrowser/CompositionRoot.cs index a844b607..08505f4f 100644 --- a/SafeExamBrowser/CompositionRoot.cs +++ b/SafeExamBrowser/CompositionRoot.cs @@ -77,13 +77,14 @@ namespace SafeExamBrowser StartupController = new StartupController(logger, settings, text, uiFactory); StartupOperations = new Queue(); - StartupOperations.Enqueue(new DeviceInterceptionOperation(keyboardInterceptor, logger, mouseInterceptor, nativeMethods)); + StartupOperations.Enqueue(new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods)); StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); StartupOperations.Enqueue(new WorkingAreaOperation(logger, Taskbar, workingArea)); StartupOperations.Enqueue(new TaskbarOperation(logger, settings, Taskbar, text, uiFactory)); StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); - StartupOperations.Enqueue(new EventControllerOperation(runtimeController, logger)); + StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, logger)); + StartupOperations.Enqueue(new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods)); } } }