changed Initialize to be synchronous

This commit is contained in:
Ell 2021-05-02 19:34:21 +02:00
parent 3ee8c4deca
commit 92e8a8e6f5
5 changed files with 14 additions and 14 deletions

View file

@ -6,8 +6,8 @@ using Illumilib;
namespace Demo {
internal static class Program {
private static async Task Main(string[] args) {
await IllumilibLighting.Initialize();
private static void Main(string[] args) {
IllumilibLighting.Initialize();
Console.WriteLine("Setting specific positions");
IllumilibLighting.SetKeyboardLighting(0, 1, 0);

View file

@ -28,18 +28,18 @@ namespace Illumilib {
/// <summary>
/// Initializes Illumilib, starting all of the supported lighting systems.
/// Any lighting systems that are not supported, or for which devices are not present, will be ignored.
/// This function runs asynchronously.
/// </summary>
/// <returns>Whether at least one lighting system was successfully initialized</returns>
/// <exception cref="InvalidOperationException">Thrown if Illumilib has already been <see cref="Initialized"/></exception>
public static async Task Initialize() {
public static bool Initialize() {
if (Initialized)
throw new InvalidOperationException("Illumilib has already been initialized");
var ret = new List<LightingSystem>();
systems = new List<LightingSystem>();
foreach (var system in new LightingSystem[] {new LogitechLighting(), new RazerLighting()}) {
if (await system.Initialize())
ret.Add(system);
if (system.Initialize())
systems.Add(system);
}
systems = ret;
return systems.Count > 0;
}
/// <summary>

View file

@ -4,7 +4,7 @@ using System.Threading.Tasks;
namespace Illumilib.System {
internal abstract class LightingSystem : IDisposable {
public abstract Task<bool> Initialize();
public abstract bool Initialize();
public abstract void Dispose();

View file

@ -7,12 +7,12 @@ namespace Illumilib.System {
private readonly byte[] bitmap = new byte[LogitechGsdk.LogiLedBitmapSize];
private bool bitmapDirty;
public override Task<bool> Initialize() {
public override bool Initialize() {
try {
LogitechGsdk.LogiLedInit();
return Task.FromResult(true);
return true;
} catch {
return Task.FromResult(false);
return false;
}
}

View file

@ -10,9 +10,9 @@ namespace Illumilib.System {
private CustomKeyboardEffect effect = new CustomKeyboardEffect(Color.Black);
private bool effectOutdated;
public override async Task<bool> Initialize() {
public override bool Initialize() {
try {
this.chroma = await ColoreProvider.CreateNativeAsync();
this.chroma = ColoreProvider.CreateNativeAsync().Result;
return true;
} catch {
return false;