-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMainWindowViewModel.cs
More file actions
45 lines (41 loc) · 1.13 KB
/
MainWindowViewModel.cs
File metadata and controls
45 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.ComponentModel;
using System.Runtime.CompilerServices;
using PowerSync.Common.Client;
namespace PowersyncDotnetTodoList.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
#region Fields
private readonly PowerSyncDatabase _db;
private bool _connected = false;
#endregion
#region Properties
public bool Connected
{
get => _connected;
set
{
if (_connected != value)
{
_connected = value;
OnPropertyChanged();
}
}
}
#endregion
#region Constructor
public MainWindowViewModel(PowerSyncDatabase db)
{
_db = db;
// Set up the listener to track the status changes
_ = Task.Run(async () =>
{
await foreach (var update in _db.Events.OnStatusChanged.ListenAsync(new CancellationToken()))
{
Connected = update.Status.Connected;
}
});
}
#endregion
}
}