From eb065088047ff9a11950d2be7691d57436397fc3 Mon Sep 17 00:00:00 2001 From: Coen van den Munckhof Date: Wed, 1 May 2024 19:41:34 +0200 Subject: [PATCH] implement --- .../Common/FilesFilterSettingsService.cs | 2 +- .../Git/AutoFetch/DefaultAutoFetchHandler.cs | 31 ++++++++----------- src/RepoM.Api/Git/IRepositoryView.cs | 2 ++ src/RepoM.Api/Git/RepositoryViewModel.cs | 4 ++- src/RepoM.App/App.xaml | 3 +- .../Converters/UtcToLocalDateTimeConverter.cs | 6 ++-- src/RepoM.App/MainWindow.xaml | 4 ++- src/RepoM.App/MainWindow.xaml.cs | 20 ++---------- src/RepoM.App/NotifyIconResources.xaml | 5 ++- 9 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/RepoM.Api/Common/FilesFilterSettingsService.cs b/src/RepoM.Api/Common/FilesFilterSettingsService.cs index ea9b2284..fb23ff34 100644 --- a/src/RepoM.Api/Common/FilesFilterSettingsService.cs +++ b/src/RepoM.Api/Common/FilesFilterSettingsService.cs @@ -56,7 +56,7 @@ private Dictionary Load() Dictionary? result = deserializer.Deserialize?>(yml); if (result == null) { - return new Dictionary(); + return new(); } foreach (KeyValuePair item in result) diff --git a/src/RepoM.Api/Git/AutoFetch/DefaultAutoFetchHandler.cs b/src/RepoM.Api/Git/AutoFetch/DefaultAutoFetchHandler.cs index 35440f13..cc12d34c 100644 --- a/src/RepoM.Api/Git/AutoFetch/DefaultAutoFetchHandler.cs +++ b/src/RepoM.Api/Git/AutoFetch/DefaultAutoFetchHandler.cs @@ -13,16 +13,19 @@ public class DefaultAutoFetchHandler : IAutoFetchHandler private readonly Timer _timer; private readonly Dictionary _profiles; private int _lastFetchRepository = -1; + private readonly IAppSettingsService _appSettingsService; + private readonly IRepositoryInformationAggregator _repositoryInformationAggregator; + private readonly IRepositoryWriter _repositoryWriter; public DefaultAutoFetchHandler( IAppSettingsService appSettingsService, IRepositoryInformationAggregator repositoryInformationAggregator, IRepositoryWriter repositoryWriter) { - AppSettingsService = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService)); - RepositoryInformationAggregator = repositoryInformationAggregator ?? throw new ArgumentNullException(nameof(repositoryInformationAggregator)); - RepositoryWriter = repositoryWriter ?? throw new ArgumentNullException(nameof(repositoryWriter)); - AppSettingsService.RegisterInvalidationHandler(() => Mode = AppSettingsService.AutoFetchMode); + _appSettingsService = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService)); + _repositoryInformationAggregator = repositoryInformationAggregator ?? throw new ArgumentNullException(nameof(repositoryInformationAggregator)); + _repositoryWriter = repositoryWriter ?? throw new ArgumentNullException(nameof(repositoryWriter)); + _appSettingsService.RegisterInvalidationHandler(() => Mode = _appSettingsService.AutoFetchMode); _profiles = new Dictionary { @@ -60,7 +63,7 @@ private void UpdateBehavior(AutoFetchMode mode) private void FetchNext(object? timerState) { - var hasAny = RepositoryInformationAggregator.Repositories?.Any() ?? false; + var hasAny = _repositoryInformationAggregator.Repositories?.Any() ?? false; if (!hasAny) { return; @@ -71,9 +74,9 @@ private void FetchNext(object? timerState) // 2. makes sure that no repository is jumped over because the list // of repositories is constantly changed and not sorted in any way in memory. // So we cannot guarantee that each repository is fetched on each iteration if we do not sort. - var repositories = RepositoryInformationAggregator.Repositories? - .OrderBy(r => r.Name) - .ToArray() ?? Array.Empty(); + var repositories = _repositoryInformationAggregator.Repositories? + .OrderBy(r => r.Name) + .ToArray() ?? []; // temporarily disable the timer to prevent parallel fetch executions UpdateBehavior(AutoFetchMode.Off); @@ -87,12 +90,10 @@ private void FetchNext(object? timerState) RepositoryViewModel repositoryViewModel = repositories[_lastFetchRepository]; - Console.WriteLine($"Auto-fetching {repositoryViewModel.Name} (index {_lastFetchRepository} of {repositories.Length})"); - repositoryViewModel.IsSynchronizing = true; try { - RepositoryWriter.Fetch(repositoryViewModel.Repository); + _repositoryWriter.Fetch(repositoryViewModel.Repository); } catch { @@ -116,7 +117,7 @@ public bool Active if (value && _mode == null) { - Mode = AppSettingsService.AutoFetchMode; + Mode = _appSettingsService.AutoFetchMode; } UpdateBehavior(); @@ -137,10 +138,4 @@ public AutoFetchMode Mode UpdateBehavior(); } } - - public IAppSettingsService AppSettingsService { get; } - - public IRepositoryInformationAggregator RepositoryInformationAggregator { get; } - - public IRepositoryWriter RepositoryWriter { get; } } \ No newline at end of file diff --git a/src/RepoM.Api/Git/IRepositoryView.cs b/src/RepoM.Api/Git/IRepositoryView.cs index 2a2fa629..1bfc6036 100644 --- a/src/RepoM.Api/Git/IRepositoryView.cs +++ b/src/RepoM.Api/Git/IRepositoryView.cs @@ -10,6 +10,8 @@ public interface IRepositoryView bool IsPinned { get; } + bool IsNotBare { get; } + bool HasUnpushedChanges { get; } Repository Repository { get; } diff --git a/src/RepoM.Api/Git/RepositoryViewModel.cs b/src/RepoM.Api/Git/RepositoryViewModel.cs index c536b890..f848d57d 100644 --- a/src/RepoM.Api/Git/RepositoryViewModel.cs +++ b/src/RepoM.Api/Git/RepositoryViewModel.cs @@ -53,6 +53,8 @@ private void EnsureStatusCache() public bool IsPinned => _monitor.IsPinned(Repository); + public bool IsNotBare => !Repository.IsBare; + public string Name => Repository.Name + (IsSynchronizing ? SyncAppendix : string.Empty); public string Path => Repository.Path; @@ -65,7 +67,7 @@ private void EnsureStatusCache() public string BehindBy => Repository.BehindBy?.ToString() ?? string.Empty; - public string[] Branches => Repository.Branches ?? Array.Empty(); + public string[] Branches => Repository.Branches ?? []; public string LocalUntracked => Repository.LocalUntracked?.ToString() ?? string.Empty; diff --git a/src/RepoM.App/App.xaml b/src/RepoM.App/App.xaml index 87cf4138..d47a215c 100644 --- a/src/RepoM.App/App.xaml +++ b/src/RepoM.App/App.xaml @@ -1,10 +1,9 @@  - + - +