1
1
using System ;
2
+ using System . Diagnostics ;
2
3
using System . Threading ;
3
4
using System . Threading . Tasks ;
4
5
using Coder . Desktop . App . Models ;
@@ -73,6 +74,8 @@ public async Task ExitApplication()
73
74
{
74
75
_handleWindowClosed = false ;
75
76
Exit ( ) ;
77
+ var syncController = _services . GetRequiredService < ISyncSessionController > ( ) ;
78
+ await syncController . DisposeAsync ( ) ;
76
79
var rpcController = _services . GetRequiredService < IRpcController > ( ) ;
77
80
// TODO: send a StopRequest if we're connected???
78
81
await rpcController . DisposeAsync ( ) ;
@@ -86,20 +89,52 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
86
89
if ( rpcController . GetState ( ) . RpcLifecycle == RpcLifecycle . Disconnected )
87
90
// Passing in a CT with no cancellation is desired here, because
88
91
// the named pipe open will block until the pipe comes up.
89
- _ = rpcController . Reconnect ( CancellationToken . None ) ;
92
+ // TODO: log
93
+ _ = rpcController . Reconnect ( CancellationToken . None ) . ContinueWith ( t =>
94
+ {
95
+ #if DEBUG
96
+ if ( t . Exception != null )
97
+ {
98
+ Debug . WriteLine ( t . Exception ) ;
99
+ Debugger . Break ( ) ;
100
+ }
101
+ #endif
102
+ } ) ;
90
103
91
- // Load the credentials in the background. Even though we pass a CT
92
- // with no cancellation, the method itself will impose a timeout on the
93
- // HTTP portion.
104
+ // Load the credentials in the background.
105
+ var credentialManagerCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 15 ) ) ;
94
106
var credentialManager = _services . GetRequiredService < ICredentialManager > ( ) ;
95
- _ = credentialManager . LoadCredentials ( CancellationToken . None ) ;
107
+ _ = credentialManager . LoadCredentials ( credentialManagerCts . Token ) . ContinueWith ( t =>
108
+ {
109
+ // TODO: log
110
+ #if DEBUG
111
+ if ( t . Exception != null )
112
+ {
113
+ Debug . WriteLine ( t . Exception ) ;
114
+ Debugger . Break ( ) ;
115
+ }
116
+ #endif
117
+ credentialManagerCts . Dispose ( ) ;
118
+ } , CancellationToken . None ) ;
119
+
120
+ // Initialize file sync.
121
+ var syncSessionCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 10 ) ) ;
122
+ var syncSessionController = _services . GetRequiredService < ISyncSessionController > ( ) ;
123
+ _ = syncSessionController . Initialize ( syncSessionCts . Token ) . ContinueWith ( t =>
124
+ {
125
+ // TODO: log
126
+ #if DEBUG
127
+ if ( t . IsCanceled || t . Exception != null ) Debugger . Break ( ) ;
128
+ #endif
129
+ syncSessionCts . Dispose ( ) ;
130
+ } , CancellationToken . None ) ;
96
131
97
132
// Prevent the TrayWindow from closing, just hide it.
98
133
var trayWindow = _services . GetRequiredService < TrayWindow > ( ) ;
99
- trayWindow . Closed += ( sender , args ) =>
134
+ trayWindow . Closed += ( _ , closedArgs ) =>
100
135
{
101
136
if ( ! _handleWindowClosed ) return ;
102
- args . Handled = true ;
137
+ closedArgs . Handled = true ;
103
138
trayWindow . AppWindow . Hide ( ) ;
104
139
} ;
105
140
}
0 commit comments