diff --git a/Illumilib/IllumilibLighting.cs b/Illumilib/IllumilibLighting.cs index 89c9e72..d004ce5 100644 --- a/Illumilib/IllumilibLighting.cs +++ b/Illumilib/IllumilibLighting.cs @@ -11,15 +11,19 @@ namespace Illumilib { public static class IllumilibLighting { private static List systems; + /// + /// A property that returns whether Illumilib is currently initialized + /// + public static bool Initialized => systems != null; /// /// 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. /// - /// Thrown if Illumilib has already been initialized + /// Thrown if Illumilib has already been public static async Task Initialize() { - if (systems != null) + if (Initialized) throw new InvalidOperationException("Illumilib has already been initialized"); var ret = new List(); foreach (var system in new LightingSystem[] {new LogitechLighting(), new RazerLighting()}) { @@ -33,6 +37,8 @@ namespace Illumilib { /// Disposes Illumilib, disposing all of the underlying lighting systems /// public static void Dispose() { + if (!Initialized) + return; ForEach(s => s.Dispose()); systems = null; } @@ -81,7 +87,7 @@ namespace Illumilib { } private static void ForEach(Action action) { - if (systems == null) + if (!Initialized) throw new InvalidOperationException("Illumilib has not been initialized yet"); foreach (var system in systems) action(system);