@@ -27,7 +27,6 @@ public partial class App : IDisposable
2727 private static bool _isRunning ;
2828 private static Mutex _mutex ;
2929 private static NotifyIcon _notifyIcon ;
30- private static readonly List < ProcessStartInfo > _processes = new List < ProcessStartInfo > ( ) ;
3130 private static readonly List < string > _notifications = new List < string > ( ) ;
3231 private static readonly object _showHidelock = new object ( ) ;
3332
@@ -151,9 +150,7 @@ protected virtual void Dispose(bool disposing)
151150 try
152151 {
153152 if ( _notifyIcon != null )
154- {
155153 _notifyIcon . Dispose ( ) ;
156- }
157154 }
158155 catch
159156 {
@@ -298,16 +295,14 @@ private void OnProcessExit(object sender, EventArgs e)
298295 {
299296 Dispose ( ) ;
300297
301- foreach ( var process in _processes )
298+ try
302299 {
303- try
304- {
305- Process . Start ( process ) ;
306- }
307- catch
308- {
309- // ignored
310- }
300+ if ( Updater . Process != null )
301+ Process . Start ( Updater . Process ) ;
302+ }
303+ catch ( Exception ex )
304+ {
305+ Logger . Error ( "Error starting update process." + ex ) ;
311306 }
312307 }
313308
@@ -354,11 +349,11 @@ private void OnNotifyIconClick(object sender, System.Windows.Forms.MouseEventArg
354349 MainWindow . Dispatcher . BeginInvoke ( ( Action ) ( ( ) =>
355350 {
356351 var mainWindow = MainWindow as MainWindow ;
357-
352+
358353 if ( mainWindow != null )
359354 {
360355 var optimizeButton = mainWindow . FindName ( "Optimize" ) as UIElement ;
361-
356+
362357 if ( optimizeButton != null )
363358 {
364359 Keyboard . Focus ( optimizeButton ) ;
@@ -398,13 +393,14 @@ private void OnNotifyIconClick(object sender, System.Windows.Forms.MouseEventArg
398393 /// <param name="startupEvent">The <see cref="StartupEventArgs" /> instance containing the event data.</param>
399394 protected override void OnStartup ( StartupEventArgs startupEvent )
400395 {
396+ var startupType = Enums . StartupType . App ;
397+
401398 try
402399 {
403400 Initialize ( ) ;
404401
405- var commandLineArguments = startupEvent != null ? new List < string > ( startupEvent . Args . Select ( arg => arg . Replace ( "-" , "/" ) . Trim ( ) ) ) : null ;
402+ var commandLineArguments = startupEvent != null ? startupEvent . Args . Select ( arg => arg . Replace ( "-" , "/" ) . Trim ( ) ) . ToArray ( ) : null ;
406403 var memoryAreas = Enums . Memory . Areas . None ;
407- var startupType = Enums . StartupType . App ;
408404
409405 if ( commandLineArguments != null )
410406 {
@@ -414,16 +410,6 @@ protected override void OnStartup(StartupEventArgs startupEvent)
414410 // Process command‑line arguments
415411 foreach ( var argument in commandLineArguments . Select ( arg => arg . Replace ( "/" , string . Empty ) ) )
416412 {
417- // Memory areas to optimize
418- Enums . Memory . Areas area ;
419-
420- if ( Enum . TryParse ( argument , out area ) )
421- memoryAreas |= area ;
422-
423- // Version (Update)
424- if ( argument . Equals ( Version . ToString ( ) ) )
425- _notifications . Add ( string . Format ( Localizer . Culture , Localizer . String . UpdatedToVersion , string . Format ( Localizer . Culture , Constants . App . VersionFormat , Version . Major , Version . Minor , Version . Build ) ) ) ;
426-
427413 // Startup Type
428414 if ( memoryAreas != Enums . Memory . Areas . None )
429415 startupType = Enums . StartupType . Silent ;
@@ -436,6 +422,16 @@ protected override void OnStartup(StartupEventArgs startupEvent)
436422
437423 if ( argument . Equals ( Constants . App . CommandLineArgument . Uninstall , StringComparison . OrdinalIgnoreCase ) )
438424 startupType = Enums . StartupType . Uninstallation ;
425+
426+ // Memory areas to optimize
427+ Enums . Memory . Areas area ;
428+
429+ if ( Enum . TryParse ( argument , out area ) )
430+ memoryAreas |= area ;
431+
432+ // Notify version update
433+ if ( argument . Equals ( Version . ToString ( ) ) )
434+ _notifications . Add ( string . Format ( Localizer . Culture , Localizer . String . UpdatedToVersion , string . Format ( Localizer . Culture , Constants . App . VersionFormat , Version . Major , Version . Minor , Version . Build ) ) ) ;
439435 }
440436 }
441437
@@ -528,7 +524,9 @@ protected override void OnStartup(StartupEventArgs startupEvent)
528524 catch ( Exception e )
529525 {
530526 Logger . Error ( e ) ;
531- ShowDialog ( e ) ;
527+
528+ if ( startupType == Enums . StartupType . App )
529+ ShowDialog ( e ) ;
532530
533531 Shutdown ( true ) ;
534532 }
0 commit comments