Skip to content

Commit

Permalink
Ava: Fix nca extraction window never closing & minor cleanup (Ryujinx…
Browse files Browse the repository at this point in the history
…#4569)

* ava: Remove unused doWhileDeferred parameters

* ava: Minimally improve swkbd dialog

It's currently impossible to get the dialog to redirect focus to the InputBox.

* ava: Fix nca extraction dialog never closing

Also contains some minor cleanup
  • Loading branch information
TSRBerry committed Apr 16, 2023
1 parent c5258cf commit 6dbcdfe
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 185 deletions.
31 changes: 16 additions & 15 deletions Ryujinx.Ava/Common/ApplicationHelper.cs
Expand Up @@ -13,6 +13,7 @@
using LibHac.Tools.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Controls;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common.Logging;
Expand Down Expand Up @@ -152,25 +153,17 @@ public static async Task ExtractSection(NcaSectionType ncaSectionType, string ti
string destination = await folderDialog.ShowAsync(_owner);
var cancellationToken = new CancellationTokenSource();

UpdateWaitWindow waitingDialog = new(
LocaleManager.Instance[LocaleKeys.DialogNcaExtractionTitle],
LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogNcaExtractionMessage, ncaSectionType, Path.GetFileName(titleFilePath)),
cancellationToken);

if (!string.IsNullOrWhiteSpace(destination))
{
Thread extractorThread = new(() =>
{
Dispatcher.UIThread.Post(async () =>
{
UserResult result = await ContentDialogHelper.CreateConfirmationDialog(
LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogNcaExtractionMessage, ncaSectionType, Path.GetFileName(titleFilePath)),
"",
"",
LocaleManager.Instance[LocaleKeys.InputDialogCancel],
LocaleManager.Instance[LocaleKeys.DialogNcaExtractionTitle]);
if (result == UserResult.Cancel)
{
cancellationToken.Cancel();
}
});
Dispatcher.UIThread.Post(waitingDialog.Show);
using FileStream file = new(titleFilePath, FileMode.Open, FileAccess.Read);
Nca mainNca = null;
Expand Down Expand Up @@ -222,6 +215,8 @@ public static async Task ExtractSection(NcaSectionType ncaSectionType, string ti
Dispatcher.UIThread.InvokeAsync(async () =>
{
waitingDialog.Close();
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogNcaExtractionMainNcaNotFoundErrorMessage]);
});
Expand Down Expand Up @@ -263,11 +258,15 @@ public static async Task ExtractSection(NcaSectionType ncaSectionType, string ti
Dispatcher.UIThread.InvokeAsync(async () =>
{
waitingDialog.Close();
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogNcaExtractionCheckLogErrorMessage]);
});
}
else if (resultCode.Value.IsSuccess())
{
Dispatcher.UIThread.Post(waitingDialog.Close);
NotificationHelper.Show(
LocaleManager.Instance[LocaleKeys.DialogNcaExtractionTitle],
$"{titleName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}",
Expand All @@ -284,6 +283,8 @@ public static async Task ExtractSection(NcaSectionType ncaSectionType, string ti
Dispatcher.UIThread.InvokeAsync(async () =>
{
waitingDialog.Close();
await ContentDialogHelper.CreateErrorDialog(ex.Message);
});
}
Expand Down
3 changes: 2 additions & 1 deletion Ryujinx.Ava/UI/Applet/SwkbdAppletDialog.axaml
Expand Up @@ -48,6 +48,7 @@
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Focusable="True"
KeyUp="Message_KeyUp"
Text="{Binding Message}"
TextInput="Message_TextInput"
Expand All @@ -61,4 +62,4 @@
HorizontalAlignment="Stretch"
TextWrapping="Wrap" />
</Grid>
</UserControl>
</UserControl>
45 changes: 8 additions & 37 deletions Ryujinx.Ava/UI/Applet/SwkbdAppletDialog.axaml.cs
Expand Up @@ -45,6 +45,13 @@ public SwkbdAppletDialog()
InitializeComponent();
}

protected override void OnGotFocus(GotFocusEventArgs e)
{
// FIXME: This does not work. Might be a bug in Avalonia with DialogHost
// Currently focus will be redirected to the overlay window instead.
Input.Focus();
}

public string Message { get; set; } = "";
public string MainText { get; set; } = "";
public string SecondaryText { get; set; } = "";
Expand All @@ -59,24 +66,6 @@ public static async Task<(UserResult Result, string Input)> ShowInputDialog(Styl

string input = string.Empty;

var overlay = new ContentDialogOverlayWindow()
{
Height = window.Bounds.Height,
Width = window.Bounds.Width,
Position = window.PointToScreen(new Point())
};

window.PositionChanged += OverlayOnPositionChanged;

void OverlayOnPositionChanged(object sender, PixelPointEventArgs e)
{
overlay.Position = window.PointToScreen(new Point());
}

contentDialog = overlay.ContentDialog;

bool opened = false;

content.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);

content._host = contentDialog;
Expand All @@ -97,25 +86,7 @@ void OverlayOnPositionChanged(object sender, PixelPointEventArgs e)
};
contentDialog.Closed += handler;

