From 92e8a8e6f5e20181f82577ba2361a225b4a5adf7 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 2 May 2021 19:34:21 +0200 Subject: [PATCH] changed Initialize to be synchronous --- Demo/Program.cs | 4 ++-- Illumilib/IllumilibLighting.cs | 12 ++++++------ Illumilib/System/LightingSystem.cs | 2 +- Illumilib/System/LogitechLighting.cs | 6 +++--- Illumilib/System/RazerLighting.cs | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Demo/Program.cs b/Demo/Program.cs index ec5fd46..4fb9b36 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -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); diff --git a/Illumilib/IllumilibLighting.cs b/Illumilib/IllumilibLighting.cs index 9673a14..4a304e2 100644 --- a/Illumilib/IllumilibLighting.cs +++ b/Illumilib/IllumilibLighting.cs @@ -28,18 +28,18 @@ namespace Illumilib { /// /// 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. /// + /// Whether at least one lighting system was successfully initialized /// Thrown if Illumilib has already been - public static async Task Initialize() { + public static bool Initialize() { if (Initialized) throw new InvalidOperationException("Illumilib has already been initialized"); - var ret = new List(); + systems = new List(); 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; } /// diff --git a/Illumilib/System/LightingSystem.cs b/Illumilib/System/LightingSystem.cs index 8dae9d9..4ef2bb4 100644 --- a/Illumilib/System/LightingSystem.cs +++ b/Illumilib/System/LightingSystem.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace Illumilib.System { internal abstract class LightingSystem : IDisposable { - public abstract Task Initialize(); + public abstract bool Initialize(); public abstract void Dispose(); diff --git a/Illumilib/System/LogitechLighting.cs b/Illumilib/System/LogitechLighting.cs index 2da4be3..437b20c 100644 --- a/Illumilib/System/LogitechLighting.cs +++ b/Illumilib/System/LogitechLighting.cs @@ -7,12 +7,12 @@ namespace Illumilib.System { private readonly byte[] bitmap = new byte[LogitechGsdk.LogiLedBitmapSize]; private bool bitmapDirty; - public override Task Initialize() { + public override bool Initialize() { try { LogitechGsdk.LogiLedInit(); - return Task.FromResult(true); + return true; } catch { - return Task.FromResult(false); + return false; } } diff --git a/Illumilib/System/RazerLighting.cs b/Illumilib/System/RazerLighting.cs index 78bba3d..3a3f425 100644 --- a/Illumilib/System/RazerLighting.cs +++ b/Illumilib/System/RazerLighting.cs @@ -10,9 +10,9 @@ namespace Illumilib.System { private CustomKeyboardEffect effect = new CustomKeyboardEffect(Color.Black); private bool effectOutdated; - public override async Task Initialize() { + public override bool Initialize() { try { - this.chroma = await ColoreProvider.CreateNativeAsync(); + this.chroma = ColoreProvider.CreateNativeAsync().Result; return true; } catch { return false;