Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b215ba0

Browse files
committed
fix startup lock bug
1 parent c5f360a commit b215ba0

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

App/ViewModels/TrayWindowViewModel.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.UI.Dispatching;
1717
using Microsoft.UI.Xaml;
1818
using Microsoft.UI.Xaml.Controls;
19-
using Exception = System.Exception;
2019

2120
namespace Coder.Desktop.App.ViewModels;
2221

@@ -106,8 +105,8 @@ public void Initialize(DispatcherQueue dispatcherQueue)
106105
_rpcController.StateChanged += (_, rpcModel) => UpdateFromRpcModel(rpcModel);
107106
UpdateFromRpcModel(_rpcController.GetState());
108107

109-
_credentialManager.CredentialsChanged += (_, credentialModel) => UpdateFromCredentialsModel(credentialModel);
110-
UpdateFromCredentialsModel(_credentialManager.GetCachedCredentials());
108+
_credentialManager.CredentialsChanged += (_, credentialModel) => UpdateFromCredentialModel(credentialModel);
109+
UpdateFromCredentialModel(_credentialManager.GetCachedCredentials());
111110
}
112111

113112
private void UpdateFromRpcModel(RpcModel rpcModel)
@@ -211,16 +210,32 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
211210
if (Agents.Count < MaxAgents) ShowAllAgents = false;
212211
}
213212

214-
private void UpdateFromCredentialsModel(CredentialModel credentialModel)
213+
private void UpdateFromCredentialModel(CredentialModel credentialModel)
215214
{
216215
// Ensure we're on the UI thread.
217216
if (_dispatcherQueue == null) return;
218217
if (!_dispatcherQueue.HasThreadAccess)
219218
{
220-
_dispatcherQueue.TryEnqueue(() => UpdateFromCredentialsModel(credentialModel));
219+
_dispatcherQueue.TryEnqueue(() => UpdateFromCredentialModel(credentialModel));
221220
return;
222221
}
223222

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+
224239
// HACK: the HyperlinkButton crashes the whole app if the initial URI
225240
// or this URI is invalid. CredentialModel.CoderUrl should never be
226241
// null while the Page is active as the Page is only displayed when

App/Views/Pages/TrayWindowMainPage.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
242242
TextAlignment="Center"
243243
VerticalAlignment="Center"
244-
Margin="0,-1,0,0" />
244+
Margin="0,-3,0,0" />
245245
</Grid>
246246

247247
<ItemsRepeater

0 commit comments

Comments
 (0)