overlay.Opened += OverlayOnActivated;

async void OverlayOnActivated(object sender, EventArgs e)
{
if (opened)
{
return;
}

opened = true;

overlay.Position = window.PointToScreen(new Point());

await contentDialog.ShowAsync(overlay);
contentDialog.Closed -= handler;
overlay.Close();
};

await overlay.ShowDialog(window);
await ContentDialogHelper.ShowAsync(contentDialog);

return (result, input);
}
Expand Down
32 changes: 0 additions & 32 deletions Ryujinx.Ava/UI/Controls/InputDialog.axaml

This file was deleted.

57 changes: 0 additions & 57 deletions Ryujinx.Ava/UI/Controls/InputDialog.axaml.cs

This file was deleted.

11 changes: 11 additions & 0 deletions Ryujinx.Ava/UI/Controls/UpdateWaitWindow.axaml.cs
@@ -1,15 +1,26 @@
using Avalonia.Controls;
using Ryujinx.Ava.UI.Windows;
using System.Threading;

namespace Ryujinx.Ava.UI.Controls
{
public partial class UpdateWaitWindow : StyleableWindow
{
public UpdateWaitWindow(string primaryText, string secondaryText, CancellationTokenSource cancellationToken) : this(primaryText, secondaryText)
{
SystemDecorations = SystemDecorations.Full;
ShowInTaskbar = true;

Closing += (_, _) => cancellationToken.Cancel();
}

public UpdateWaitWindow(string primaryText, string secondaryText) : this()
{
PrimaryText.Text = primaryText;
SecondaryText.Text = secondaryText;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
SystemDecorations = SystemDecorations.BorderOnly;
ShowInTaskbar = false;
}

public UpdateWaitWindow()
Expand Down
32 changes: 1 addition & 31 deletions Ryujinx.Ava/UI/Helpers/ContentDialogHelper.cs
Expand Up @@ -27,7 +27,6 @@ public static class ContentDialogHelper
string closeButton,
UserResult primaryButtonResult = UserResult.Ok,
ManualResetEvent deferResetEvent = null,
Func<Window, Task> doWhileDeferred = null,
TypedEventHandler<ContentDialog, ContentDialogButtonClickEventArgs> deferCloseAction = null)
{
UserResult result = UserResult.None;
Expand Down Expand Up @@ -78,12 +77,11 @@ public static class ContentDialogHelper
int iconSymbol,
UserResult primaryButtonResult = UserResult.Ok,
ManualResetEvent deferResetEvent = null,
Func<Window, Task> doWhileDeferred = null,
TypedEventHandler<ContentDialog, ContentDialogButtonClickEventArgs> deferCloseAction = null)
{
Grid content = CreateTextDialogContent(primaryText, secondaryText, iconSymbol);

return await ShowContentDialog(title, content, primaryButton, secondaryButton, closeButton, primaryButtonResult, deferResetEvent, doWhileDeferred, deferCloseAction);
return await ShowContentDialog(title, content, primaryButton, secondaryButton, closeButton, primaryButtonResult, deferResetEvent, deferCloseAction);
}

public async static Task<UserResult> ShowDeferredContentDialog(
Expand Down Expand Up @@ -111,7 +109,6 @@ public static class ContentDialogHelper
iconSymbol,
primaryButton == LocaleManager.Instance[LocaleKeys.InputDialogYes] ? UserResult.Yes : UserResult.Ok,
deferResetEvent,
doWhileDeferred,
DeferClose);

async void DeferClose(ContentDialog sender, ContentDialogButtonClickEventArgs args)
Expand Down Expand Up @@ -236,11 +233,6 @@ private static Grid CreateTextDialogContent(string primaryText, string secondary
primaryButtonResult);
}

