From 726dc4e79bfc5a06bcb769d16526ba3cbc2b1bc3 Mon Sep 17 00:00:00 2001
From: dyakovei <dyakov.hellvisionstudio@gmail.com>
Date: Fri, 20 Jan 2023 14:58:51 +0000
Subject: [PATCH] return the focus to the input field after printing and new
 marketing (#41)

add marketing shutdown message
add returning the focus to the input field after printing #36
closes #36
---
 PrinterApp/App.xaml.cs        |  1 +
 PrinterApp/MainWindow.xaml    | 30 ++++++++++++++++--------------
 PrinterApp/MainWindow.xaml.cs |  1 +
 PrinterApp/Marketing.cs       |  9 +++++++++
 PrinterApp/PrinterApp.csproj  |  2 +-
 PrinterApp/PrinterModel.cs    |  5 +++++
 6 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/PrinterApp/App.xaml.cs b/PrinterApp/App.xaml.cs
index 968da09..d48704e 100644
--- a/PrinterApp/App.xaml.cs
+++ b/PrinterApp/App.xaml.cs
@@ -87,6 +87,7 @@ private void MainWindowClosing(object? sender, System.ComponentModel.CancelEvent
                 return;
             }
 
+            Marketing.ManualShutdown();
             _printerModel.SocketsClose();
             _autoUpdater.StopTimer();
             Current.Shutdown();
diff --git a/PrinterApp/MainWindow.xaml b/PrinterApp/MainWindow.xaml
index acde9f4..e487e2b 100644
--- a/PrinterApp/MainWindow.xaml
+++ b/PrinterApp/MainWindow.xaml
@@ -12,7 +12,7 @@
         ResizeMode="NoResize"
         Topmost="True"
         ShowInTaskbar="False"
-        d:DataContext="{d:DesignInstance local:PrinterViewModel}">
+        d:DataContext="{d:DesignInstance local:PrinterViewModel}" Focusable="False">
     <Viewbox Stretch="Fill" KeyDown="UIElement_OnKeyDown">
         <Canvas x:Name="RootCanvas" Background="{DynamicResource App.Background}" Height="900" Width="1600">
             <Canvas Height="900" Width="1600" Visibility="{Binding FlakesVisibility}">
@@ -43,11 +43,12 @@
             </Canvas>
             <Image Width="212" Height="212" Source="{Binding PrintQr}" HorizontalAlignment="Left"
                    VerticalAlignment="Top" Canvas.Left="219" Canvas.Top="485"
-                   Visibility="{Binding PrintQrVisibility}" />
+                   Visibility="{Binding PrintQrVisibility}" Focusable="False" />
             <Rectangle Width="3" Height="590" Canvas.Left="684" Canvas.Top="155"
-                       Fill="{DynamicResource Labels.Foreground}" />
+                       Fill="{DynamicResource Labels.Foreground}" Focusable="False" />
             <TextBlock FontSize="24" Width="641" Height="449" Canvas.Left="814" Canvas.Top="57" TextWrapping="Wrap"
-                       Foreground="{DynamicResource Labels.Foreground}" FontFamily="Roboto" FontWeight="Bold">
+                       Foreground="{DynamicResource Labels.Foreground}" FontFamily="Roboto" FontWeight="Bold"
+                       Focusable="False">
                 <Run
                     Text="0) Подключись со своего устройства к интернету. Можно воспользоваться сетями Wi-Fi в холле ЦФА или гостевым Wi-Fi PKFF_Free. " />
                 <LineBreak />
@@ -59,24 +60,25 @@
             </TextBlock>
             <TextBlock Text="Приложение Твой ФФ!" FontSize="24" Width="256" Height="28" Canvas.Left="854"
                        Canvas.Top="540" TextWrapping="Wrap" Foreground="{DynamicResource Labels.Foreground}"
-                       FontWeight="Bold" />
+                       FontWeight="Bold" Focusable="False" />
             <TextBlock Text="Бот принтера ВК" FontSize="24" Width="189" Height="28" Canvas.Left="1208"
                        Canvas.Top="540"
-                       TextWrapping="Wrap" Foreground="{DynamicResource Labels.Foreground}" FontWeight="Bold" />
+                       TextWrapping="Wrap" Foreground="{DynamicResource Labels.Foreground}" FontWeight="Bold"
+                       Focusable="False" />
             <TextBlock Text="app.profcomff.com" FontSize="24" Width="209" Height="28" Canvas.Left="878"
                        Canvas.Top="815" TextWrapping="Wrap" Foreground="{DynamicResource Labels.Foreground}"
-                       FontWeight="Bold" />
+                       FontWeight="Bold" Focusable="False" />
             <TextBlock Text="vk.me/profcomff_print_bot" FontSize="24" Width="290" Height="28" Canvas.Left="1158"
                        Canvas.Top="815" TextWrapping="Wrap" Foreground="{DynamicResource Labels.Foreground}"
-                       FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Center" />
+                       FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Center" Focusable="False" />
             <Rectangle Width="212" Height="212" Fill="{DynamicResource Qr.AppProfcomffCom}" Canvas.Left="876"
-                       Canvas.Top="591" HorizontalAlignment="Center" VerticalAlignment="Top" />
+                       Canvas.Top="591" HorizontalAlignment="Center" VerticalAlignment="Top" Focusable="False" />
             <Rectangle Width="212" Height="212" Fill="{DynamicResource Qr.ProfcomffPrint}" Canvas.Left="1197"
-                       Canvas.Top="591" HorizontalAlignment="Left" VerticalAlignment="Center" />
+                       Canvas.Top="591" HorizontalAlignment="Left" VerticalAlignment="Center" Focusable="False" />
             <TextBlock Text="{Binding Compliment}" TextWrapping="Wrap"
                        Foreground="{DynamicResource Labels.Foreground}" FontFamily="Roboto" FontWeight="Bold"
                        FontSize="24" Canvas.Left="120" Canvas.Top="485" Height="152" Width="410"
-                       HorizontalAlignment="Left" VerticalAlignment="Top" />
+                       HorizontalAlignment="Left" VerticalAlignment="Top" Focusable="False" />
             <Grid Canvas.Left="120" Canvas.Top="263" Width="410">
                 <TextBlock Text="Код документа для печати" FontSize="24" TextWrapping="Wrap"
                            Foreground="{DynamicResource Labels.Foreground}" FontWeight="Bold" Margin="0,0,104,158" />
@@ -88,7 +90,7 @@
                          IsEnabled="{Binding DownloadNotInProgress}"
                          TextAlignment="Center" Style="{DynamicResource MyTextBoxStyle1}"
                          VerticalContentAlignment="Center"
-                         HorizontalContentAlignment="Center" Margin="0,29,0,105" />
+                         HorizontalContentAlignment="Center" Margin="0,29,0,105" TabIndex="1" />
                 <TextBlock IsHitTestVisible="False" Text="Введите код здесь" VerticalAlignment="Top"
                            HorizontalAlignment="Center" Margin="0,41,0,0" Foreground="DarkGray" FontSize="24">
                     <TextBlock.Style>
@@ -107,9 +109,9 @@
                        Background="Red" Foreground="White"
                        Content="{Binding ErrorTextBlockText, FallbackValue=123}"
                        Padding="0,0,0,0" Margin="0,157,0,0" Visibility="{Binding ErrorTextBlockVisibility}" />
-                <Button Content="Распечатать сразу" Click="Print_OnClick"
+                <Button x:Name="ButtonPrint" Content="Распечатать сразу" Click="Print_OnClick"
                         Style="{DynamicResource MyButtonStyle}" FontSize="20"
-                        IsEnabled="{Binding DownloadNotInProgress}" Margin="0,92,0,42" />
+                        IsEnabled="{Binding DownloadNotInProgress}" Margin="0,92,0,42" Focusable="True" TabIndex="2" />
             </Grid>
         </Canvas>
     </Viewbox>
diff --git a/PrinterApp/MainWindow.xaml.cs b/PrinterApp/MainWindow.xaml.cs
index c48de7a..b707314 100644
--- a/PrinterApp/MainWindow.xaml.cs
+++ b/PrinterApp/MainWindow.xaml.cs
@@ -99,6 +99,7 @@ public MainWindow(PrinterModel printerModel)
             Topmost = false;
             ShowInTaskbar = true;
 #endif
+            _printerModel.PrintAsyncCompleteEvent += () => { CodeBox.Focus(); };
             Marketing.MainWindowLoaded();
         }
 
