Skip to content

Commit

Permalink
Merge pull request #16 from miloszwasacz/dev
Browse files Browse the repository at this point in the history
Hotfix v1.0.1
  • Loading branch information
miloszwasacz authored May 31, 2024
2 parents 9da0bf5 + 48c515f commit da53e21
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public Layout GetLayout(IViewModelProvider vmProvider, Hotspot.Media hotspot) =>
public Layout GetWelcomeLayout() =>
new MockSimpleDescriptionLayout(WelcomeViewModel.WelcomeTitle, WelcomeViewModel.WelcomeMessage);

/// <returns>
/// A new <see cref="MockSimpleDescriptionLayout" /> with the given title and description.
/// </returns>
public Layout GetMessageLayout(string title, string description) =>
new MockSimpleDescriptionLayout(title, description);

/// <returns>A new <see cref="MockSimpleDescriptionLayout" /> with the given title and message.</returns>
public Layout GetErrorLayout(string message, string title = ILayoutProvider.DefaultErrorTitle) =>
new MockSimpleDescriptionLayout(title, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public void OnHotspotActivated(object? sender, IHotspotHandler.HotspotArgs e)
/// <summary>
/// Calls <see cref="INavigator.OpenEditor" /> on <see cref="_navigator" />
/// </summary>
public void OpenEditor()
public Task OpenEditor()
{
_navigator.OpenEditor();
return Task.CompletedTask;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public async Task OnHotspotActivatedExceptionTest((Exception, string) testCase)
}

[Test]
public void OpenEditorTest()
[Timeout(5000)]
public async Task OpenEditorTest()
{
var navigator = new MockNavigator();
var contentProvider = new MockContentProvider(FilesAll);
Expand All @@ -353,7 +354,7 @@ public void OpenEditorTest()
hotspotHandler,
new MockLoggerFactory()
);
displayViewModel.OpenEditor();
await displayViewModel.OpenEditor();

Assert.That(navigator.IsEditorOpen, Is.True);
}
Expand Down
2 changes: 1 addition & 1 deletion WallProjections/Helper/Interfaces/IHotspotHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IHotspotHandler : IDisposable
/// <summary>
/// The total time required to activate a hotspot.
/// </summary>
public static readonly TimeSpan ActivationTime = TimeSpan.FromSeconds(2);
public static readonly TimeSpan ActivationTime = TimeSpan.FromSeconds(1);

/// <summary>
/// The total time required to deactivate a hotspot.
Expand Down
54 changes: 49 additions & 5 deletions WallProjections/ViewModels/Display/DisplayViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Avalonia.Threading;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using WallProjections.Helper.Interfaces;
Expand Down Expand Up @@ -57,6 +58,14 @@ public sealed class DisplayViewModel : ViewModelBase, IDisplayViewModel
/// </summary>
private Layout _contentViewModel;

/// <summary>
/// Whether the Display is performing cleanup and closing
/// </summary>
/// <remarks>
/// Remember to use <i>lock (this)</i> when accessing this field
/// </remarks>
private bool _closing;

