Skip to content

Commit

Permalink
fix: Convert the update dialog to be a ContainedDialog (#1201)
Browse files Browse the repository at this point in the history
#### Details
Currently, our update dialog is a traditional modal dialog in a separate window. This results in some undesirable side effects while the dialog is open, such as the inability to reposition or close the application. To improve this behavior, this PR switches the update dialog to be a `ContainedDialog`, following the same pattern as our telemetry and channel switching dialogs. With one exception, the updated `UpdateContainedDialog` provides exactly the same functionality to the user as the existing `UpdateDialog`. The exception: for required updates, there is now a Close button in place of the Later button for option updates.

##### Motivation
Addresses issue #1186 (at least partially) 

##### Context
- To support this change, I updated `DialogContainerModeControl` to disable all background `ContainedDialog`. This way, in the (rare) scenario where the user has the Update, Telemetry, and StartUp dialogs all open at once, only the topmost contained dialog will show up in the tab order.

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox -->

- [n/a] Run through of all [test scenarios](https://github.com/Microsoft/accessibility-insights-windows/blob/main/docs/Scenarios.md) completed?
- [x] Does this address an existing issue? If yes, Issue# - #1186
- [x] Includes UI changes?
  - [x] Run the production version of Accessibility Insights for Windows against a version with changes.
  - [x] Attach any screenshots / GIF's that are applicable.

> Note: After the PR has been created, certain checks will be kicked off. All of these checks must pass before a merge.
  • Loading branch information
jalkire authored Sep 24, 2021
1 parent 7f8687d commit b27b8a8
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ChangeChannelContainedDialog(ReleaseChannel channel)
WaitHandle.Reset();
}

protected override void SetFocusOnDefaultControl()
public override void SetFocusOnDefaultControl()
{
btnOk.Focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void DismissDialog()
WaitHandle.Set();
}

protected abstract void SetFocusOnDefaultControl();
public abstract void SetFocusOnDefaultControl();

public Task<bool> ShowDialog(Action<ContainedDialog> hideDialog)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ private void hlLink_RequestNavigate(object sender, RequestNavigateEventArgs e)
#pragma warning restore CA1031 // Do not catch general exception types
}

protected override void SetFocusOnDefaultControl() => hlVersion.Focus();
public override void SetFocusOnDefaultControl() => hlVersion.Focus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void btnExit_Click(object sender, RoutedEventArgs e)
WaitHandle.Set();
}

