Skip to content

Commit

Permalink
Reduce interface usage, replace async void with async Task (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Dec 16, 2024
1 parent 7a7ca5f commit f8e405d
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Fronter.Extensions;

public static class NotificationMessageBuilderExtensions {
internal static class NotificationMessageBuilderExtensions {
public static NotificationMessageBuilder CreateError(this INotificationMessageManager manager) {
return manager
.CreateMessage()
Expand Down
4 changes: 2 additions & 2 deletions Fronter.NET/Extensions/TranslationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Fronter.Extensions;

// idea based on https://gist.github.com/jakubfijalkowski/0771bfbd26ce68456d3e
public sealed partial class TranslationSource : ReactiveObject {
internal sealed partial class TranslationSource : ReactiveObject {
private static readonly ILog logger = LogManager.GetLogger("Translator");
private TranslationSource() {
const string languagesPath = "languages.txt";
Expand Down Expand Up @@ -148,7 +148,7 @@ private void LoadLanguages() {
}
}

public IList<string> LoadedLanguages { get; } = [];
public List<string> LoadedLanguages { get; } = [];
private readonly Dictionary<string, CultureInfo> languages = [];
private readonly Dictionary<string, Dictionary<string, string>> translations = []; // key, <language, text>

Expand Down
4 changes: 4 additions & 0 deletions Fronter.NET/Fronter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@
<ItemGroup>
<Folder Include="Models\Database\" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Fronter.Tests"/>
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions Fronter.NET/Models/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Fronter.Models.Configuration;

public sealed class Config {
internal sealed class Config {
public string Name { get; private set; } = string.Empty;
public string ConverterFolder { get; private set; } = string.Empty;
public string BackendExePath { get; private set; } = string.Empty; // relative to ConverterFolder
Expand All @@ -28,9 +28,9 @@ public sealed class Config {
public string ConverterReleaseForumThread { get; private set; } = string.Empty;
public string LatestGitHubConverterReleaseUrl { get; private set; } = string.Empty;
public string PagesCommitIdUrl { get; private set; } = string.Empty;
public IList<RequiredFile> RequiredFiles { get; } = new List<RequiredFile>();
public IList<RequiredFolder> RequiredFolders { get; } = new List<RequiredFolder>();
public IList<Option> Options { get; } = new List<Option>();
public List<RequiredFile> RequiredFiles { get; } = [];
public List<RequiredFolder> RequiredFolders { get; } = [];
public List<Option> Options { get; } = [];
private int optionCounter;

private static readonly ILog logger = LogManager.GetLogger("Configuration");
Expand Down
8 changes: 4 additions & 4 deletions Fronter.NET/Models/Configuration/Options/CheckBoxSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Fronter.Models.Configuration.Options;

public sealed class CheckBoxSelector {
internal sealed class CheckBoxSelector {
public CheckBoxSelector(BufferedReader reader) {
var parser = new Parser();
RegisterKeys(parser);
Expand All @@ -20,15 +20,15 @@ private void RegisterKeys(Parser parser) {
parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreAndLogItem);
}

public ISet<string> GetSelectedValues() {
public HashSet<string> GetSelectedValues() {
var toReturn = new HashSet<string>(StringComparer.Ordinal);
foreach (ToggleableOption option in CheckBoxOptions.Where(option => option.Value)) {
toReturn.Add(option.Name);
}
return toReturn;
}

public ISet<int> GetSelectedIds() {
public HashSet<int> GetSelectedIds() {
var toReturn = new HashSet<int>();
foreach (ToggleableOption option in CheckBoxOptions.Where(option => option.Value)) {
toReturn.Add(option.Id);
Expand All @@ -49,5 +49,5 @@ public void SetSelectedValues(ISet<string> selection) {

private int optionCounter = 0;
public bool Preloaded { get; set; } = false;
public IList<ToggleableOption> CheckBoxOptions { get; } = new List<ToggleableOption>();
public List<ToggleableOption> CheckBoxOptions { get; } = [];
}
4 changes: 2 additions & 2 deletions Fronter.NET/Models/Configuration/Options/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Fronter.Models.Configuration.Options;

public sealed class Option {
internal sealed class Option {
private static readonly ILog logger = LogManager.GetLogger("Option");
public Option(BufferedReader reader, int id) {
Id = id;
Expand Down Expand Up @@ -78,7 +78,7 @@ public string GetValue() {
return string.Empty;
}

public ISet<string> GetValues() {
public HashSet<string> GetValues() {
return CheckBoxSelector is not null
? CheckBoxSelector.GetSelectedValues()
: new HashSet<string>(StringComparer.Ordinal);
Expand Down
4 changes: 2 additions & 2 deletions Fronter.NET/Models/Configuration/Options/RadioSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Fronter.Models.Configuration.Options;

public sealed class RadioSelector {
internal sealed class RadioSelector {
private static readonly ILog logger = LogManager.GetLogger("Radio selector");
public RadioSelector(BufferedReader reader) {
var parser = new Parser();
Expand Down Expand Up @@ -71,5 +71,5 @@ public ToggleableOption? SelectedOption {
}

private int optionCounter = 0;
public IList<ToggleableOption> RadioOptions { get; } = new List<ToggleableOption>();
public List<ToggleableOption> RadioOptions { get; } = [];
}
2 changes: 1 addition & 1 deletion Fronter.NET/Models/Configuration/RequiredFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Fronter.Models.Configuration;

public sealed class RequiredFolder : RequiredPath {
internal sealed class RequiredFolder : RequiredPath {
private static readonly ILog logger = LogManager.GetLogger("Required folder");
public RequiredFolder(BufferedReader reader, Config config) {
this.config = config;
Expand Down
2 changes: 1 addition & 1 deletion Fronter.NET/Services/SentryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Fronter.Services;

public sealed class SentryHelper {
internal sealed class SentryHelper {
public SentryHelper(Config config) {
this.config = config;
InitSentry();
Expand Down
4 changes: 2 additions & 2 deletions Fronter.NET/Services/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Fronter.Services;

public static class UpdateChecker {
internal static class UpdateChecker {
private static readonly ILog Logger = LogManager.GetLogger("Update checker");
private static readonly HttpClient HttpClient = new() {Timeout = TimeSpan.FromMinutes(5)};
public static async Task<bool> IsUpdateAvailable(string commitIdFilePath, string commitIdUrl) {
Expand Down Expand Up @@ -149,7 +149,7 @@ private static async Task DownloadFileAsync(string installerUrl, string fileName
await File.WriteAllBytesAsync(fileName, responseBytes);
}

public static async void RunInstallerAndDie(string installerUrl, Config config, INotificationMessageManager notificationManager) {
public static async Task RunInstallerAndDie(string installerUrl, Config config, INotificationMessageManager notificationManager) {
Logger.Debug("Downloading installer...");

var fileName = Path.GetTempFileName();
Expand Down
4 changes: 2 additions & 2 deletions Fronter.NET/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace Fronter.ViewModels;

[SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Global")]
public sealed class MainWindowViewModel : ViewModelBase {
internal sealed class MainWindowViewModel : ViewModelBase {
private static readonly ILog logger = LogManager.GetLogger("Frontend");
private readonly TranslationSource loc = TranslationSource.Instance;
public IEnumerable<MenuItemViewModel> LanguageMenuItems => loc.LoadedLanguages
Expand Down Expand Up @@ -313,7 +313,7 @@ await Dispatcher.UIThread.InvokeAsync(async () => {

// If we can use an installer, download it, run it, and exit.
if (info.UseInstaller) {
UpdateChecker.RunInstallerAndDie(info.AssetUrl, Config, NotificationManager);
await UpdateChecker.RunInstallerAndDie(info.AssetUrl, Config, NotificationManager);
} else{
UpdateChecker.StartUpdaterAndDie(info.AssetUrl, Config.ConverterFolder);
}
Expand Down
2 changes: 1 addition & 1 deletion Fronter.NET/ViewModels/OptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Fronter.ViewModels;

public sealed class OptionsViewModel : ViewModelBase {
internal sealed class OptionsViewModel : ViewModelBase {
public OptionsViewModel(IEnumerable<Option> items) {
Items = new ObservableCollection<Option>(items);
}
Expand Down

0 comments on commit f8e405d

Please sign in to comment.