internal static UpdateWaitWindow CreateWaitingDialog(string mainText, string secondaryText)
{
return new(mainText, secondaryText);
}

internal static async Task CreateUpdaterInfoDialog(string primary, string secondaryText)
{
await ShowTextDialog(
Expand Down Expand Up @@ -319,28 +311,6 @@ internal static async Task<bool> CreateStopEmulationDialog()
LocaleManager.Instance[LocaleKeys.DialogExitSubMessage]);
}

internal static async Task<string> CreateInputDialog(
string title,
string mainText,
string subText,
uint maxLength = int.MaxValue,
string input = "")
{
var result = await InputDialog.ShowInputDialog(
title,
mainText,
input,
subText,
maxLength);

if (result.Result == UserResult.Ok)
{
return result.Input;
}

return string.Empty;
}

public static async Task<ContentDialogResult> ShowAsync(ContentDialog contentDialog)
{
ContentDialogResult result;
Expand Down
2 changes: 1 addition & 1 deletion Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs
Expand Up @@ -972,7 +972,7 @@ private async Task HandleFirmwareInstallation(string filename)
LocaleManager.Instance[LocaleKeys.InputDialogNo],
LocaleManager.Instance[LocaleKeys.RyujinxConfirm]);

UpdateWaitWindow waitingDialog = ContentDialogHelper.CreateWaitingDialog(dialogTitle, LocaleManager.Instance[LocaleKeys.DialogFirmwareInstallerFirmwareInstallWaitMessage]);
UpdateWaitWindow waitingDialog = new(dialogTitle, LocaleManager.Instance[LocaleKeys.DialogFirmwareInstallerFirmwareInstallWaitMessage]);

if (result == UserResult.Yes)
{
Expand Down
18 changes: 7 additions & 11 deletions Ryujinx.Ava/UI/Windows/ContentDialogOverlayWindow.axaml
@@ -1,4 +1,4 @@
<window:StyleableWindow
<window:StyleableWindow
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -10,20 +10,16 @@
d:DesignHeight="450"
x:Class="Ryujinx.Ava.UI.Windows.ContentDialogOverlayWindow"
Title="ContentDialogOverlayWindow"
Focusable="True">
Focusable="False">
<window:StyleableWindow.Styles>
<Style Selector="ui|ContentDialog /template/ Panel#LayoutRoot">
<Setter Property="Background"
Value="Transparent" />
</Style>
</window:StyleableWindow.Styles>
<ContentControl
Focusable="False"
IsVisible="False"
KeyboardNavigation.IsTabStop="False">
<ui:ContentDialog Name="ContentDialog"
IsPrimaryButtonEnabled="True"
IsSecondaryButtonEnabled="True"
IsVisible="False" />
</ContentControl>
<ui:ContentDialog Name="ContentDialog"
IsPrimaryButtonEnabled="True"
IsSecondaryButtonEnabled="True"
IsVisible="False"
Focusable="True"/>
</window:StyleableWindow>

0 comments on commit 6dbcdfe

Please sign in to comment.