|
16 | 16 | using Microsoft.UI.Dispatching;
|
17 | 17 | using Microsoft.UI.Xaml;
|
18 | 18 | using Microsoft.UI.Xaml.Controls;
|
19 |
| -using Exception = System.Exception; |
20 | 19 |
|
21 | 20 | namespace Coder.Desktop.App.ViewModels;
|
22 | 21 |
|
@@ -106,8 +105,8 @@ public void Initialize(DispatcherQueue dispatcherQueue)
|
106 | 105 | _rpcController.StateChanged += (_, rpcModel) => UpdateFromRpcModel(rpcModel);
|
107 | 106 | UpdateFromRpcModel(_rpcController.GetState());
|
108 | 107 |
|
109 |
| - _credentialManager.CredentialsChanged += (_, credentialModel) => UpdateFromCredentialsModel(credentialModel); |
110 |
| - UpdateFromCredentialsModel(_credentialManager.GetCachedCredentials()); |
| 108 | + _credentialManager.CredentialsChanged += (_, credentialModel) => UpdateFromCredentialModel(credentialModel); |
| 109 | + UpdateFromCredentialModel(_credentialManager.GetCachedCredentials()); |
111 | 110 | }
|
112 | 111 |
|
113 | 112 | private void UpdateFromRpcModel(RpcModel rpcModel)
|
@@ -211,16 +210,32 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
|
211 | 210 | if (Agents.Count < MaxAgents) ShowAllAgents = false;
|
212 | 211 | }
|
213 | 212 |
|
214 |
| - private void UpdateFromCredentialsModel(CredentialModel credentialModel) |
| 213 | + private void UpdateFromCredentialModel(CredentialModel credentialModel) |
215 | 214 | {
|
216 | 215 | // Ensure we're on the UI thread.
|
217 | 216 | if (_dispatcherQueue == null) return;
|
218 | 217 | if (!_dispatcherQueue.HasThreadAccess)
|
219 | 218 | {
|
220 |
| - _dispatcherQueue.TryEnqueue(() => UpdateFromCredentialsModel(credentialModel)); |
| 219 | + _dispatcherQueue.TryEnqueue(() => UpdateFromCredentialModel(credentialModel)); |
221 | 220 | return;
|
222 | 221 | }
|
223 | 222 |
|
| 223 | + // CredentialModel updates trigger RpcStateModel updates first. This |
| 224 | + // resolves an issue on startup where the window would be locked for 5 |
| 225 | + // seconds, even if all startup preconditions have been met: |
| 226 | + // |
| 227 | + // 1. RPC state updates, but credentials are invalid so the window |
| 228 | + // enters the invalid loading state to prevent interaction. |
| 229 | + // 2. Credential model finally becomes valid after reaching out to the |
| 230 | + // server to check credentials. |
| 231 | + // 3. UpdateFromCredentialModel previously did not re-trigger RpcModel |
| 232 | + // update. |
| 233 | + // 4. Five seconds after step 1, a new RPC state update would come in |
| 234 | + // and finally unlock the window. |
| 235 | + // |
| 236 | + // Calling UpdateFromRpcModel at step 3 resolves this issue. |
| 237 | + UpdateFromRpcModel(_rpcController.GetState()); |
| 238 | + |
224 | 239 | // HACK: the HyperlinkButton crashes the whole app if the initial URI
|
225 | 240 | // or this URI is invalid. CredentialModel.CoderUrl should never be
|
226 | 241 | // null while the Page is active as the Page is only displayed when
|
|
0 commit comments