protected override void SetFocusOnDefaultControl()
public override void SetFocusOnDefaultControl()
{
btnExit.Focus();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!-- Copyright (c) Microsoft. All rights reserved.
Licensed under the MIT license. See LICENSE file in the project root for full license information.-->
<dialogs:ContainedDialog
xmlns:dialogs="clr-namespace:AccessibilityInsights.SharedUx.Dialogs"
x:Class="AccessibilityInsights.SharedUx.Dialogs.UpdateContainedDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:AccessibilityInsights.SharedUx.Properties"
mc:Ignorable="d"
AutomationProperties.Name="{x:Static properties:Resources.UpdateContainedDialogAutomationName}">
<dialogs:ContainedDialog.Resources>
<ResourceDictionary Source="pack://application:,,,/AccessibilityInsights.SharedUx;component/Resources/Styles.xaml"/>
</dialogs:ContainedDialog.Resources>
<Border VerticalAlignment="Center" HorizontalAlignment="Center"
BorderThickness="{DynamicResource ResourceKey=BtnBrdrThickness}"
BorderBrush="{DynamicResource ResourceKey=PrimaryFGBrush}">
<Grid Width="370" HorizontalAlignment="Center" VerticalAlignment="Center"
Background="{DynamicResource ResourceKey=SecondaryBGBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="12"/>
</Grid.RowDefinitions>
<Label Grid.Column="1" HorizontalAlignment="Left" Margin="2,8" Name="lblUpdate" Content="{x:Static properties:Resources.UpdateContainedDialog_An_update_is_available}" Style="{StaticResource TxtTelemetryDialogLabel}"/>
<TextBlock Grid.Column="1" Grid.Row="1" Style="{StaticResource TxtTelemetryDialogText}" TextWrapping="Wrap" Margin="8">
<Hyperlink x:Name="hlReleaseNotes" Click="hlReleaseNotes_Click" FocusVisualStyle="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" Style="{StaticResource hLink}">
<Run Text="{x:Static properties:Resources.ReleaseNotesText}" />
</Hyperlink>
</TextBlock>
<Grid Grid.Column="1" Grid.Row="2" Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button x:Name="btnUpdateNow" Click="UpdateNow_Click" Grid.Column="2" Width="100" Height="30"
Style="{StaticResource BtnBlueRounded}" Content="{x:Static properties:Resources.btnUpdateNowText}"/>
<Button x:Name="btnUpdateLater" Click="UpdateLater_Dismiss" Grid.Column="1" Width="100" Height="30"
Style="{StaticResource BtnBlueRounded}" Content="{x:Static properties:Resources.btnUpdateLaterText}"/>
</Grid>
</Grid>
</Border>
</dialogs:ContainedDialog>
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using AccessibilityInsights.CommonUxComponents.Dialogs;
using AccessibilityInsights.Misc;
using AccessibilityInsights.SharedUx.FileIssue;
using AccessibilityInsights.SharedUx.Telemetry;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;

namespace AccessibilityInsights.Dialogs
namespace AccessibilityInsights.SharedUx.Dialogs
{
/// <summary>
/// Interaction logic for UpdateDialog.xaml
/// </summary>
public partial class UpdateDialog : Window
public partial class UpdateContainedDialog : ContainedDialog
{
public Uri ReleaseNotesUri { get; }

/// <summary>
/// Initializes update dialog
/// </summary>
/// <param name="releaseNotesUri">Uri to release notes</param>
public UpdateDialog(Uri releaseNotesUri)
public UpdateContainedDialog(Uri releaseNotesUri)
{
InitializeComponent();
this.ReleaseNotesUri = releaseNotesUri;
Topmost = App.Current.MainWindow.Topmost;
WaitHandle.Reset();
}

private void UpdateNow_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.Close();
WaitHandle.Set();
}

private void UpdateLater_Click(object sender, RoutedEventArgs e)
private void UpdateLater_Dismiss(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
DismissDialog();
}

/// <summary>
/// Navigates to the url for the release notes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ReleaseNotes_Click(object sender, RoutedEventArgs e)
private void UpdateLater_Close(object sender, RoutedEventArgs e)
{
Application.Current.MainWindow.Close();
}

public void SetModeToRequired()
{
lblUpdate.Content = Properties.Resources.UpdateContainedDialog_An_update_is_required;
btnUpdateLater.Content = Properties.Resources.closeDialogText;
btnUpdateLater.Click -= UpdateLater_Dismiss;
btnUpdateLater.Click += UpdateLater_Close;
}

public override void SetFocusOnDefaultControl()
{
btnUpdateNow.Focus();
}

private void hlReleaseNotes_Click(object sender, RoutedEventArgs e)
{
string error = string.Empty;
string releaseNotesString = string.Empty;
Expand All @@ -53,19 +67,19 @@ private void ReleaseNotes_Click(object sender, RoutedEventArgs e)

if (ReleaseNotesUri.Scheme == Uri.UriSchemeHttp || ReleaseNotesUri.Scheme == Uri.UriSchemeHttps)
{
System.Diagnostics.Process.Start(releaseNotesString);
Process.Start(releaseNotesString);
}
else
{
error = Properties.Resources.ReleaseNotes_ClickURLErrorMessage + " " + releaseNotesString;
error = string.Format(CultureInfo.CurrentCulture, Properties.Resources.ReleaseNotes_ClickURLErrorMessage, releaseNotesString);
MessageDialog.Show(error);
}
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
{
ex.ReportException();
error = Properties.Resources.ReleaseNotes_ClickLoadErrorMessage + " " + releaseNotesString;
error = string.Format(CultureInfo.CurrentCulture, Properties.Resources.ReleaseNotes_ClickLoadErrorMessage, releaseNotesString);
MessageDialog.Show(error);
}
#pragma warning restore CA1031 // Do not catch general exception types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,14 @@ public static TelemetryEvent ForIssueFilingCompleted(IIssueResult issueResult, I
{ TelemetryProperty.IssueReporter, IssueReporter.DisplayName?.ToString(CultureInfo.InvariantCulture) },
});
}

public static TelemetryEvent ForReleaseNotesClick(string error)
{
return new TelemetryEvent(TelemetryAction.Upgrade_Update_ReleaseNote,
new Dictionary<TelemetryProperty, string>
{
{ TelemetryProperty.Error, error },
});
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/AccessibilityInsights.SharedUx/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1515,4 +1515,31 @@ Do you want to change the channel? </value>
<data name="TextRangeControl_Details" xml:space="preserve">
<value>Details</value>
</data>
<data name="UpdateContainedDialogAutomationName" xml:space="preserve">
<value>There is an update available</value>
</data>
<data name="UpdateContainedDialog_An_update_is_required" xml:space="preserve">
<value>An update is required</value>
</data>
<data name="UpdateContainedDialog_An_update_is_available" xml:space="preserve">
<value>An update is available</value>
</data>
<data name="ReleaseNotes_ClickLoadErrorMessage" xml:space="preserve">
<value>There was an error loading the URL.\nURL: {0}</value>
</data>
<data name="ReleaseNotes_ClickURLErrorMessage" xml:space="preserve">
<value>The URL was not properly formatted.\nURL: {0}</value>
</data>
<data name="ReleaseNotesText" xml:space="preserve">
<value>View the release notes here.</value>
</data>
<data name="btnUpdateLaterText" xml:space="preserve">
<value>Later</value>
</data>
<data name="btnUpdateNowText" xml:space="preserve">
<value>Update now</value>
</data>
<data name="closeDialogText" xml:space="preserve">
<value>Close</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/AccessibilityInsights.SharedUx/SharedUx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@
</None>
</ItemGroup>

<ItemGroup>
<Page Update="Dialogs\UpdateContainedDialog.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>

</Project>
Loading

0 comments on commit b27b8a8

Please sign in to comment.