Skip to content

Commit

Permalink
feat(ui): [User Can] See indication of exporting activity
Browse files Browse the repository at this point in the history
Fixes #42
  • Loading branch information
jcoliz committed Jul 23, 2024
1 parent e2b216e commit decdfa4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
1 change: 1 addition & 0 deletions LogoSlideMaker.WinUi/LogoSlideMaker.WinUi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.0.240109" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.2.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240607001" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
Expand Down
18 changes: 13 additions & 5 deletions LogoSlideMaker.WinUi/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:win2dcanvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
xmlns:converters="using:CommunityToolkit.WinUI.Converters"
mc:Ignorable="d"
Closed="Window_Closed"
>

<Grid x:Name="Root">
<Grid.Resources>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="64" />
<RowDefinition Height="*" />
Expand All @@ -21,17 +25,17 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Background="#333333">
<AppBarButton Icon="OpenFile" Label="Open" Click="OpenDocument"/>
<AppBarButton Icon="Refresh" Label="Reload" Command="{Binding Reload}" />
<AppBarButton Icon="OpenFile" Label="Open" Click="OpenDocument" IsEnabled="{Binding IsExporting, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"/>
<AppBarButton Icon="Refresh" Label="Reload" Command="{Binding Reload}" IsEnabled="{Binding IsExporting, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}" />
<AppBarButton Icon="Back" Label="Previous" Command="{Binding PreviousSlide}" />
<AppBarButton Icon="Forward" Label="Next" Command="{Binding NextSlide}" />
<AppBarToggleButton Icon="ViewAll" Label="Boxes" IsChecked="{Binding ShowBoundingBoxes, Mode=TwoWay}" />
<AppBarButton Label="About" Click="ShowAboutDialog">
<AppBarButton Label="About" Click="ShowAboutDialog" IsEnabled="{Binding IsExporting, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
<AppBarButton.Icon>
<ImageIcon Source="ms-appx:///Assets/icon-info.svg"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Icon="Download" Label="Export" Click="ExportSlides"/>
<AppBarButton Icon="Download" Label="Export" Click="ExportSlides" IsEnabled="{Binding IsExporting, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"/>
</StackPanel>
<Border Grid.Column="1" Background="#333333" Height="64">
<TextBlock Foreground="White" Height="64" FontFamily="Segoe UI" FontSize="14" HorizontalTextAlignment="Right" Margin="20,3,20,0">
Expand All @@ -42,6 +46,10 @@
</Border>
<win2dcanvas:CanvasControl Width="1280" Height="720" Grid.Row="1" Grid.ColumnSpan="2" x:Name="canvas" Draw="DrawCanvas" ClearColor="#333333" CreateResources="CreateResourcesEvent"/>
<ProgressRing Grid.Row="1" Grid.ColumnSpan="2" IsActive="{Binding IsLoading}" Foreground="White"/>
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Background="#333333" VerticalAlignment="Center" Padding="40" Visibility="{Binding IsExporting, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
<TextBlock Margin="0,0,0,20" HorizontalAlignment="Center" FontSize="20">Exporting...</TextBlock>
<ProgressRing IsActive="True" Foreground="White"/>
</StackPanel>

<ContentDialog x:Name="aboutDialog" SecondaryButtonText="View Logs" SecondaryButtonClick="OpenLogsFolder"
PrimaryButtonText="OK">
Expand Down
48 changes: 39 additions & 9 deletions LogoSlideMaker.WinUi/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,26 @@ private async void ExportSlides(object _, RoutedEventArgs __)
var file = await picker.PickSaveFileAsync();
if (file != null)
{
// Render to slide
var outPath = file.Path;

// TODO: Loading affordance would be nice
// TODO: Also should get this off the UI thread! :(
await viewModel.ExportToAsync(outPath);

logOkPath(outPath);
// Get off of the UI thread
var ___ = Task.Run(async () =>
{
await viewModel.ExportToAsync(outPath);
})
.ContinueWith(t =>
{
if (t.Exception is not null)
{
logFail(t.Exception);
}
else
{
// TODO: This would be the time to emit an event that we have successfully
// exported
logOkPath(outPath);
}
});
}
else
{
Expand All @@ -286,12 +298,27 @@ private async void ExportSlides(object _, RoutedEventArgs __)

private async void ShowAboutDialog(object sender, RoutedEventArgs e)
{
await aboutDialog.ShowAsync();
try
{
await aboutDialog.ShowAsync();

logOk();
logOk();
}
catch (Exception ex)
{
const int E_ASYNC_OPERATION_NOT_STARTED = unchecked((int)0x80000019);
if (ex.HResult == E_ASYNC_OPERATION_NOT_STARTED)
{
logDebugBusy();
}
else
{
logFail(ex);
}
}
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "UI system requires calling with instance")]
//[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "UI system requires calling with instance")]
private void OpenLogsFolder(ContentDialog _, ContentDialogButtonClickEventArgs __)
{
Process.Start("explorer.exe", MainViewModel.LogsFolder);
Expand Down Expand Up @@ -493,6 +520,9 @@ private static void Draw(RectanglePrimitive primitive, CanvasDrawingSession sess
[LoggerMessage(Level = LogLevel.Debug, Message = "{Location}: No resource load needed at this time")]
public partial void logDebugNoLoadNeeded([CallerMemberName] string? location = null);

[LoggerMessage(Level = LogLevel.Debug, Message = "{Location}: No action taken, because busy")]
public partial void logDebugBusy([CallerMemberName] string? location = null);

#endregion
}

Expand Down
22 changes: 22 additions & 0 deletions LogoSlideMaker.WinUi/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ public bool IsLoading
}
private bool _IsLoading = true;


/// <summary>
/// Whether we are currently exporting a presentation
/// </summary>
public bool IsExporting
{
get => _IsExporting;
set
{
if (value != _IsExporting)
{
_IsExporting = value;
OnPropertyChanged();
}
}
}
private bool _IsExporting = false;

/// <summary>
/// Display names of the slides
/// </summary>
Expand Down Expand Up @@ -484,6 +502,8 @@ public async Task ExportToAsync(string outPath)
return;
}

IsExporting = true;

var exportPipeline = new ExportPipeline(_definition);

var directory = LastOpenedFilePath is not null ? Path.GetDirectoryName(LastOpenedFilePath) : null;
Expand Down Expand Up @@ -528,6 +548,8 @@ public async Task ExportToAsync(string outPath)
finally
{
templateStream?.Dispose();

IsExporting = false;
}
}

Expand Down

0 comments on commit decdfa4

Please sign in to comment.