@@ -16,24 +16,28 @@ namespace Coder.Desktop.App.ViewModels;
16
16
17
17
public partial class FileSyncListViewModel : ObservableObject
18
18
{
19
- public delegate void OnFileSyncListStaleDelegate ( ) ;
20
-
21
- // Triggered when the window should be closed.
22
- public event OnFileSyncListStaleDelegate ? OnFileSyncListStale ;
23
-
24
19
private DispatcherQueue ? _dispatcherQueue ;
25
20
26
21
private readonly ISyncSessionController _syncSessionController ;
27
22
private readonly IRpcController _rpcController ;
28
23
private readonly ICredentialManager _credentialManager ;
29
24
30
25
[ ObservableProperty ]
26
+ [ NotifyPropertyChangedFor ( nameof ( ShowUnavailable ) ) ]
31
27
[ NotifyPropertyChangedFor ( nameof ( ShowLoading ) ) ]
32
28
[ NotifyPropertyChangedFor ( nameof ( ShowError ) ) ]
33
29
[ NotifyPropertyChangedFor ( nameof ( ShowSessions ) ) ]
34
30
public partial bool Loading { get ; set ; } = true ;
35
31
36
32
[ ObservableProperty ]
33
+ [ NotifyPropertyChangedFor ( nameof ( ShowUnavailable ) ) ]
34
+ [ NotifyPropertyChangedFor ( nameof ( ShowLoading ) ) ]
35
+ [ NotifyPropertyChangedFor ( nameof ( ShowError ) ) ]
36
+ [ NotifyPropertyChangedFor ( nameof ( ShowSessions ) ) ]
37
+ public partial string ? UnavailableMessage { get ; set ; } = null ;
38
+
39
+ [ ObservableProperty ]
40
+ [ NotifyPropertyChangedFor ( nameof ( ShowUnavailable ) ) ]
37
41
[ NotifyPropertyChangedFor ( nameof ( ShowLoading ) ) ]
38
42
[ NotifyPropertyChangedFor ( nameof ( ShowError ) ) ]
39
43
[ NotifyPropertyChangedFor ( nameof ( ShowSessions ) ) ]
@@ -72,9 +76,11 @@ public bool NewSessionCreateEnabled
72
76
}
73
77
}
74
78
75
- public bool ShowLoading => Loading && Error == null ;
76
- public bool ShowError => Error != null ;
77
- public bool ShowSessions => ! Loading && Error == null ;
79
+ // TODO: this could definitely be improved
80
+ public bool ShowUnavailable => UnavailableMessage != null ;
81
+ public bool ShowLoading => Loading && UnavailableMessage == null && Error == null ;
82
+ public bool ShowError => UnavailableMessage == null && Error != null ;
83
+ public bool ShowSessions => ! Loading && UnavailableMessage == null && Error == null ;
78
84
79
85
public FileSyncListViewModel ( ISyncSessionController syncSessionController , IRpcController rpcController ,
80
86
ICredentialManager credentialManager )
@@ -105,54 +111,56 @@ public void Initialize(DispatcherQueue dispatcherQueue)
105
111
{
106
112
_dispatcherQueue = dispatcherQueue ;
107
113
108
- _rpcController . StateChanged += ( _ , rpcModel ) => UpdateFromRpcModel ( rpcModel ) ;
109
- _credentialManager . CredentialsChanged += ( _ , credentialModel ) => UpdateFromCredentialsModel ( credentialModel ) ;
114
+ _rpcController . StateChanged += RpcControllerStateChanged ;
115
+ _credentialManager . CredentialsChanged += CredentialManagerCredentialsChanged ;
110
116
111
117
var rpcModel = _rpcController . GetState ( ) ;
112
118
var credentialModel = _credentialManager . GetCachedCredentials ( ) ;
113
- // TODO: fix this
114
- //if (MaybeSendStaleEvent(rpcModel, credentialModel)) return;
119
+ MaybeSetUnavailableMessage ( rpcModel , credentialModel ) ;
115
120
116
121
// TODO: Simulate loading until we have real data.
117
122
Task . Delay ( TimeSpan . FromSeconds ( 3 ) ) . ContinueWith ( _ => _dispatcherQueue . TryEnqueue ( ( ) => Loading = false ) ) ;
118
123
}
119
124
120
- private void UpdateFromRpcModel ( RpcModel rpcModel )
125
+ private void RpcControllerStateChanged ( object ? sender , RpcModel rpcModel )
121
126
{
122
127
// Ensure we're on the UI thread.
123
128
if ( _dispatcherQueue == null ) return ;
124
129
if ( ! _dispatcherQueue . HasThreadAccess )
125
130
{
126
- _dispatcherQueue . TryEnqueue ( ( ) => UpdateFromRpcModel ( rpcModel ) ) ;
131
+ _dispatcherQueue . TryEnqueue ( ( ) => RpcControllerStateChanged ( sender , rpcModel ) ) ;
127
132
return ;
128
133
}
129
134
130
135
var credentialModel = _credentialManager . GetCachedCredentials ( ) ;
131
- MaybeSendStaleEvent ( rpcModel , credentialModel ) ;
136
+ MaybeSetUnavailableMessage ( rpcModel , credentialModel ) ;
132
137
}
133
138
134
- private void UpdateFromCredentialsModel ( CredentialModel credentialModel )
139
+ private void CredentialManagerCredentialsChanged ( object ? sender , CredentialModel credentialModel )
135
140
{
136
141
// Ensure we're on the UI thread.
137
142
if ( _dispatcherQueue == null ) return ;
138
143
if ( ! _dispatcherQueue . HasThreadAccess )
139
144
{
140
- _dispatcherQueue . TryEnqueue ( ( ) => UpdateFromCredentialsModel ( credentialModel ) ) ;
145
+ _dispatcherQueue . TryEnqueue ( ( ) => CredentialManagerCredentialsChanged ( sender , credentialModel ) ) ;
141
146
return ;
142
147
}
143
148
144
149
var rpcModel = _rpcController . GetState ( ) ;
145
- MaybeSendStaleEvent ( rpcModel , credentialModel ) ;
150
+ MaybeSetUnavailableMessage ( rpcModel , credentialModel ) ;
146
151
}
147
152
148
- private bool MaybeSendStaleEvent ( RpcModel rpcModel , CredentialModel credentialModel )
153
+ private void MaybeSetUnavailableMessage ( RpcModel rpcModel , CredentialModel credentialModel )
149
154
{
150
- var ok = rpcModel . RpcLifecycle is RpcLifecycle . Connected
151
- && rpcModel . VpnLifecycle is VpnLifecycle . Started
152
- && credentialModel . State == CredentialState . Valid ;
153
-
154
- if ( ! ok ) OnFileSyncListStale ? . Invoke ( ) ;
155
- return ! ok ;
155
+ if ( rpcModel . RpcLifecycle != RpcLifecycle . Connected )
156
+ UnavailableMessage =
157
+ "Disconnected from the Windows service. Please see the tray window for more information." ;
158
+ else if ( credentialModel . State != CredentialState . Valid )
159
+ UnavailableMessage = "Please sign in to access file sync." ;
160
+ else if ( rpcModel . VpnLifecycle != VpnLifecycle . Started )
161
+ UnavailableMessage = "Please start Coder Connect from the tray window to access file sync." ;
162
+ else
163
+ UnavailableMessage = null ;
156
164
}
157
165
158
166
private void ClearNewForm ( )
0 commit comments