diff --git a/ModerationClient/Services/ClientContainer.cs b/ModerationClient/Services/ClientContainer.cs
index fa3abef..957e3cc 100644
--- a/ModerationClient/Services/ClientContainer.cs
+++ b/ModerationClient/Services/ClientContainer.cs
@@ -1,8 +1,40 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
+
namespace ModerationClient.Services;
public class ClientContainer {
- public ClientContainer(MatrixAuthenticationService authService, CommandLineConfiguration cfg)
+ private readonly ILogger<ClientContainer> _logger;
+ private readonly MatrixAuthenticationService _authService;
+ private readonly CommandLineConfiguration _cfg;
+
+ public ClientContainer(ILogger<ClientContainer> logger, MatrixAuthenticationService authService, CommandLineConfiguration cfg) {
+ _logger = logger;
+ _authService = authService;
+ _cfg = cfg;
+ }
+
+ private bool _isRunning = false;
+
+ public void EnsureRunning()
+ {
+ if (_isRunning) return;
+ _isRunning = true;
+ _ = Task.Run(Run).ContinueWith(t => {
+ if (t.IsFaulted)
+ {
+ _logger.LogError(t.Exception, "Error in client container task");
+ }
+ return _isRunning = false;
+ });
+ }
+
+ private async Task Run()
{
+ Console.WriteLine("Running client view model loop...");
+ ArgumentNullException.ThrowIfNull(_authService.Homeserver, nameof(_authService.Homeserver));
}
}
\ No newline at end of file
diff --git a/ModerationClient/Services/CommandLineConfiguration.cs b/ModerationClient/Services/CommandLineConfiguration.cs
index 4f7da2d..fcb5072 100644
--- a/ModerationClient/Services/CommandLineConfiguration.cs
+++ b/ModerationClient/Services/CommandLineConfiguration.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+using System.Globalization;
using System.IO;
using System.Text.Json;
+using System.Text.Json.Serialization;
using ArcaneLibs;
using ArcaneLibs.Extensions;
@@ -35,10 +37,12 @@ public record CommandLineConfiguration {
List<string> args = new();
if (Profile != current.Profile) args.AddRange(["--profile", Profile]);
if (IsTemporary) args.Add("--temporary");
- if (Math.Abs(Scale - 1f) > float.Epsilon) args.AddRange(["--scale", Scale.ToString()]);
+ if (Math.Abs(Scale - 1f) > float.Epsilon) args.AddRange(["--scale", Scale.ToString(CultureInfo.InvariantCulture)]);
if (ProfileDirectory != current.ProfileDirectory) args.AddRange(["--profile-dir", ProfileDirectory]);
if (!string.IsNullOrWhiteSpace(_loginData) && _loginData != current.LoginData) args.AddRange(["--login-data", _loginData!]);
if (TestConfiguration is not null && TestConfiguration != current.TestConfiguration) args.AddRange(["--test-config", TestConfiguration!.ToJson()]);
+
+ Console.WriteLine("Serialised CommandLineConfiguration: " + string.Join(" ", args));
return args.ToArray();
}
public static CommandLineConfiguration FromSerialised(string[] args) {
@@ -85,11 +89,13 @@ public record CommandLineConfiguration {
}
}
+ [JsonIgnore]
private string? testConfiguration {
get => TestConfiguration?.ToJson();
init => TestConfiguration = value is null ? null : JsonSerializer.Deserialize<TestConfig>(value);
}
+ [JsonIgnore]
public TestConfig? TestConfiguration { get; init; }
public class TestConfig {
diff --git a/ModerationClient/Services/MatrixAuthenticationService.cs b/ModerationClient/Services/MatrixAuthenticationService.cs
index 46ec067..e4fb99b 100644
--- a/ModerationClient/Services/MatrixAuthenticationService.cs
+++ b/ModerationClient/Services/MatrixAuthenticationService.cs
@@ -28,6 +28,7 @@ public class MatrixAuthenticationService(ILogger<MatrixAuthenticationService> lo
if (login is null) return;
try {
Homeserver = await hsProvider.GetAuthenticatedWithToken(login.Homeserver, login.AccessToken);
+ await Homeserver.UpdateProfilePropertyAsync("meow", "h");
IsLoggedIn = true;
}
catch (MatrixException e) {
@@ -35,10 +36,15 @@ public class MatrixAuthenticationService(ILogger<MatrixAuthenticationService> lo
}
}
- public async Task LoginAsync(string username, string password) {
+ public async Task LoginAsync(string username, string password, string? homeserver = null) {
Directory.CreateDirectory(Util.ExpandPath($"{cfg.ProfileDirectory}")!);
- var mxidParts = username.Split(':', 2);
- var res = await hsProvider.Login(mxidParts[1], username, password);
+
+ if (string.IsNullOrWhiteSpace(homeserver)) {
+ var mxidParts = username.Split(':', 2);
+ homeserver = mxidParts[1];
+ }
+
+ var res = await hsProvider.Login(homeserver, username, password);
await File.WriteAllTextAsync(Path.Combine(cfg.ProfileDirectory, "login.json"), res.ToJson());
await LoadProfileAsync();
diff --git a/ModerationClient/Services/StatusBarService.cs b/ModerationClient/Services/StatusBarService.cs
index 57aff21..f1d7223 100644
--- a/ModerationClient/Services/StatusBarService.cs
+++ b/ModerationClient/Services/StatusBarService.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.ObjectModel;
using ArcaneLibs;
namespace ModerationClient.Services;
@@ -16,4 +17,21 @@ public class StatusBarService : NotifyPropertyChanged {
get => _isBusy;
set => SetField(ref _isBusy, value);
}
+
+ public ObservableCollection<Progress> ProgressBars { get; } = new();
+
+
+ public class Progress : NotifyPropertyChanged {
+ public Progress(int total) {
+ Total = total;
+ }
+
+ public int Total { get; }
+ public int Current { get; private set; }
+
+ public void Increment() {
+ Current++;
+ OnPropertyChanged(nameof(Current));
+ }
+ }
}
\ No newline at end of file
|