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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using Artemis.DeviceProviders;
|
using Artemis.DeviceProviders;
|
||||||
using Artemis.Events;
|
using Artemis.Events;
|
||||||
using Artemis.Services;
|
using Artemis.Services;
|
||||||
@ -93,33 +94,59 @@ namespace Artemis.Managers
|
|||||||
|
|
||||||
if (!wasNull)
|
if (!wasNull)
|
||||||
ReleaseActiveKeyboard();
|
ReleaseActiveKeyboard();
|
||||||
|
bool asynchEnable = false;
|
||||||
// Disable everything if there's no active keyboard found
|
if (keyboardProvider.CanEnable())
|
||||||
if (!keyboardProvider.CanEnable())
|
|
||||||
{
|
{
|
||||||
DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
|
FinishEnableKeyboard(keyboardProvider, oldKeyboard);
|
||||||
ActiveKeyboard = null;
|
|
||||||
General.Default.LastKeyboard = null;
|
|
||||||
General.Default.Save();
|
|
||||||
_logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name);
|
|
||||||
ChangingKeyboard = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
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;
|
if (!asynchEnable)
|
||||||
ActiveKeyboard.Enable();
|
{
|
||||||
|
// Disable everything if there's no active keyboard found
|
||||||
General.Default.LastKeyboard = ActiveKeyboard.Name;
|
DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
|
||||||
General.Default.Save();
|
ActiveKeyboard = null;
|
||||||
|
General.Default.LastKeyboard = null;
|
||||||
EnableUsableDevices();
|
General.Default.Save();
|
||||||
|
_logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name);
|
||||||
ChangingKeyboard = false;
|
ChangingKeyboard = false;
|
||||||
_events.PublishOnUIThread(new ActiveKeyboardChanged(oldKeyboard, ActiveKeyboard));
|
return;
|
||||||
_logger.Debug("Enabled keyboard: {0}", keyboardProvider.Name);
|
}
|
||||||
|
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()
|
private void EnableUsableDevices()
|
||||||
{
|
{
|
||||||
foreach (var mouseProvider in MiceProviders)
|
foreach (var mouseProvider in MiceProviders)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user