@@ -42,6 +42,8 @@ public MainWindowViewModel() {
42
42
Task . Factory . StartNew ( PingServer ) ;
43
43
Task . Factory . StartNew ( PingSite ) ;
44
44
ServerAddress = Configuration . Instance . ServerAddress ;
45
+ SshUsername = Configuration . Instance . ServerUsername ;
46
+ SshPassword = Configuration . Instance . ServerPassword ;
45
47
}
46
48
47
49
/// <summary>
@@ -137,15 +139,29 @@ public bool IsDisplayingAdvancedCommands {
137
139
/// </summary>
138
140
public string ? SshUsername {
139
141
get => _sshUsername ;
140
- set => this . RaiseAndSetIfChanged ( ref _sshUsername , value ) ;
142
+ set {
143
+ Configuration . Instance . ServerUsername = value ;
144
+ this . RaiseAndSetIfChanged ( ref _sshUsername , value ) ;
145
+ try {
146
+ Configuration . WriteConfiguration ( ) ;
147
+ }
148
+ catch { }
149
+ }
141
150
}
142
151
143
152
/// <summary>
144
153
/// The password to use for the SSH session for commands.
145
154
/// </summary>
146
155
public string ? SshPassword {
147
156
get => _sshPassword ;
148
- set => this . RaiseAndSetIfChanged ( ref _sshPassword , value ) ;
157
+ set {
158
+ Configuration . Instance . ServerPassword = value ;
159
+ this . RaiseAndSetIfChanged ( ref _sshPassword , value ) ;
160
+ try {
161
+ Configuration . WriteConfiguration ( ) ;
162
+ }
163
+ catch { }
164
+ }
149
165
}
150
166
151
167
/// <summary>
@@ -178,9 +194,10 @@ private async Task PingSite() {
178
194
WebsiteUp = await SendHeadRequest ( "https://nullinside.com" ) ;
179
195
ApiUp = await SendHeadRequest ( "https://nullinside.com/api/v1/featureToggle" ) ;
180
196
NullUp = await SendHeadRequest ( "https://nullinside.com/null/v1/database/migration" ) ;
181
- ChatTimestamp = await SendGetRequest ( "https://nullinside.com/twitch-bot/v1/bot/chat/timestamp" ) ;
197
+ ( HttpStatusCode , string ? ) chat = await SendGetRequest ( "https://nullinside.com/twitch-bot/v1/bot/chat/timestamp" ) ;
182
198
bool chatNotUpdating = false ;
183
- if ( null != ChatTimestamp ) {
199
+ if ( HttpStatusCode . OK == chat . Item1 && null != chat . Item2 ) {
200
+ ChatTimestamp = chat . Item2 ;
184
201
string parsed = ChatTimestamp . Trim ( '"' ) ;
185
202
if ( DateTime . TryParse ( parsed , out DateTime time ) ) {
186
203
string timestamp = time . ToLocalTime ( ) . ToString ( CultureInfo . InvariantCulture ) ;
@@ -190,6 +207,10 @@ private async Task PingSite() {
190
207
chatNotUpdating = diff > TimeSpan . FromMinutes ( 5 ) ;
191
208
}
192
209
}
210
+ else {
211
+ ChatTimestamp = null ;
212
+ chatNotUpdating = true ;
213
+ }
193
214
194
215
if ( ( ! WebsiteUp || ! ApiUp || ! NullUp || chatNotUpdating ) && IsMinimized ) {
195
216
WindowState = WindowState . Normal ;
@@ -224,18 +245,18 @@ private async Task<bool> SendHeadRequest(string address) {
224
245
/// </summary>
225
246
/// <param name="address">The address to send the request to.</param>
226
247
/// <returns>The content of the response.</returns>
227
- private async Task < string ? > SendGetRequest ( string address ) {
248
+ private async Task < ( HttpStatusCode , string ? ) > SendGetRequest ( string address ) {
228
249
try {
229
250
var handler = new HttpClientHandler ( ) ;
230
251
handler . AutomaticDecompression = ~ DecompressionMethods . None ;
231
252
using var httpClient = new HttpClient ( handler ) ;
232
253
using var request = new HttpRequestMessage ( HttpMethod . Get , address ) ;
233
254
request . Headers . TryAddWithoutValidation ( "user-agent" , Nullinside . Api . Common . Constants . FAKE_USER_AGENT ) ;
234
255
HttpResponseMessage response = await httpClient . SendAsync ( request ) ;
235
- return await response . Content . ReadAsStringAsync ( ) ;
256
+ return ( response . StatusCode , await response . Content . ReadAsStringAsync ( ) ) ;
236
257
}
237
258
catch {
238
- return null ;
259
+ return ( HttpStatusCode . InternalServerError , null ) ;
239
260
}
240
261
}
241
262
0 commit comments