mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
First attempt at fix for isasue 93. 10 attempts to reconnect, 500 MS between each.
This commit is contained in:
parent
af75f2e44d
commit
82b2607911
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Artemis.DeviceProviders;
|
||||
using Artemis.Events;
|
||||
using Artemis.Services;
|
||||
@ -93,33 +94,59 @@ namespace Artemis.Managers
|
||||
|
||||
if (!wasNull)
|
||||
ReleaseActiveKeyboard();
|
||||
|
||||
// Disable everything if there's no active keyboard found
|
||||
if (!keyboardProvider.CanEnable())
|
||||
bool asynchEnable = false;
|
||||
if (keyboardProvider.CanEnable())
|
||||
{
|
||||
DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
|
||||
ActiveKeyboard = null;
|
||||
General.Default.LastKeyboard = null;
|
||||
General.Default.Save();
|
||||
_logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name);
|
||||
ChangingKeyboard = false;
|
||||
return;
|
||||
FinishEnableKeyboard(keyboardProvider, oldKeyboard);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
var thread = new Thread(
|
||||
() =>
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
asynchEnable = keyboardProvider.CanEnable();
|
||||
});
|
||||
_logger.Warn("Failed enabling keyboard: {0}, re-attempt {1} of 10", keyboardProvider.Name, i);
|
||||
thread.Start();
|
||||
if (asynchEnable)
|
||||
break;
|
||||
}
|
||||
|
||||
ActiveKeyboard = keyboardProvider;
|
||||
ActiveKeyboard.Enable();
|
||||
|
||||
General.Default.LastKeyboard = ActiveKeyboard.Name;
|
||||
General.Default.Save();
|
||||
|
||||
EnableUsableDevices();
|
||||
|
||||
ChangingKeyboard = false;
|
||||
_events.PublishOnUIThread(new ActiveKeyboardChanged(oldKeyboard, ActiveKeyboard));
|
||||
_logger.Debug("Enabled keyboard: {0}", keyboardProvider.Name);
|
||||
if (!asynchEnable)
|
||||
{
|
||||
// Disable everything if there's no active keyboard found
|
||||
DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
|
||||
ActiveKeyboard = null;
|
||||
General.Default.LastKeyboard = null;
|
||||
General.Default.Save();
|
||||
_logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name);
|
||||
ChangingKeyboard = false;
|
||||
return;
|
||||
}
|
||||
FinishEnableKeyboard(keyboardProvider, oldKeyboard);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void FinishEnableKeyboard(KeyboardProvider keyboardProvider, KeyboardProvider oldKeyboard)
|
||||
{
|
||||
ActiveKeyboard = keyboardProvider;
|
||||
ActiveKeyboard.Enable();
|
||||
|
||||
General.Default.LastKeyboard = ActiveKeyboard.Name;
|
||||
General.Default.Save();
|
||||
|
||||
EnableUsableDevices();
|
||||
|
||||
ChangingKeyboard = false;
|
||||
_events.PublishOnUIThread(new ActiveKeyboardChanged(oldKeyboard, ActiveKeyboard));
|
||||
_logger.Debug("Enabled keyboard: {0}", keyboardProvider.Name);
|
||||
}
|
||||
|
||||
private void EnableUsableDevices()
|
||||
{
|
||||
foreach (var mouseProvider in MiceProviders)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user