@@ -42,6 +42,8 @@ public MainWindowViewModel() {
4242 Task . Factory . StartNew ( PingServer ) ;
4343 Task . Factory . StartNew ( PingSite ) ;
4444 ServerAddress = Configuration . Instance . ServerAddress ;
45+ SshUsername = Configuration . Instance . ServerUsername ;
46+ SshPassword = Configuration . Instance . ServerPassword ;
4547 }
4648
4749 /// <summary>
@@ -137,15 +139,29 @@ public bool IsDisplayingAdvancedCommands {
137139 /// </summary>
138140 public string ? SshUsername {
139141 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+ }
141150 }
142151
143152 /// <summary>
144153 /// The password to use for the SSH session for commands.
145154 /// </summary>
146155 public string ? SshPassword {
147156 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+ }
149165 }
150166
151167 /// <summary>
@@ -178,9 +194,10 @@ private async Task PingSite() {
178194 WebsiteUp = await SendHeadRequest ( "https://nullinside.com" ) ;
179195 ApiUp = await SendHeadRequest ( "https://nullinside.com/api/v1/featureToggle" ) ;
180196 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" ) ;
182198 bool chatNotUpdating = false ;
183- if ( null != ChatTimestamp ) {
199+ if ( HttpStatusCode . OK == chat . Item1 && null != chat . Item2 ) {
200+ ChatTimestamp = chat . Item2 ;
184201 string parsed = ChatTimestamp . Trim ( '"' ) ;
185202 if ( DateTime . TryParse ( parsed , out DateTime time ) ) {
186203 string timestamp = time . ToLocalTime ( ) . ToString ( CultureInfo . InvariantCulture ) ;
@@ -190,6 +207,10 @@ private async Task PingSite() {
190207 chatNotUpdating = diff > TimeSpan . FromMinutes ( 5 ) ;
191208 }
192209 }
210+ else {
211+ ChatTimestamp = null ;
212+ chatNotUpdating = true ;
213+ }
193214
194215 if ( ( ! WebsiteUp || ! ApiUp || ! NullUp || chatNotUpdating ) && IsMinimized ) {
195216 WindowState = WindowState . Normal ;
@@ -224,18 +245,18 @@ private async Task<bool> SendHeadRequest(string address) {
224245 /// </summary>
225246 /// <param name="address">The address to send the request to.</param>
226247 /// <returns>The content of the response.</returns>
227- private async Task < string ? > SendGetRequest ( string address ) {
248+ private async Task < ( HttpStatusCode , string ? ) > SendGetRequest ( string address ) {
228249 try {
229250 var handler = new HttpClientHandler ( ) ;
230251 handler . AutomaticDecompression = ~ DecompressionMethods . None ;
231252 using var httpClient = new HttpClient ( handler ) ;
232253 using var request = new HttpRequestMessage ( HttpMethod . Get , address ) ;
233254 request . Headers . TryAddWithoutValidation ( "user-agent" , Nullinside . Api . Common . Constants . FAKE_USER_AGENT ) ;
234255 HttpResponseMessage response = await httpClient . SendAsync ( request ) ;
235- return await response . Content . ReadAsStringAsync ( ) ;
256+ return ( response . StatusCode , await response . Content . ReadAsStringAsync ( ) ) ;
236257 }
237258 catch {
238- return null ;
259+ return ( HttpStatusCode . InternalServerError , null ) ;
239260 }
240261 }
241262
0 commit comments