Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added display factory test for desktop #596

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions Source/implementations/desktop/Meadow.Desktop/Desktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Desktop : IMeadowDevice
{
private IMeadowDevice _implementation = default!;
private IResizablePixelDisplay? _display;
private Func<IResizablePixelDisplay?> _displayFactory;

/// <inheritdoc/>
public event NetworkConnectionHandler? NetworkConnected;
Expand All @@ -22,29 +23,39 @@ public class Desktop : IMeadowDevice
/// <summary>
/// Gets or sets the display associated with the desktop.
/// </summary>
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;
}

/// <summary>
/// Override this property to provide a non-default factory method for generating the platform Display
/// </summary>
public virtual Func<IResizablePixelDisplay?> DisplayFactory
{
get => _displayFactory;
set => _displayFactory = value;
}

/// <summary>
/// Initializes a new instance of the Desktop class.
/// </summary>
public Desktop()
{
_displayFactory = GenerateDefaultDisplay;
}

/// <inheritdoc/>
public void Initialize(MeadowPlatform detectedPlatform)
{

_implementation = detectedPlatform switch
{
MeadowPlatform.OSX => new Mac(),
Expand Down
Loading