Skip to content

Commit 694985f

Browse files
committed
Fix application failing to show if it was started in tray
1 parent d3ba566 commit 694985f

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

CompactGUI/Application.xaml.vb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ Class Application
2626
End If
2727

2828
mainWindow = New MainWindow()
29-
If e.Args.Length = 1 AndAlso e.Args(0).ToString = "-tray" Then
30-
mainWindow.ViewModel.ClosingCommand.Execute(New ComponentModel.CancelEventArgs(True))
31-
ElseIf e.Args.Length = 1 Then
32-
Await mainWindow.ViewModel.SelectFolderAsync(e.Args(0))
33-
End If
29+
Dim shouldMinimizeToTray As Boolean = (e.Args.Length = 1 AndAlso e.Args(0).ToString = "-tray") OrElse
30+
(SettingsHandler.AppSettings.StartInSystemTray AndAlso e.Args.Length = 0)
3431

35-
If SettingsHandler.AppSettings.StartInSystemTray AndAlso e.Args.Length = 0 Then
32+
If shouldMinimizeToTray Then
33+
mainWindow.Show()
3634
mainWindow.ViewModel.ClosingCommand.Execute(New ComponentModel.CancelEventArgs(True))
3735
Else
36+
If e.Args.Length = 1 Then
37+
Await mainWindow.ViewModel.SelectFolderAsync(e.Args(0))
38+
End If
3839
mainWindow.Show()
3940
End If
4041

CompactGUI/ViewModels/MainViewModel.TrayHandler.vb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ Partial Public Class MainViewModel
3434
Private Sub InitialiseNotificationTray()
3535
ClosingCommand = New RelayCommand(Of CancelEventArgs)(AddressOf Closing)
3636
NotifyCommand = New RelayCommand(Sub() Notify("Hello", "World"))
37-
NotifyIconOpenCommand = New RelayCommand(Sub()
38-
Application.Current.MainWindow.Show()
39-
WindowState = WindowState.Normal
40-
Application.Current.MainWindow.Topmost = True
41-
Application.Current.MainWindow.Activate()
42-
Application.Current.MainWindow.Topmost = False
43-
End Sub)
37+
NotifyIconOpenCommand = New RelayCommand(AddressOf NotifyOpen)
4438
NotifyIconExitCommand = New RelayCommand(AddressOf NotifyExit)
4539
End Sub
4640

41+
Private Sub NotifyOpen()
42+
Application.Current.MainWindow.Show()
43+
WindowState = WindowState.Normal
44+
Application.Current.MainWindow.Topmost = True
45+
Application.Current.MainWindow.Activate()
46+
Application.Current.MainWindow.Topmost = False
47+
End Sub
48+
4749
Private Sub NotifyExit()
4850
If Watcher.WatchedFolders.Count = 0 Then Application.Current.Shutdown()
4951
Dim res = MessageBox.Show(

0 commit comments

Comments
 (0)