2525using G33kShell . Desktop . Terminal ;
2626using G33kShell . Desktop . Terminal . Controls ;
2727using SkiaSharp ;
28+ using Border = G33kShell . Desktop . Console . Controls . Border ;
29+ using Image = G33kShell . Desktop . Console . Controls . Image ;
30+ using ProgressBar = G33kShell . Desktop . Console . Controls . ProgressBar ;
31+ using TextBlock = G33kShell . Desktop . Console . Controls . TextBlock ;
2832
2933// ReSharper disable UnusedMember.Local
3034
@@ -41,6 +45,7 @@ public class ShellViewModel : ViewModelBase, IDisposable
4145{
4246 private TerminalState m_terminalState ;
4347 private ScreensaverControl m_screensaverControl ;
48+ private bool m_cancelLogin ;
4449
4550 /// <summary>
4651 /// Occurs when a request is made to reveal the current working directory.
@@ -62,10 +67,28 @@ public ShellViewModel(SkinBase skin)
6267 WindowManager = new WindowManager ( 100 , 38 , skin ) ;
6368 _ = StartAsync ( ) ;
6469 }
65-
70+
71+ public void CancelLogin ( ) => m_cancelLogin = true ;
72+
6673#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
6774 private async Task StartAsync ( )
6875 {
76+ #if ! DEBUG
77+ // Start the 'sign in' face-finding background task.
78+ var signInTask = CaptureFaceAsync ( ) ;
79+
80+ // Log-in awesomeness.
81+ if ( ! m_cancelLogin )
82+ await BiosCheckAsync ( ) ;
83+ if ( ! m_cancelLogin )
84+ await LoadOsAsync ( ) ;
85+
86+ if ( ! m_cancelLogin )
87+ {
88+ var signInResult = await signInTask ;
89+ await LogInAsync ( signInResult ) ;
90+ }
91+ #endif
6992
7093 // Run the terminal.
7194 _ = Task . Run ( RunTerminal ) ;
@@ -186,10 +209,19 @@ private async Task BiosCheckAsync()
186209 } )
187210 . AddChild ( biosText ) ;
188211
189- await Task . Run ( ( ) => biosText . Waiter . Wait ( ) ) ;
190- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
212+ if ( ! m_cancelLogin )
213+ await Task . Run ( ( ) =>
214+ {
215+ while ( ! m_cancelLogin && ! biosText . Waiter . Wait ( 100 ) )
216+ {
217+ // Wait.
218+ }
219+ } ) ;
220+ if ( ! m_cancelLogin )
221+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
191222 await WindowManager . Root . ClearAsync ( ClearTransition . Immediate ) ;
192- await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
223+ if ( ! m_cancelLogin )
224+ await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
193225 }
194226
195227 private async Task LoadOsAsync ( )
@@ -221,25 +253,28 @@ private async Task LoadOsAsync()
221253 } ) ;
222254
223255 // Animate the 'Penetration' process.
224- await new Animation (
225- TimeSpan . FromSeconds ( 2 ) ,
226- TimeSpan . FromSeconds ( 5 ) ,
227- f =>
228- {
229- WindowManager . Find < ProgressBar > ( "LogoProgress" ) . Progress = ( int ) ( f * 100 ) ;
230- return true ;
231- } )
232- . StartAsync ( ) ;
256+ if ( ! m_cancelLogin )
257+ await new Animation (
258+ TimeSpan . FromSeconds ( 2 ) ,
259+ TimeSpan . FromSeconds ( 5 ) ,
260+ f =>
261+ {
262+ WindowManager . Find < ProgressBar > ( "LogoProgress" ) . Progress = ( int ) ( f * 100 ) ;
263+ return ! m_cancelLogin ;
264+ } )
265+ . StartAsync ( ) ;
233266
234267 // Clear the screen with the Explode transition.
235- await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
268+ if ( ! m_cancelLogin )
269+ await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
236270 await WindowManager . Root . ClearAsync ( ClearTransition . Explode ) ;
237- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
271+ if ( ! m_cancelLogin )
272+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
238273 }
239274
240275 private async Task LogInAsync ( ( SKBitmap Image , FaceFinder . FaceDetails Face ) ? faceAnalysis )
241276 {
242- if ( faceAnalysis == null )
277+ if ( faceAnalysis == null || m_cancelLogin )
243278 return ;
244279
245280 // 'Sign in' face analysis...
@@ -307,7 +342,7 @@ private async Task LogInAsync((SKBitmap Image, FaceFinder.FaceDetails Face)? fac
307342 featureBoxes . Add ( border ) ;
308343 }
309344
310- for ( var i = 0 ; i < 8 ; i ++ )
345+ for ( var i = 0 ; i < 8 && ! m_cancelLogin ; i ++ )
311346 {
312347 featureBoxes . Shuffle ( ) ;
313348 foreach ( var featureBox in featureBoxes )
@@ -333,9 +368,11 @@ private async Task LogInAsync((SKBitmap Image, FaceFinder.FaceDetails Face)? fac
333368 HorizontalAlignment = HorizontalAlignment . Center , VerticalAlignment = VerticalAlignment . Center
334369 } ) ;
335370
336- await Task . Delay ( TimeSpan . FromSeconds ( 4 ) ) ;
371+ if ( ! m_cancelLogin )
372+ await Task . Delay ( TimeSpan . FromSeconds ( 4 ) ) ;
337373 await WindowManager . Root . ClearAsync ( ClearTransition . Explode ) ;
338- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
374+ if ( ! m_cancelLogin )
375+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
339376 }
340377
341378 private static FaceFinder CreateFaceFinder ( ) =>
0 commit comments