Skip to content

Commit f7817a9

Browse files
committed
feat: wire up file sync window
1 parent da29411 commit f7817a9

12 files changed

+752
-145
lines changed

App/App.xaml.cs

+42-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Threading;
34
using System.Threading.Tasks;
45
using 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
}

App/Models/SyncSessionModel.cs

+4-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Coder.Desktop.App.Converters;
32
using Coder.Desktop.MutagenSdk.Proto.Synchronization;
43
using Coder.Desktop.MutagenSdk.Proto.Url;
@@ -64,6 +63,10 @@ public class SyncSessionModel
6463

6564
public readonly string[] Errors = [];
6665

66+
// If Paused is true, the session can be resumed. If false, the session can
67+
// be paused.
68+
public bool Paused => StatusCategory is SyncSessionStatusCategory.Paused or SyncSessionStatusCategory.Halted;
69+
6770
public string StatusDetails
6871
{
6972
get
@@ -84,37 +87,6 @@ public string SizeDetails
8487
}
8588
}
8689

87-
// TODO: remove once we process sessions from the mutagen RPC
88-
public SyncSessionModel(string alphaPath, string betaName, string betaPath,
89-
SyncSessionStatusCategory statusCategory,
90-
string statusString, string statusDescription, string[] errors)
91-
{
92-
Identifier = "TODO";
93-
Name = "TODO";
94-
95-
AlphaName = "Local";
96-
AlphaPath = alphaPath;
97-
BetaName = betaName;
98-
BetaPath = betaPath;
99-
StatusCategory = statusCategory;
100-
StatusString = statusString;
101-
StatusDescription = statusDescription;
102-
AlphaSize = new SyncSessionModelEndpointSize
103-
{
104-
SizeBytes = (ulong)new Random().Next(0, 1000000000),
105-
FileCount = (ulong)new Random().Next(0, 10000),
106-
DirCount = (ulong)new Random().Next(0, 10000),
107-
};
108-
BetaSize = new SyncSessionModelEndpointSize
109-
{
110-
SizeBytes = (ulong)new Random().Next(0, 1000000000),
111-
FileCount = (ulong)new Random().Next(0, 10000),
112-
DirCount = (ulong)new Random().Next(0, 10000),
113-
};
114-
115-
Errors = errors;
116-
}
117-
11890
public SyncSessionModel(State state)
11991
{
12092
Identifier = state.Session.Identifier;

0 commit comments

Comments
 (0)