@@ -20,6 +20,10 @@ public class LauncherCommands
20
20
private LauncherMessaging _msgr ;
21
21
public readonly Channel < string > CommandChannel ;
22
22
23
+ /// <summary>
24
+ /// Constructor for LauncherCommands
25
+ /// </summary>
26
+ /// <param name="windowVm">ViewModel of the Main Window</param>
23
27
public LauncherCommands ( MainWindowViewModel windowVm )
24
28
{
25
29
_windowVm = windowVm ;
@@ -29,12 +33,18 @@ public LauncherCommands(MainWindowViewModel windowVm)
29
33
CommandChannel = Channel . CreateUnbounded < string > ( ) ;
30
34
}
31
35
36
+ /// <summary>
37
+ /// Activates Main Window and brings to front.
38
+ /// </summary>
32
39
private void ActivateWindow ( )
33
40
{
34
- // This may not work, but let's try anyway...
35
- // In particular keep in mind:
36
- // https://github.com/AvaloniaUI/Avalonia/issues/2398
37
- _windowVm . Control ? . Activate ( ) ;
41
+ var window = _windowVm . Control ;
42
+ if ( window != null )
43
+ {
44
+ Dispatcher . UIThread . Post ( window . Activate ) ;
45
+ return ;
46
+ }
47
+ Console . WriteLine ( $ "MainWindowViewModel not activated; window returned null. :: ActivateWindow()") ;
38
48
}
39
49
40
50
private async Task Connect ( string param )
@@ -75,6 +85,7 @@ private async Task Connect(string param)
75
85
Log . Warning ( $ "Dropping connect command: Busy connecting to a server") ;
76
86
return ;
77
87
}
88
+
78
89
// Note that we don't want to activate the window for something we'll requeue again and again.
79
90
ActivateWindow ( ) ;
80
91
Log . Information ( $ "Connect command: \" { param } \" , \" { reason } \" ") ;
@@ -125,41 +136,47 @@ private async Task RunSingleCommand(string cmd)
125
136
}
126
137
}
127
138
128
- if ( cmd == PingCommand )
129
- {
130
- // Yup!
131
- ActivateWindow ( ) ;
132
- }
133
- else if ( cmd == RedialWaitCommand )
134
- {
135
- // Redialling wait
136
- await Task . Delay ( ConfigConstants . LauncherCommandsRedialWaitTimeout ) ;
137
- }
138
- else if ( cmd . StartsWith ( "R" ) )
139
- {
140
- // Reason (encoded in UTF-8 and then into hex for safety)
141
- _reason = GetUntrustedTextField ( ) ?? "" ;
142
- }
143
- else if ( cmd . StartsWith ( "r" ) )
144
- {
145
- // Reason (no encoding)
146
- _reason = cmd . Substring ( 1 ) ;
147
- }
148
- else if ( cmd . StartsWith ( "C" ) )
139
+ switch ( cmd )
149
140
{
150
- // Uri (encoded in UTF-8 and then into hex for safety)
151
- var uri = GetUntrustedTextField ( ) ;
152
- if ( uri != null )
153
- await Connect ( uri ) ;
154
- }
155
- else if ( cmd . StartsWith ( "c" ) )
156
- {
157
- // Used by the "pass URI as argument" logic, doesn't need to bother with safety measures
158
- await Connect ( cmd . Substring ( 1 ) ) ;
159
- }
160
- else
161
- {
162
- Log . Error ( $ "Unhandled launcher command: { cmd } ") ;
141
+ case PingCommand :
142
+ // Yup!
143
+ ActivateWindow ( ) ;
144
+ break ;
145
+ case RedialWaitCommand :
146
+ // Redialling wait
147
+ await Task . Delay ( ConfigConstants . LauncherCommandsRedialWaitTimeout ) ;
148
+ break ;
149
+ default :
150
+ {
151
+ if ( cmd . StartsWith ( 'R' ) )
152
+ {
153
+ // Reason (encoded in UTF-8 and then into hex for safety)
154
+ _reason = GetUntrustedTextField ( ) ?? "" ;
155
+ }
156
+ else if ( cmd . StartsWith ( 'r' ) )
157
+ {
158
+ // Reason (no encoding)
159
+ _reason = cmd . Substring ( 1 ) ;
160
+ }
161
+ else if ( cmd . StartsWith ( 'C' ) )
162
+ {
163
+ // Uri (encoded in UTF-8 and then into hex for safety)
164
+ var uri = GetUntrustedTextField ( ) ;
165
+ if ( uri != null )
166
+ await Connect ( uri ) ;
167
+ }
168
+ else if ( cmd . StartsWith ( 'c' ) )
169
+ {
170
+ // Used by the "pass URI as argument" logic, doesn't need to bother with safety measures
171
+ await Connect ( cmd . Substring ( 1 ) ) ;
172
+ }
173
+ else
174
+ {
175
+ Log . Error ( $ "Unhandled launcher command: { cmd } ") ;
176
+ }
177
+
178
+ break ;
179
+ }
163
180
}
164
181
}
165
182
@@ -170,4 +187,3 @@ private async Task RunSingleCommand(string cmd)
170
187
public const string BlankReasonCommand = "r" ;
171
188
public static string ConstructConnectCommand ( Uri uri ) => "c" + uri . ToString ( ) ;
172
189
}
173
-
0 commit comments