mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2026-10-29 01:26:09 +03:00
Reformat code
This commit is contained in:
137 files changed
+1587
-1573
No files matched your search
@@ -21,19 +21,19 @@ sealed partial class DownloadItemFilterPanelModel : ObservableObject, IAsyncDisp
|
||||
public sealed record Unit(string Name, uint Scale);
|
||||
|
||||
private static readonly Unit[] AllUnits = [
|
||||
new Unit("B", 1),
|
||||
new Unit("kB", 1024),
|
||||
new Unit("MB", 1024 * 1024)
|
||||
new Unit("B", Scale: 1),
|
||||
new Unit("kB", Scale: 1024),
|
||||
new Unit("MB", Scale: 1024 * 1024)
|
||||
];
|
||||
|
||||
|
||||
private static readonly HashSet<string> FilterProperties = [
|
||||
nameof(LimitSize),
|
||||
nameof(MaximumSize),
|
||||
nameof(MaximumSizeUnit)
|
||||
nameof(MaximumSizeUnit),
|
||||
];
|
||||
|
||||
|
||||
public string FilterStatisticsText { get; private set; } = "";
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private bool limitSize = false;
|
||||
|
||||
@@ -42,51 +42,51 @@ sealed partial class DownloadItemFilterPanelModel : ObservableObject, IAsyncDisp
|
||||
|
||||
[ObservableProperty]
|
||||
private Unit maximumSizeUnit = AllUnits[0];
|
||||
|
||||
|
||||
public IEnumerable<Unit> Units => AllUnits;
|
||||
|
||||
|
||||
private readonly State state;
|
||||
private readonly string verb;
|
||||
|
||||
|
||||
private readonly DelayedThrottledTask<FilterSettings> saveFilterSettingsTask;
|
||||
private bool isLoadingFilterSettings;
|
||||
|
||||
|
||||
private readonly RestartableTask<long> downloadItemCountTask;
|
||||
private long? matchingItemCount;
|
||||
|
||||
private readonly IDisposable downloadItemCountSubscription;
|
||||
private long? totalItemCount;
|
||||
|
||||
|
||||
[Obsolete("Designer")]
|
||||
public DownloadItemFilterPanelModel() : this(State.Dummy) {}
|
||||
|
||||
|
||||
public DownloadItemFilterPanelModel(State state, string verb = "Matches") {
|
||||
this.state = state;
|
||||
this.verb = verb;
|
||||
|
||||
|
||||
this.saveFilterSettingsTask = new DelayedThrottledTask<FilterSettings>(Log, TimeSpan.FromSeconds(5), SaveFilterSettings);
|
||||
|
||||
|
||||
this.downloadItemCountTask = new RestartableTask<long>(SetMatchingCount, TaskScheduler.FromCurrentSynchronizationContext());
|
||||
this.downloadItemCountSubscription = state.Db.Downloads.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(OnDownloadItemCountChanged);
|
||||
|
||||
|
||||
UpdateFilterStatistics();
|
||||
|
||||
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
|
||||
public async Task Initialize() {
|
||||
isLoadingFilterSettings = true;
|
||||
|
||||
LimitSize = await state.Db.Settings.Get(SettingsKey.DownloadsLimitSize, LimitSize);
|
||||
MaximumSize = await state.Db.Settings.Get(SettingsKey.DownloadsMaximumSize, MaximumSize);
|
||||
|
||||
if (await state.Db.Settings.Get(SettingsKey.DownloadsMaximumSizeUnit, null) is {} unitName && AllUnits.FirstOrDefault(unit => unit.Name == unitName) is {} unitValue) {
|
||||
|
||||
if (await state.Db.Settings.Get(SettingsKey.DownloadsMaximumSizeUnit, defaultValue: null) is {} unitName && AllUnits.FirstOrDefault(unit => unit.Name == unitName) is {} unitValue) {
|
||||
MaximumSizeUnit = unitValue;
|
||||
}
|
||||
|
||||
isLoadingFilterSettings = false;
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask DisposeAsync() {
|
||||
saveFilterSettingsTask.Dispose();
|
||||
|
||||
@@ -112,7 +112,7 @@ sealed partial class DownloadItemFilterPanelModel : ObservableObject, IAsyncDisp
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName != null && FilterProperties.Contains(e.PropertyName)) {
|
||||
if (!isLoadingFilterSettings) {
|
||||
@@ -128,9 +128,9 @@ sealed partial class DownloadItemFilterPanelModel : ObservableObject, IAsyncDisp
|
||||
UpdateFilterStatistics();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UpdateFilterStatistics() {
|
||||
var filter = CreateFilter();
|
||||
DownloadItemFilter filter = CreateFilter();
|
||||
if (filter.IsEmpty) {
|
||||
downloadItemCountTask.Cancel();
|
||||
matchingItemCount = totalItemCount;
|
||||
@@ -142,23 +142,23 @@ sealed partial class DownloadItemFilterPanelModel : ObservableObject, IAsyncDisp
|
||||
downloadItemCountTask.Restart(cancellationToken => state.Db.Downloads.Count(filter, cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetMatchingCount(long matchingAttachmentCount) {
|
||||
this.matchingItemCount = matchingAttachmentCount;
|
||||
UpdateFilterStatisticsText();
|
||||
}
|
||||
|
||||
|
||||
private void UpdateFilterStatisticsText() {
|
||||
var matchingItemCountStr = matchingItemCount?.Format() ?? "(...)";
|
||||
var totalItemCountStr = totalItemCount?.Format() ?? "(...)";
|
||||
|
||||
string matchingItemCountStr = matchingItemCount?.Format() ?? "(...)";
|
||||
string totalItemCountStr = totalItemCount?.Format() ?? "(...)";
|
||||
|
||||
FilterStatisticsText = verb + " " + matchingItemCountStr + " out of " + totalItemCountStr + " file" + (totalItemCount is null or 1 ? "." : "s.");
|
||||
OnPropertyChanged(nameof(FilterStatisticsText));
|
||||
}
|
||||
|
||||
|
||||
public DownloadItemFilter CreateFilter() {
|
||||
DownloadItemFilter filter = new ();
|
||||
|
||||
|
||||
if (LimitSize) {
|
||||
try {
|
||||
filter.MaxBytes = maximumSize * maximumSizeUnit.Scale;
|
||||
@@ -166,7 +166,7 @@ sealed partial class DownloadItemFilterPanelModel : ObservableObject, IAsyncDisp
|
||||
// set no size limit, because the overflown size is larger than any file could possibly be
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace DHT.Desktop.Main.Controls;
|
||||
@@ -7,16 +8,16 @@ namespace DHT.Desktop.Main.Controls;
|
||||
public sealed partial class MessageFilterPanel : UserControl {
|
||||
public MessageFilterPanel() {
|
||||
InitializeComponent();
|
||||
|
||||
var culture = Program.Culture;
|
||||
foreach (var picker in new CalendarDatePicker[] { StartDatePicker, EndDatePicker }) {
|
||||
|
||||
CultureInfo culture = Program.Culture;
|
||||
foreach (CalendarDatePicker picker in new CalendarDatePicker[] { StartDatePicker, EndDatePicker }) {
|
||||
picker.FirstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
|
||||
picker.SelectedDateFormat = CalendarDatePickerFormat.Custom;
|
||||
picker.CustomDateFormatString = culture.DateTimeFormat.ShortDatePattern;
|
||||
picker.Watermark = culture.DateTimeFormat.ShortDatePattern;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CalendarDatePicker_OnSelectedDateChanged(object? sender, SelectionChangedEventArgs e) {
|
||||
if (DataContext is MessageFilterPanelModel model) {
|
||||
model.StartDate = StartDatePicker.SelectedDate;
|
||||
|
||||
@@ -27,46 +27,46 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
nameof(FilterByChannel),
|
||||
nameof(IncludedChannels),
|
||||
nameof(FilterByUser),
|
||||
nameof(IncludedUsers)
|
||||
nameof(IncludedUsers),
|
||||
];
|
||||
|
||||
|
||||
public string FilterStatisticsText { get; private set; } = "";
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler? FilterPropertyChanged;
|
||||
|
||||
|
||||
public bool HasAnyFilters => FilterByDate || FilterByChannel || FilterByUser;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private bool filterByDate = false;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTime? startDate = null;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTime? endDate = null;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private bool filterByChannel = false;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private HashSet<ulong>? includedChannels = null;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private bool filterByUser = false;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private HashSet<ulong>? includedUsers = null;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private string channelFilterLabel = "";
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private string userFilterLabel = "";
|
||||
|
||||
|
||||
private readonly Window window;
|
||||
private readonly State state;
|
||||
private readonly string verb;
|
||||
|
||||
|
||||
private readonly RestartableTask<long> exportedMessageCountTask;
|
||||
private long? exportedMessageCount;
|
||||
|
||||
@@ -78,28 +78,28 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
|
||||
private readonly IDisposable userCountSubscription;
|
||||
private long? totalUserCount;
|
||||
|
||||
|
||||
[Obsolete("Designer")]
|
||||
public MessageFilterPanelModel() : this(null!, State.Dummy) {}
|
||||
|
||||
|
||||
public MessageFilterPanelModel(Window window, State state, string verb = "Matches") {
|
||||
this.window = window;
|
||||
this.state = state;
|
||||
this.verb = verb;
|
||||
|
||||
|
||||
this.exportedMessageCountTask = new RestartableTask<long>(SetExportedMessageCount, TaskScheduler.FromCurrentSynchronizationContext());
|
||||
|
||||
this.messageCountSubscription = state.Db.Messages.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(OnMessageCountChanged);
|
||||
this.channelCountSubscription = state.Db.Channels.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(OnChannelCountChanged);
|
||||
this.userCountSubscription = state.Db.Users.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(OnUserCountChanged);
|
||||
|
||||
|
||||
UpdateFilterStatistics();
|
||||
UpdateChannelFilterLabel();
|
||||
UpdateUserFilterLabel();
|
||||
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
|
||||
public void Dispose() {
|
||||
exportedMessageCountTask.Cancel();
|
||||
|
||||
@@ -107,13 +107,13 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
channelCountSubscription.Dispose();
|
||||
userCountSubscription.Dispose();
|
||||
}
|
||||
|
||||
|
||||
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName != null && FilterProperties.Contains(e.PropertyName)) {
|
||||
UpdateFilterStatistics();
|
||||
FilterPropertyChanged?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
|
||||
if (e.PropertyName is nameof(FilterByChannel) or nameof(IncludedChannels)) {
|
||||
UpdateChannelFilterLabel();
|
||||
}
|
||||
@@ -121,12 +121,12 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
UpdateUserFilterLabel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnMessageCountChanged(long newMessageCount) {
|
||||
totalMessageCount = newMessageCount;
|
||||
UpdateFilterStatistics();
|
||||
}
|
||||
|
||||
|
||||
private void OnChannelCountChanged(long newChannelCount) {
|
||||
totalChannelCount = newChannelCount;
|
||||
UpdateChannelFilterLabel();
|
||||
@@ -136,7 +136,7 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
totalUserCount = newUserCount;
|
||||
UpdateUserFilterLabel();
|
||||
}
|
||||
|
||||
|
||||
private void UpdateChannelFilterLabel() {
|
||||
if (totalChannelCount.HasValue) {
|
||||
long total = totalChannelCount.Value;
|
||||
@@ -147,7 +147,7 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
ChannelFilterLabel = "Loading...";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateUserFilterLabel() {
|
||||
if (totalUserCount.HasValue) {
|
||||
long total = totalUserCount.Value;
|
||||
@@ -158,9 +158,9 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
UserFilterLabel = "Loading...";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateFilterStatistics() {
|
||||
var filter = CreateFilter();
|
||||
MessageFilter filter = CreateFilter();
|
||||
if (filter.IsEmpty) {
|
||||
exportedMessageCountTask.Cancel();
|
||||
exportedMessageCount = totalMessageCount;
|
||||
@@ -172,38 +172,38 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
exportedMessageCountTask.Restart(cancellationToken => state.Db.Messages.Count(filter, cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetExportedMessageCount(long exportedMessageCount) {
|
||||
this.exportedMessageCount = exportedMessageCount;
|
||||
UpdateFilterStatisticsText();
|
||||
}
|
||||
|
||||
|
||||
private void UpdateFilterStatisticsText() {
|
||||
var exportedMessageCountStr = exportedMessageCount?.Format() ?? "(...)";
|
||||
var totalMessageCountStr = totalMessageCount?.Format() ?? "(...)";
|
||||
|
||||
string exportedMessageCountStr = exportedMessageCount?.Format() ?? "(...)";
|
||||
string totalMessageCountStr = totalMessageCount?.Format() ?? "(...)";
|
||||
|
||||
FilterStatisticsText = verb + " " + exportedMessageCountStr + " out of " + totalMessageCountStr + " message" + (totalMessageCount is null or 1 ? "." : "s.");
|
||||
OnPropertyChanged(nameof(FilterStatisticsText));
|
||||
}
|
||||
|
||||
|
||||
public async Task OpenChannelFilterDialog() {
|
||||
async Task<List<CheckBoxItem<ulong>>> PrepareChannelItems(ProgressDialog dialog) {
|
||||
var items = new List<CheckBoxItem<ulong>>();
|
||||
var servers = await state.Db.Servers.Get().ToDictionaryAsync(static server => server.Id);
|
||||
|
||||
await foreach (var channel in state.Db.Channels.Get()) {
|
||||
var channelId = channel.Id;
|
||||
var channelName = channel.Name;
|
||||
|
||||
Dictionary<ulong, DHT.Server.Data.Server> servers = await state.Db.Servers.Get().ToDictionaryAsync(static server => server.Id);
|
||||
|
||||
await foreach (Channel channel in state.Db.Channels.Get()) {
|
||||
ulong channelId = channel.Id;
|
||||
string channelName = channel.Name;
|
||||
|
||||
string title;
|
||||
if (servers.TryGetValue(channel.Server, out var server)) {
|
||||
var titleBuilder = new StringBuilder();
|
||||
var serverType = server.Type;
|
||||
|
||||
ServerType? serverType = server.Type;
|
||||
|
||||
titleBuilder.Append('[')
|
||||
.Append(ServerTypes.ToString(serverType))
|
||||
.Append("] ");
|
||||
|
||||
|
||||
if (serverType == ServerType.DirectMessage) {
|
||||
titleBuilder.Append(channelName);
|
||||
}
|
||||
@@ -212,24 +212,24 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
.Append(" - ")
|
||||
.Append(channelName);
|
||||
}
|
||||
|
||||
|
||||
title = titleBuilder.ToString();
|
||||
}
|
||||
else {
|
||||
title = channelName;
|
||||
}
|
||||
|
||||
|
||||
items.Add(new CheckBoxItem<ulong>(channelId) {
|
||||
Title = title,
|
||||
IsChecked = IncludedChannels == null || IncludedChannels.Contains(channelId)
|
||||
IsChecked = IncludedChannels == null || IncludedChannels.Contains(channelId),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
const string Title = "Included Channels";
|
||||
|
||||
|
||||
List<CheckBoxItem<ulong>> items;
|
||||
try {
|
||||
items = await ProgressDialog.ShowIndeterminate(window, Title, "Loading channels...", PrepareChannelItems);
|
||||
@@ -237,29 +237,29 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
await Dialog.ShowOk(window, Title, "Error loading channels: " + e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await OpenIdFilterDialog(Title, items);
|
||||
|
||||
HashSet<ulong>? result = await OpenIdFilterDialog(Title, items);
|
||||
if (result != null) {
|
||||
IncludedChannels = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task OpenUserFilterDialog() {
|
||||
async Task<List<CheckBoxItem<ulong>>> PrepareUserItems(ProgressDialog dialog) {
|
||||
var checkBoxItems = new List<CheckBoxItem<ulong>>();
|
||||
|
||||
await foreach (var user in state.Db.Users.Get()) {
|
||||
|
||||
await foreach (User user in state.Db.Users.Get()) {
|
||||
checkBoxItems.Add(new CheckBoxItem<ulong>(user.Id) {
|
||||
Title = user.DisplayName == null ? user.Name : $"{user.DisplayName} ({user.Name})",
|
||||
IsChecked = IncludedUsers == null || IncludedUsers.Contains(user.Id)
|
||||
IsChecked = IncludedUsers == null || IncludedUsers.Contains(user.Id),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return checkBoxItems;
|
||||
}
|
||||
|
||||
|
||||
const string Title = "Included Users";
|
||||
|
||||
|
||||
List<CheckBoxItem<ulong>> items;
|
||||
try {
|
||||
items = await ProgressDialog.ShowIndeterminate(window, Title, "Loading users...", PrepareUserItems);
|
||||
@@ -267,42 +267,42 @@ sealed partial class MessageFilterPanelModel : ObservableObject, IDisposable {
|
||||
await Dialog.ShowOk(window, Title, "Error loading users: " + e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await OpenIdFilterDialog(Title, items);
|
||||
|
||||
HashSet<ulong>? result = await OpenIdFilterDialog(Title, items);
|
||||
if (result != null) {
|
||||
IncludedUsers = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task<HashSet<ulong>?> OpenIdFilterDialog(string title, List<CheckBoxItem<ulong>> items) {
|
||||
items.Sort(static (item1, item2) => item1.Title.CompareTo(item2.Title));
|
||||
|
||||
|
||||
var model = new CheckBoxDialogModel<ulong>(items) {
|
||||
Title = title
|
||||
Title = title,
|
||||
};
|
||||
|
||||
|
||||
var dialog = new CheckBoxDialog { DataContext = model };
|
||||
var result = await dialog.ShowDialog<DialogResult.OkCancel>(window);
|
||||
|
||||
|
||||
return result == DialogResult.OkCancel.Ok ? model.SelectedItems.Select(static item => item.Item).ToHashSet() : null;
|
||||
}
|
||||
|
||||
|
||||
public MessageFilter CreateFilter() {
|
||||
MessageFilter filter = new ();
|
||||
|
||||
|
||||
if (FilterByDate) {
|
||||
filter.StartDate = StartDate;
|
||||
filter.EndDate = EndDate?.AddDays(1).AddMilliseconds(-1);
|
||||
}
|
||||
|
||||
|
||||
if (FilterByChannel && IncludedChannels != null) {
|
||||
filter.ChannelIds = new HashSet<ulong>(IncludedChannels);
|
||||
}
|
||||
|
||||
|
||||
if (FilterByUser && IncludedUsers != null) {
|
||||
filter.UserIds = new HashSet<ulong>(IncludedUsers);
|
||||
}
|
||||
|
||||
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
@@ -17,24 +17,24 @@ sealed partial class ServerConfigurationPanelModel : ObservableObject, IDisposab
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(HasMadeChanges))]
|
||||
private string inputPort;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(HasMadeChanges))]
|
||||
private string inputToken;
|
||||
|
||||
|
||||
public bool HasMadeChanges => ServerConfiguration.Port.ToString() != InputPort || ServerConfiguration.Token != InputToken;
|
||||
|
||||
|
||||
[ObservableProperty(Setter = Access.Private)]
|
||||
private bool isToggleServerButtonEnabled = true;
|
||||
|
||||
|
||||
public string ToggleServerButtonText => server.IsRunning ? "Stop Server" : "Start Server";
|
||||
|
||||
|
||||
private readonly Window window;
|
||||
private readonly ServerManager server;
|
||||
|
||||
|
||||
[Obsolete("Designer")]
|
||||
public ServerConfigurationPanelModel() : this(null!, State.Dummy) {}
|
||||
|
||||
|
||||
public ServerConfigurationPanelModel(Window window, State state) {
|
||||
this.window = window;
|
||||
this.server = state.Server;
|
||||
@@ -43,19 +43,19 @@ sealed partial class ServerConfigurationPanelModel : ObservableObject, IDisposab
|
||||
|
||||
server.StatusChanged += OnServerStatusChanged;
|
||||
}
|
||||
|
||||
|
||||
public void Dispose() {
|
||||
server.StatusChanged -= OnServerStatusChanged;
|
||||
}
|
||||
|
||||
|
||||
private void OnServerStatusChanged(object? sender, ServerManager.Status e) {
|
||||
Dispatcher.UIThread.InvokeAsync(UpdateServerStatus);
|
||||
}
|
||||
|
||||
|
||||
private void UpdateServerStatus() {
|
||||
OnPropertyChanged(nameof(ToggleServerButtonText));
|
||||
}
|
||||
|
||||
|
||||
private async Task StartServer() {
|
||||
IsToggleServerButtonEnabled = false;
|
||||
|
||||
@@ -69,7 +69,7 @@ sealed partial class ServerConfigurationPanelModel : ObservableObject, IDisposab
|
||||
UpdateServerStatus();
|
||||
IsToggleServerButtonEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
private async Task StopServer() {
|
||||
IsToggleServerButtonEnabled = false;
|
||||
|
||||
@@ -83,7 +83,7 @@ sealed partial class ServerConfigurationPanelModel : ObservableObject, IDisposab
|
||||
UpdateServerStatus();
|
||||
IsToggleServerButtonEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
public async Task OnClickToggleServerButton() {
|
||||
if (server.IsRunning) {
|
||||
await StopServer();
|
||||
@@ -92,17 +92,17 @@ sealed partial class ServerConfigurationPanelModel : ObservableObject, IDisposab
|
||||
await StartServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnClickRandomizeToken() {
|
||||
InputToken = ServerUtils.GenerateRandomToken(20);
|
||||
}
|
||||
|
||||
|
||||
public async Task OnClickApplyChanges() {
|
||||
if (!ushort.TryParse(InputPort, out ushort port)) {
|
||||
await Dialog.ShowOk(window, "Invalid Port", "Port must be a number between 0 and 65535.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ServerConfiguration.Port = port;
|
||||
ServerConfiguration.Token = inputToken;
|
||||
|
||||
@@ -110,7 +110,7 @@ sealed partial class ServerConfigurationPanelModel : ObservableObject, IDisposab
|
||||
|
||||
await StartServer();
|
||||
}
|
||||
|
||||
|
||||
public void OnClickCancelChanges() {
|
||||
InputPort = ServerConfiguration.Port.ToString();
|
||||
InputToken = ServerConfiguration.Token;
|
||||
|
||||
@@ -17,38 +17,38 @@ sealed partial class StatusBarModel : ObservableObject, IDisposable {
|
||||
|
||||
[ObservableProperty(Setter = Access.Private)]
|
||||
private long? messageCount;
|
||||
|
||||
|
||||
[ObservableProperty(Setter = Access.Private)]
|
||||
[NotifyPropertyChangedFor(nameof(ServerStatusText))]
|
||||
private ServerManager.Status serverStatus;
|
||||
|
||||
|
||||
public string ServerStatusText => serverStatus switch {
|
||||
ServerManager.Status.Starting => "STARTING",
|
||||
ServerManager.Status.Started => "READY",
|
||||
ServerManager.Status.Stopping => "STOPPING",
|
||||
ServerManager.Status.Stopped => "STOPPED",
|
||||
_ => ""
|
||||
_ => "",
|
||||
};
|
||||
|
||||
|
||||
private readonly State state;
|
||||
private readonly IDisposable serverCountSubscription;
|
||||
private readonly IDisposable channelCountSubscription;
|
||||
private readonly IDisposable messageCountSubscription;
|
||||
|
||||
|
||||
[Obsolete("Designer")]
|
||||
public StatusBarModel() : this(State.Dummy) {}
|
||||
|
||||
|
||||
public StatusBarModel(State state) {
|
||||
this.state = state;
|
||||
|
||||
serverCountSubscription = state.Db.Servers.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(newServerCount => ServerCount = newServerCount);
|
||||
channelCountSubscription = state.Db.Channels.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(newChannelCount => ChannelCount = newChannelCount);
|
||||
messageCountSubscription = state.Db.Messages.TotalCount.ObserveOn(AvaloniaScheduler.Instance).Subscribe(newMessageCount => MessageCount = newMessageCount);
|
||||
|
||||
|
||||
state.Server.StatusChanged += OnServerStatusChanged;
|
||||
serverStatus = state.Server.IsRunning ? ServerManager.Status.Started : ServerManager.Status.Stopped;
|
||||
}
|
||||
|
||||
|
||||
public void Dispose() {
|
||||
serverCountSubscription.Dispose();
|
||||
channelCountSubscription.Dispose();
|
||||
@@ -56,7 +56,7 @@ sealed partial class StatusBarModel : ObservableObject, IDisposable {
|
||||
|
||||
state.Server.StatusChanged -= OnServerStatusChanged;
|
||||
}
|
||||
|
||||
|
||||
private void OnServerStatusChanged(object? sender, ServerManager.Status e) {
|
||||
Dispatcher.UIThread.InvokeAsync(() => ServerStatus = e);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user