From 2efe651ffb49e3f1e51ba706eeff2a71b548d09d Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Mon, 30 Dec 2024 18:01:13 -0600 Subject: [PATCH] added display factory test for desktop --- .../desktop/Meadow.Desktop/Desktop.cs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Source/implementations/desktop/Meadow.Desktop/Desktop.cs b/Source/implementations/desktop/Meadow.Desktop/Desktop.cs index 551dab06..95bdac33 100644 --- a/Source/implementations/desktop/Meadow.Desktop/Desktop.cs +++ b/Source/implementations/desktop/Meadow.Desktop/Desktop.cs @@ -13,6 +13,7 @@ public class Desktop : IMeadowDevice { private IMeadowDevice _implementation = default!; private IResizablePixelDisplay? _display; + private Func _displayFactory; /// public event NetworkConnectionHandler? NetworkConnected; @@ -22,17 +23,25 @@ public class Desktop : IMeadowDevice /// /// Gets or sets the display associated with the desktop. /// - public virtual IResizablePixelDisplay? Display + public virtual IResizablePixelDisplay? Display => _display ??= DisplayFactory(); + + private IResizablePixelDisplay? GenerateDefaultDisplay() { - get + if (_implementation is IPixelDisplayProvider displayProvider) { - if (_implementation is IPixelDisplayProvider displayProvider) - { - return _display ??= displayProvider.CreateDisplay(); - } - - return null; + return displayProvider.CreateDisplay(); } + + return null; + } + + /// + /// Override this property to provide a non-default factory method for generating the platform Display + /// + public virtual Func DisplayFactory + { + get => _displayFactory; + set => _displayFactory = value; } /// @@ -40,11 +49,13 @@ public virtual IResizablePixelDisplay? Display /// public Desktop() { + _displayFactory = GenerateDefaultDisplay; } /// public void Initialize(MeadowPlatform detectedPlatform) { + _implementation = detectedPlatform switch { MeadowPlatform.OSX => new Mac(),