11using System ;
2+ using System . Diagnostics ;
23using System . Threading ;
34using System . Threading . Tasks ;
45using Coder . Desktop . App . Models ;
@@ -73,6 +74,8 @@ public async Task ExitApplication()
7374 {
7475 _handleWindowClosed = false ;
7576 Exit ( ) ;
77+ var syncController = _services . GetRequiredService < ISyncSessionController > ( ) ;
78+ await syncController . DisposeAsync ( ) ;
7679 var rpcController = _services . GetRequiredService < IRpcController > ( ) ;
7780 // TODO: send a StopRequest if we're connected???
7881 await rpcController . DisposeAsync ( ) ;
@@ -86,20 +89,52 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
8689 if ( rpcController . GetState ( ) . RpcLifecycle == RpcLifecycle . Disconnected )
8790 // Passing in a CT with no cancellation is desired here, because
8891 // 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+ } ) ;
90103
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 ) ) ;
94106 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 ) ;
96131
97132 // Prevent the TrayWindow from closing, just hide it.
98133 var trayWindow = _services . GetRequiredService < TrayWindow > ( ) ;
99- trayWindow . Closed += ( sender , args ) =>
134+ trayWindow . Closed += ( _ , closedArgs ) =>
100135 {
101136 if ( ! _handleWindowClosed ) return ;
102- args . Handled = true ;
137+ closedArgs . Handled = true ;
103138 trayWindow . AppWindow . Hide ( ) ;
104139 } ;
105140 }
0 commit comments