Skip to content

Commit bfdd73d

Browse files
committed
feature: auto-fetch now is a global setting instead of per-repo setting (#2050)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 42734b9 commit bfdd73d

File tree

6 files changed

+36
-56
lines changed

6 files changed

+36
-56
lines changed

src/Models/RepositorySettings.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ public string ConventionalTypesOverride
3030
set;
3131
} = string.Empty;
3232

33-
public bool EnableAutoFetch
34-
{
35-
get;
36-
set;
37-
} = false;
38-
39-
public int AutoFetchInterval
40-
{
41-
get;
42-
set;
43-
} = 10;
44-
4533
public bool AskBeforeAutoUpdatingSubmodules
4634
{
4735
get;

src/ViewModels/Preferences.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ public bool IgnoreCRAtEOLInDiff
254254
}
255255
}
256256

257+
public bool EnableAutoFetch
258+
{
259+
get;
260+
set;
261+
} = false;
262+
263+
public int AutoFetchInterval
264+
{
265+
get;
266+
set;
267+
} = 10;
268+
257269
public bool IgnoreWhitespaceChangesInDiff
258270
{
259271
get => _ignoreWhitespaceChangesInDiff;

src/ViewModels/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ private async Task AutoFetchOnUIThread()
18871887

18881888
try
18891889
{
1890-
if (_settings is not { EnableAutoFetch: true } || !CanCreatePopup())
1890+
if (Preferences.Instance.EnableAutoFetch || !CanCreatePopup())
18911891
{
18921892
_lastFetchTime = DateTime.Now;
18931893
return;
@@ -1898,7 +1898,7 @@ private async Task AutoFetchOnUIThread()
18981898
return;
18991899

19001900
var now = DateTime.Now;
1901-
var desire = _lastFetchTime.AddMinutes(_settings.AutoFetchInterval);
1901+
var desire = _lastFetchTime.AddMinutes(Preferences.Instance.AutoFetchInterval);
19021902
if (desire > now)
19031903
return;
19041904

src/ViewModels/RepositoryConfigure.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,6 @@ public bool AskBeforeAutoUpdatingSubmodules
101101
set => _repo.Settings.AskBeforeAutoUpdatingSubmodules = value;
102102
}
103103

104-
public bool EnableAutoFetch
105-
{
106-
get => _repo.Settings.EnableAutoFetch;
107-
set => _repo.Settings.EnableAutoFetch = value;
108-
}
109-
110-
public int? AutoFetchInterval
111-
{
112-
get => _repo.Settings.AutoFetchInterval;
113-
set
114-
{
115-
if (value is null || value < 1)
116-
return;
117-
118-
var interval = (int)value;
119-
if (_repo.Settings.AutoFetchInterval != interval)
120-
_repo.Settings.AutoFetchInterval = interval;
121-
}
122-
}
123-
124104
public AvaloniaList<Models.CommitTemplate> CommitTemplates
125105
{
126106
get => _repo.Settings.CommitTemplates;

src/Views/Preferences.axaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.Git}"/>
310310
</TabItem.Header>
311311

312-
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
312+
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto,32" ColumnDefinitions="Auto,*">
313313
<TextBlock Grid.Row="0" Grid.Column="0"
314314
Text="{DynamicResource Text.Preferences.Git.Path}"
315315
HorizontalAlignment="Right"
@@ -405,6 +405,26 @@
405405
Content="{DynamicResource Text.Preferences.Git.UseLibsecret}"
406406
IsChecked="{Binding UseLibsecretInsteadOfGCM, Mode=TwoWay}"
407407
IsVisible="{OnPlatform False, Linux=True}"/>
408+
409+
<StackPanel Grid.Row="9" Grid.Column="1" Orientation="Horizontal">
410+
<CheckBox x:Name="AutoFetchCheckBox"
411+
Content="{DynamicResource Text.Configure.Git.AutoFetch}"
412+
IsChecked="{Binding EnableAutoFetch, Mode=TwoWay}"/>
413+
414+
<NumericUpDown Minimum="1" Maximum="60" Increment="1"
415+
Height="26" Width="110"
416+
Margin="8,0,0,0" Padding="4"
417+
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
418+
CornerRadius="3"
419+
ParsingNumberStyle="Integer"
420+
FormatString="0"
421+
Value="{Binding AutoFetchInterval, Mode=TwoWay, FallbackValue=10}"
422+
IsEnabled="{Binding #AutoFetchCheckBox.IsChecked}"/>
423+
424+
<TextBlock VerticalAlignment="Center"
425+
Margin="5,0,0,0"
426+
Text="{DynamicResource Text.Configure.Git.AutoFetchIntervalSuffix}" />
427+
</StackPanel>
408428
</Grid>
409429
</TabItem>
410430

src/Views/RepositoryConfigure.axaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.Git}"/>
4545
</TabItem.Header>
4646

47-
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
47+
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
4848
<TextBlock Grid.Row="0" Grid.Column="0"
4949
HorizontalAlignment="Right" VerticalAlignment="Center"
5050
Margin="0,0,8,0"
@@ -179,26 +179,6 @@
179179
<CheckBox Grid.Row="10" Grid.Column="1"
180180
Content="{DynamicResource Text.Configure.Git.AskBeforeAutoUpdatingSubmodules}"
181181
IsChecked="{Binding AskBeforeAutoUpdatingSubmodules, Mode=TwoWay}"/>
182-
183-
<StackPanel Grid.Row="11" Grid.Column="1" Orientation="Horizontal">
184-
<CheckBox x:Name="AutoFetchCheckBox"
185-
Content="{DynamicResource Text.Configure.Git.AutoFetch}"
186-
IsChecked="{Binding EnableAutoFetch, Mode=TwoWay}"/>
187-
188-
<NumericUpDown Minimum="1" Maximum="60" Increment="1"
189-
Height="26" Width="110"
190-
Margin="8,0,0,0" Padding="4"
191-
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
192-
CornerRadius="3"
193-
ParsingNumberStyle="Integer"
194-
FormatString="0"
195-
Value="{Binding AutoFetchInterval, Mode=TwoWay, FallbackValue=10}"
196-
IsEnabled="{Binding #AutoFetchCheckBox.IsChecked}"/>
197-
198-
<TextBlock VerticalAlignment="Center"
199-
Margin="5,0,0,0"
200-
Text="{DynamicResource Text.Configure.Git.AutoFetchIntervalSuffix}" />
201-
</StackPanel>
202182
</Grid>
203183
</TabItem>
204184

0 commit comments

Comments
 (0)