Skip to content

Commit

Permalink
Custom actions part impl
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 9, 2024
1 parent e330926 commit 735c9ed
Show file tree
Hide file tree
Showing 9 changed files with 1,139 additions and 990 deletions.
80 changes: 39 additions & 41 deletions plugin_OpenVR/ConfirmationFlyout.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using System.Threading.Tasks;
using Amethyst.Plugins.Contract;
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;

// To learn more about WinUI, the WinUI project structure,
Expand All @@ -24,45 +18,18 @@ namespace plugin_OpenVR;

public sealed class ConfirmationFlyout : Flyout
{
private Button ConfirmButton { get; }
private Button CancelButton { get; }
private bool ConfirmationFlyoutResult { get; set; }

private static SemaphoreSlim FlyoutExitSemaphore { get; } = new(0);

public static async Task<bool> HandleButtonConfirmationFlyout(
UIElement showAtElement, IAmethystHost host,
string content, string confirmButtonText, string cancelButtonText)
{
var flyout = new ConfirmationFlyout(content, confirmButtonText, cancelButtonText);

flyout.Closed += (_, _) => FlyoutExitSemaphore.Release();
flyout.Opening += (_, _) => host?.PlayAppSound(SoundType.Show);
flyout.Closing += (_, _) => host?.PlayAppSound(SoundType.Hide);

// Show the confirmation flyout
flyout.ShowAt(showAtElement, new FlyoutShowOptions { Placement = FlyoutPlacementMode.Bottom });

// Wait for the flyout to close
await FlyoutExitSemaphore.WaitAsync();

// Wait a bit
await Task.Delay(1200);

// Return the result
return flyout.ConfirmationFlyoutResult;
}

public ConfirmationFlyout(string content, string confirmButtonText, string cancelButtonText)
{
ConfirmButton = new Button
{
Content = confirmButtonText,
Visibility = (Visibility)Convert.ToInt32(string.IsNullOrEmpty(confirmButtonText)),
FontSize = 15, FontWeight = FontWeights.SemiBold,
FontSize = 15,
FontWeight = FontWeights.SemiBold,
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
Height = 33, Margin = new Thickness(0, 10, 5, 0),
Height = 33,
Margin = new Thickness(0, 10, 5, 0),
CornerRadius = new CornerRadius(4),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Expand All @@ -73,10 +40,12 @@ public ConfirmationFlyout(string content, string confirmButtonText, string cance
{
Content = cancelButtonText,
Visibility = (Visibility)Convert.ToInt32(string.IsNullOrEmpty(cancelButtonText)),
FontSize = 15, FontWeight = FontWeights.SemiBold,
FontSize = 15,
FontWeight = FontWeights.SemiBold,
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
Height = 33, Margin = new Thickness(5, 10, 0, 0),
Height = 33,
Margin = new Thickness(5, 10, 0, 0),
CornerRadius = new CornerRadius(4),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch
Expand Down Expand Up @@ -125,4 +94,33 @@ public ConfirmationFlyout(string content, string confirmButtonText, string cance
Grid.SetColumn(ConfirmButton, 0);
Grid.SetColumn(CancelButton, 1);
}

private Button ConfirmButton { get; }
private Button CancelButton { get; }
private bool ConfirmationFlyoutResult { get; set; }

private static SemaphoreSlim FlyoutExitSemaphore { get; } = new(0);

public static async Task<bool> HandleButtonConfirmationFlyout(
UIElement showAtElement, IAmethystHost host,
string content, string confirmButtonText, string cancelButtonText)
{
var flyout = new ConfirmationFlyout(content, confirmButtonText, cancelButtonText);

flyout.Closed += (_, _) => FlyoutExitSemaphore.Release();
flyout.Opening += (_, _) => host?.PlayAppSound(SoundType.Show);
flyout.Closing += (_, _) => host?.PlayAppSound(SoundType.Hide);

// Show the confirmation flyout
flyout.ShowAt(showAtElement, new FlyoutShowOptions { Placement = FlyoutPlacementMode.Bottom });

// Wait for the flyout to close
await FlyoutExitSemaphore.WaitAsync();

// Wait a bit
await Task.Delay(1200);

// Return the result
return flyout.ConfirmationFlyoutResult;
}
}
8 changes: 4 additions & 4 deletions plugin_OpenVR/CoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ internal class DriverInstaller : IDependencyInstaller

public List<IDependency> ListDependencies()
{
return new List<IDependency>
{
return
[
new VrDriver
{
Host = Host,
Name = Host?.RequestLocalizedString("/Dependencies/Driver") ?? "OpenVR Driver"
}
};
];
}

public List<IFix> ListFixes() => new();
public List<IFix> ListFixes() => [];
}

internal class VrDriver : IDependency
Expand Down
Loading

0 comments on commit 735c9ed

Please sign in to comment.