diff --git a/PrinterApp/Marketing.cs b/PrinterApp/Marketing.cs
index 91db911..346d9f9 100644
--- a/PrinterApp/Marketing.cs
+++ b/PrinterApp/Marketing.cs
@@ -153,6 +153,15 @@ public static void ManualReboot()
                 pathTo: "");
         }
 
+        public static void ManualShutdown()
+        {
+            Post(
+                action: "print terminal manual shutdown",
+                status: "ok",
+                pathFrom: "",
+                pathTo: "");
+        }
+
         public static void SocketException(string status)
         {
             Post(
diff --git a/PrinterApp/PrinterApp.csproj b/PrinterApp/PrinterApp.csproj
index 5940878..62fff89 100644
--- a/PrinterApp/PrinterApp.csproj
+++ b/PrinterApp/PrinterApp.csproj
@@ -11,7 +11,7 @@
     <Title>PrinterApp</Title>
     <Description>gui fo work https://app.profcomff.com/print/docs</Description>
     <Authors>Dyakov EI</Authors>
-    <Version>2.1.3.0</Version>
+    <Version>2.1.4.0</Version>
     <Company>dyakov.space</Company>
     <Copyright>dyakov.space @ 2022</Copyright>
   </PropertyGroup>
diff --git a/PrinterApp/PrinterModel.cs b/PrinterApp/PrinterModel.cs
index 83a74ca..375e2a2 100644
--- a/PrinterApp/PrinterModel.cs
+++ b/PrinterApp/PrinterModel.cs
@@ -49,6 +49,10 @@ public class PrinterModel
 
         public event RebootHandler? Reboot;
 
+        public delegate void PrintAsyncCompleteHandler();
+
+        public event PrintAsyncCompleteHandler? PrintAsyncCompleteEvent;
+
         public PrinterModel(ConfigFile configFile, AutoUpdater autoUpdater)
         {
             _configFile = configFile;
@@ -191,6 +195,7 @@ await _httpClient.GetStreamAsync(
             PrinterViewModel.DownloadNotInProgress = true;
             Log.Debug(
                 $"{GetType().Name} {MethodBase.GetCurrentMethod()?.Name}: End response code {PrinterViewModel.CodeTextBoxText}");
+            PrintAsyncCompleteEvent?.Invoke();
         }
 
         public bool WrongExitCode()