Skip to content

Commit

Permalink
implement
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed May 1, 2024
1 parent e8de53f commit eb06508
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/RepoM.Api/Common/FilesFilterSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private Dictionary<string, RepositoryFilterConfiguration> Load()
Dictionary<string, RepositoryFilterConfiguration>? result = deserializer.Deserialize<Dictionary<string, RepositoryFilterConfiguration>?>(yml);
if (result == null)
{
return new Dictionary<string, RepositoryFilterConfiguration>();
return new();
}

foreach (KeyValuePair<string, RepositoryFilterConfiguration> item in result)
Expand Down
31 changes: 13 additions & 18 deletions src/RepoM.Api/Git/AutoFetch/DefaultAutoFetchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ public class DefaultAutoFetchHandler : IAutoFetchHandler
private readonly Timer _timer;
private readonly Dictionary<AutoFetchMode, AutoFetchProfile> _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<AutoFetchMode, AutoFetchProfile>
{
Expand Down Expand Up @@ -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;
Expand All @@ -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<RepositoryViewModel>();
var repositories = _repositoryInformationAggregator.Repositories?
.OrderBy(r => r.Name)
.ToArray() ?? [];

// temporarily disable the timer to prevent parallel fetch executions
UpdateBehavior(AutoFetchMode.Off);
Expand All @@ -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
{
Expand All @@ -116,7 +117,7 @@ public bool Active

if (value && _mode == null)
{
Mode = AppSettingsService.AutoFetchMode;
Mode = _appSettingsService.AutoFetchMode;
}

UpdateBehavior();
Expand All @@ -137,10 +138,4 @@ public AutoFetchMode Mode
UpdateBehavior();
}
}

public IAppSettingsService AppSettingsService { get; }

public IRepositoryInformationAggregator RepositoryInformationAggregator { get; }

public IRepositoryWriter RepositoryWriter { get; }
}
2 changes: 2 additions & 0 deletions src/RepoM.Api/Git/IRepositoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IRepositoryView

bool IsPinned { get; }

bool IsNotBare { get; }

bool HasUnpushedChanges { get; }

Repository Repository { get; }
Expand Down
4 changes: 3 additions & 1 deletion src/RepoM.Api/Git/RepositoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -65,7 +67,7 @@ private void EnsureStatusCache()

public string BehindBy => Repository.BehindBy?.ToString() ?? string.Empty;

public string[] Branches => Repository.Branches ?? Array.Empty<string>();
public string[] Branches => Repository.Branches ?? [];

public string LocalUntracked => Repository.LocalUntracked?.ToString() ?? string.Empty;

Expand Down
3 changes: 1 addition & 2 deletions src/RepoM.App/App.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Application x:Class="RepoM.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RepoM.App"
xmlns:controls="clr-namespace:RepoM.App.Controls"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<Application.Resources>

<!--
Note that this application does not have a StartupUri declared, so no Window is automatically loaded.
Expand Down
6 changes: 3 additions & 3 deletions src/RepoM.App/Converters/UtcToLocalDateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace RepoM.App.Converters;

public class UtcToLocalDateTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return DateTime.SpecifyKind(DateTime.Parse(value.ToString() ?? string.Empty), DateTimeKind.Utc).ToLocalTime();
return DateTime.SpecifyKind(DateTime.Parse(value?.ToString() ?? string.Empty), DateTimeKind.Utc).ToLocalTime();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
4 changes: 3 additions & 1 deletion src/RepoM.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@
</StackPanel>
<TextBlock Text="{Binding CurrentBranch}"
FontSize="13.5"
Margin="8, 3, 8, 3" />
Margin="8, 3, 8, 3"
Visibility="{Binding Path=IsNotBare, Converter={StaticResource BooleanToVisibilityConverter}}"
/>
<StackPanel Orientation="Horizontal">

<Border Margin="8, 5, 8, 3"
Expand Down
20 changes: 3 additions & 17 deletions src/RepoM.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public MainWindow(

InitializeComponent();

AcrylicWindow.SetAcrylicWindowStyle(this, AcrylicWindowStyle.None);
SetAcrylicWindowStyle(this, AcrylicWindowStyle.None);

var orderingsViewModel = new OrderingsViewModel(repositoryComparerManager, threadDispatcher);
var queryParsersViewModel = new QueryParsersViewModel(_repositoryFilteringManager, threadDispatcher);
Expand Down Expand Up @@ -128,7 +128,6 @@ protected override void OnActivated(EventArgs e)
ShowUpdateIfAvailable();
txtFilter.Focus();
txtFilter.SelectAll();
TryFixFreeze();
}

protected override void OnDeactivated(EventArgs e)
Expand Down Expand Up @@ -177,22 +176,9 @@ public void ShowAndActivate()
Activate();
txtFilter.Focus();
txtFilter.SelectAll();
TryFixFreeze();
});
}

private void TryFixFreeze()
{
if (!"true".Equals(Environment.GetEnvironmentVariable("REPO_ONE_TRY_FIX_FREEZE")))
{
return;
}

var w = Width;
Width += 0.001;
Width = w;
}

private void OnScanStateChanged(object? sender, bool isScanning)
{
Dispatcher.Invoke(() => ShowScanningState(isScanning));
Expand Down Expand Up @@ -758,11 +744,11 @@ protected override void OnKeyDown(KeyEventArgs e)
// show/hide the titlebar to move the window for screenshots, for example
if (e.Key == Key.F11)
{
AcrylicWindowStyle currentStyle = AcrylicWindow.GetAcrylicWindowStyle(this);
AcrylicWindowStyle currentStyle = GetAcrylicWindowStyle(this);
AcrylicWindowStyle newStyle = currentStyle == AcrylicWindowStyle.None
? AcrylicWindowStyle.Normal
: AcrylicWindowStyle.None;
AcrylicWindow.SetAcrylicWindowStyle(this, newStyle);
SetAcrylicWindowStyle(this, newStyle);
}

// keep window open on deactivate to make screenshots, for example
Expand Down
5 changes: 2 additions & 3 deletions src/RepoM.App/NotifyIconResources.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:RepoM.App"
xmlns:controls="clr-namespace:RepoM.App.Controls"
xmlns:app="clr-namespace:RepoM.App">

Expand All @@ -10,7 +9,7 @@
The "shared" directive is needed if we reopen the sample window a few times - WPF will otherwise
reuse the same context menu (which is a resource) again (which will have its DataContext set to the old TaskbarIcon)
-->
<controls:AcrylicContextMenu x:Shared="false" x:Key="SysTrayMenu" >
<controls:AcrylicContextMenu x:Shared="false" x:Key="SysTrayMenu">
<controls:AcrylicMenuItem Header="{DynamicResource Open}" Command="{Binding OpenCommand}" />
<controls:AcrylicMenuItem Header="{DynamicResource StartWithWindows}"
Command="{Binding StartWithWindows}"
Expand All @@ -29,7 +28,7 @@
<tb:TaskbarIcon x:Key="NotifyIcon"
IconSource="/App.ico"
LeftClickCommand="{Binding OpenCommand}"
NoLeftClickDelay="True"
NoLeftClickDelay="False"
ContextMenu="{StaticResource SysTrayMenu}">

<!-- self-assign a data context (could also be done programmatically) -->
Expand Down

0 comments on commit eb06508

Please sign in to comment.