예제 #1
0
        public async Task WatcherRaisesTheChangedEventOnStart()
        {
            using var watcher = new BindingsWatcher(_gif, _gof);
            var evs = new EventCollector <BindingPreset>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart));

            var binds = await evs.WaitAsync(() =>
            {
                watcher.Start();
                watcher.Stop();
            }).ConfigureAwait(false);

            Assert.Null(binds.PresetName); // "Custom" and "Custom2" get merged to null.
            Assert.Equal(new Version(3, 0), binds.Version);
            Assert.Equal("es-ES", binds.KeyboardLayout);

            var k = binds.Bindings["Supercruise"].Primary;

            Assert.Equal("Keyboard", k.Device);
            Assert.Equal("Key_H", k.Key);
            Assert.Equal(2, k.Modifiers.Count);
            var modifiers = k.Modifiers.OrderBy(x => x.Key).ToList();

            Assert.Equal("Keyboard", modifiers[0].Device);
            Assert.Equal("Key_LeftAlt", modifiers[0].Key);
            Assert.Equal("Keyboard", modifiers[1].Device);
            Assert.Equal("Key_LeftShift", modifiers[1].Key);
        }
예제 #2
0
        public void StartAndStopAreNotReentrant()
        {
            using var watcher = new BindingsWatcher(_gif, _gof);

            bool IsRunning() => watcher.GetPrivateField <bool>("_running");

            Assert.False(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Start();
            Assert.True(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());

            watcher.Stop();
            Assert.False(IsRunning());
        }
        public void Stop()
        {
            if (!_running)
            {
                return;
            }

            _running = false;

            _modifierKeysWatcher.Stop();
            _journalWatcher.Stop();
            _statusWatcher.Stop();
            _bindingsWatcher.Stop();
            _graphicsConfig.Stop();
            _gameProcessWatcher.Stop();
        }