/// <inheritdoc />
/// <remarks>
/// Remember to use <i>lock (this)</i> when accessing this property
Expand Down Expand Up @@ -111,7 +120,7 @@ public async void OnHotspotActivated(object? sender, IHotspotHandler.HotspotArgs
{
lock (this)
{
if (ContentViewModel.HotspotId == e.Id) return;
if (ContentViewModel.HotspotId == e.Id || _closing) return;

_logger.LogTrace("Activating layout for hotspot with id {HotspotId}", e.Id);
ShowHotspot(e.Id);
Expand All @@ -127,7 +136,7 @@ private void OnLayoutDeactivated(object? sender, Layout.DeactivationEventArgs e)
{
lock (this)
{
if (!ContentViewModel.IsDeactivated(e)) return;
if (!ContentViewModel.IsDeactivated(e) || _closing) return;

_logger.LogTrace("Deactivating layout for hotspot with id {HotspotId}", ContentViewModel.HotspotId);
ShowWelcomeScreen();
Expand Down Expand Up @@ -180,12 +189,47 @@ private void ShowWelcomeScreen()
ContentViewModel = _layoutProvider.GetWelcomeLayout();
}

/// <inheritdoc />
public void OpenEditor()
/// <summary>
/// Disposes of the current <see cref="ContentViewModel" /> (if any and is <see cref="IDisposable" />)
/// and shows message screen informing the user about Python cleanup
/// </summary>
/// <remarks>
/// Remember to use <i>lock (this)</i> when calling this method
/// </remarks>
private void ShowCleanupMessage()
{
_navigator.OpenEditor();
if (ContentViewModel.HotspotId is not null)
_hotspotHandler.DeactivateHotspot(ContentViewModel.HotspotId.Value);

if (ContentViewModel is IDisposable disposable)
disposable.Dispose();

var (title, description) = IDisplayViewModel.CleanupMessage;
ContentViewModel = _layoutProvider.GetMessageLayout(title, description);
}

/// <inheritdoc />
public Task OpenEditor() => Task.Run(async () =>
{
lock (this)
{
_closing = true;
}

Dispatcher.UIThread.Invoke(() =>
{
lock (this)
{
ShowCleanupMessage();
}
});

// Wait for the cleanup message to be properly displayed
await Task.Delay(500);

Dispatcher.UIThread.Invoke(() => _navigator.OpenEditor());
});

/// <inheritdoc />
public void CloseDisplay()
{
Expand Down
3 changes: 3 additions & 0 deletions WallProjections/ViewModels/Display/Layouts/LayoutProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public Layout GetLayout(IViewModelProvider vmProvider, Hotspot.Media hotspot)
/// <inheritdoc />
public Layout GetWelcomeLayout() => new WelcomeViewModel();

/// <inheritdoc />
public Layout GetMessageLayout(string title, string description) => new MessageViewModel(title, description);

/// <inheritdoc />
public Layout GetErrorLayout(string message, string title = ILayoutProvider.DefaultErrorTitle) =>
new ErrorViewModel(title, message);
Expand Down
27 changes: 27 additions & 0 deletions WallProjections/ViewModels/Display/Layouts/MessageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using WallProjections.ViewModels.Interfaces.Display.Layouts;

namespace WallProjections.ViewModels.Display.Layouts;

/// <summary>
/// A viewmodel for a view that displays a message with a title and description.
/// </summary>
public class MessageViewModel : DescriptionViewModel
{
/// <summary>
/// Creates a new <see cref="MessageViewModel" /> with the given <paramref name="title" /> and <paramref name="description" />.
/// </summary>
/// <param name="title">The message title.</param>
/// <param name="description">The full description.</param>
/// <param name="deactivateAfter">
/// The time after which the layout should deactivate.
/// If <i>null</i>, the layout will deactivate after the <see cref="Layout.DefaultDeactivationTime">default time</see>.
/// </param>
public MessageViewModel(
string title,
string description,
TimeSpan? deactivateAfter = null
) : base(title, description, deactivateAfter ?? DefaultDeactivationTime)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using WallProjections.Helper.Interfaces;
using WallProjections.Models;
using WallProjections.ViewModels.Interfaces.Display.Layouts;
Expand All @@ -12,6 +13,11 @@ namespace WallProjections.ViewModels.Interfaces.Display;
/// </summary>
public interface IDisplayViewModel : IDisposable
{
public static readonly (string Title, string Description) CleanupMessage = (
"Closing content display",
"The hand tracking is stopping.\nPlease wait..."
);

/// <summary>
/// Event callback for when a <see cref="Hotspot" /> has been activated.
/// </summary>
Expand All @@ -28,7 +34,7 @@ public interface IDisplayViewModel : IDisposable
/// <summary>
/// Opens the <see cref="EditorWindow">Editor</see>.
/// </summary>
public void OpenEditor();
public Task OpenEditor();

/// <summary>
/// Closes the <see cref="DisplayWindow">Display</see>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public interface ILayoutProvider
/// </summary>
public Layout GetWelcomeLayout();

/// <summary>
/// Gets a layout with a message.
/// </summary>
/// <param name="title">The message title.</param>
/// <param name="description">The full description.</param>
public Layout GetMessageLayout(string title, string description);

/// <summary>
/// Gets a layout with an error message.
/// </summary>
Expand Down
10 changes: 6 additions & 4 deletions WallProjections/ViewModels/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,17 @@ private void Navigate(Window newWindow, bool showSecondary)
{
var currentWindow = MainWindow;

if (showSecondary)
OpenSecondaryWindow();
newWindow.Show();
MainWindow = newWindow;

if (showSecondary) OpenSecondaryWindow();
else
{
_secondaryScreen.window.ShowInTaskbar = false;
_secondaryScreen.window.Hide();
}

newWindow.Show();
MainWindow = newWindow;
newWindow.Activate();

currentWindow?.CloseAndDispose();
}
Expand All @@ -341,6 +342,7 @@ private void OpenSecondaryWindow()
window.WindowStartupLocation = WindowStartupLocation.Manual;
window.Position = secondaryScreen.Bounds.Position;
window.Show();
window.WindowState = WindowState.Maximized;
window.WindowState = WindowState.FullScreen;
}
else
Expand Down
4 changes: 2 additions & 2 deletions WallProjections/Views/Display/DisplayWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DisplayWindow()
/// </summary>
/// <param name="sender">The sender of the event (unused).</param>
/// <param name="e">The event arguments containing the key that was pressed.</param>
internal void OnKeyDown(object? sender, KeyEventArgs e)
internal async void OnKeyDown(object? sender, KeyEventArgs e)
{
// Ignore handled events and ones with key modifiers
if (e.Handled || e.KeyModifiers != KeyModifiers.None) return;
Expand All @@ -69,7 +69,7 @@ internal void OnKeyDown(object? sender, KeyEventArgs e)
// Open the editor
case Key.E:
{
viewModel.OpenEditor();
await viewModel.OpenEditor();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion WallProjections/Views/HotspotCircle.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void UpdateArcTransition(TimeSpan newDuration)
var current = OuterArc.SweepAngle;
var transitions = new Transitions
{
ResetBehavior = ResetBehavior.Remove
ResetBehavior = ResetBehavior.Reset
};
transitions.Add(new DoubleTransition
{
Expand Down

0 comments on commit da53e21

Please sign in to comment.