Skip to content

Commit 7c0a144

Browse files
committed
Refactor database busy indicator
1 parent 1fe33a3 commit 7c0a144

File tree

7 files changed

+56
-56
lines changed

7 files changed

+56
-56
lines changed

IPConfig/App.xaml.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.ComponentModel;
32
using System.Diagnostics;
43
using System.IO;
54
using System.Reflection;
6-
using System.Runtime.CompilerServices;
75
using System.Text;
86
using System.Text.Encodings.Web;
97
using System.Text.Json;
@@ -43,28 +41,13 @@ public partial class App : Application
4341
Converters = { new JsonStringEnumConverter() }
4442
};
4543

46-
private static bool _isDbSyncing;
47-
4844
public static bool CanForceClose { get; set; }
4945

5046
/// <summary>
5147
/// Gets the current <see cref="App"/> instance in use.
5248
/// </summary>
5349
public static new App Current => (App)Application.Current;
5450

55-
public static bool IsDbSyncing
56-
{
57-
get => _isDbSyncing;
58-
set
59-
{
60-
if (_isDbSyncing != value)
61-
{
62-
_isDbSyncing = value;
63-
OnStaticPropertyChanged();
64-
}
65-
}
66-
}
67-
6851
public static bool IsInDesignMode => Application.Current is not App;
6952

7053
public static Version? Version => Assembly.GetEntryAssembly()?.GetName().Version;
@@ -232,15 +215,4 @@ private void ThemeWatcher_WindowsThemeChanged(object? sender, ThemeWatcher.Theme
232215
ThemeManager.UpdateSkin(null);
233216
}
234217
}
235-
236-
#region Static Properties Change Notification
237-
238-
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged = delegate { };
239-
240-
private static void OnStaticPropertyChanged([CallerMemberName] string? staticPropertyName = null)
241-
{
242-
StaticPropertyChanged(null, new PropertyChangedEventArgs(staticPropertyName));
243-
}
244-
245-
#endregion Static Properties Change Notification
246218
}

IPConfig/Helpers/LiteDbHelper.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Runtime.CompilerServices;
35

46
using IPConfig.Models;
57

@@ -9,6 +11,21 @@ namespace IPConfig.Helpers;
911

1012
public static class LiteDbHelper
1113
{
14+
private static bool _isDbBusy;
15+
16+
public static bool IsDbBusy
17+
{
18+
get => _isDbBusy;
19+
private set
20+
{
21+
if (_isDbBusy != value)
22+
{
23+
_isDbBusy = value;
24+
OnStaticPropertyChanged();
25+
}
26+
}
27+
}
28+
1229
public static void Handle(Action<ILiteCollection<EditableIPConfigModel>> action)
1330
{
1431
Handle(col => {
@@ -20,14 +37,14 @@ public static void Handle(Action<ILiteCollection<EditableIPConfigModel>> action)
2037

2138
public static T Handle<T>(Func<ILiteCollection<EditableIPConfigModel>, T> func)
2239
{
23-
App.IsDbSyncing = true;
40+
IsDbBusy = true;
2441

2542
using var db = new LiteDatabase("Filename=ipconfig.db; Connection=Shared;");
2643
var col = db.GetCollection<EditableIPConfigModel>("ipconfigs");
2744

2845
var result = func(col);
2946

30-
App.IsDbSyncing = false;
47+
IsDbBusy = false;
3148

3249
return result;
3350
}
@@ -58,4 +75,15 @@ public static T Query<T>(Func<IEnumerable<EditableIPConfigModel>, T> func)
5875
return result;
5976
});
6077
}
78+
79+
#region Static Properties Change Notification
80+
81+
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged = delegate { };
82+
83+
private static void OnStaticPropertyChanged([CallerMemberName] string? staticPropertyName = null)
84+
{
85+
StaticPropertyChanged(null, new PropertyChangedEventArgs(staticPropertyName));
86+
}
87+
88+
#endregion Static Properties Change Notification
6189
}

IPConfig/Languages/Lang.Designer.cs

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPConfig/Languages/Lang.en.resx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@
212212
<data name="CheckUpdateFailed" xml:space="preserve">
213213
<value>Failed to check for updates</value>
214214
</data>
215-
<data name="ClosingInfoDbSyncing" xml:space="preserve">
216-
<value>Syncing the database, please try again later.</value>
215+
<data name="ClosingInfoDbBusy" xml:space="preserve">
216+
<value>The database is busy, please try again later.</value>
217217
</data>
218218
<data name="ClosingSaveAsk_Format" xml:space="preserve">
219219
<value>Do you want to save the changes to {0}?</value>
@@ -254,8 +254,8 @@
254254
<data name="DataValidation_ToolTip" xml:space="preserve">
255255
<value>Check that the configuration meets the basic requirements</value>
256256
</data>
257-
<data name="DbSyncing_ToolTip" xml:space="preserve">
258-
<value>Database syncing...</value>
257+
<data name="DbBusy_ToolTip" xml:space="preserve">
258+
<value>Database busy...</value>
259259
</data>
260260
<data name="Default" xml:space="preserve">
261261
<value>Default</value>

IPConfig/Languages/Lang.resx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@
221221
<value>检查更新失败</value>
222222
<comment>VersionInfoViewModel</comment>
223223
</data>
224-
<data name="ClosingInfoDbSyncing" xml:space="preserve">
225-
<value>正在同步数据库,请稍后再试。</value>
224+
<data name="ClosingInfoDbBusy" xml:space="preserve">
225+
<value>数据库繁忙,请稍后再试。</value>
226226
<comment>MainViewModel</comment>
227227
</data>
228228
<data name="ClosingSaveAsk_Format" xml:space="preserve">
@@ -277,9 +277,9 @@
277277
<value>检查配置是否符合基本要求</value>
278278
<comment>IPConfigDetailView</comment>
279279
</data>
280-
<data name="DbSyncing_ToolTip" xml:space="preserve">
281-
<value>正在同步到数据库...</value>
282-
<comment>MainWindow</comment>
280+
<data name="DbBusy_ToolTip" xml:space="preserve">
281+
<value>数据库繁忙...</value>
282+
<comment>StatusBarView</comment>
283283
</data>
284284
<data name="Default" xml:space="preserve">
285285
<value>默认</value>

IPConfig/ViewModels/MainViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ private static void ChangeLanguage(string name)
6868
[RelayCommand]
6969
private async Task ClosingAsync(CancelEventArgs e)
7070
{
71-
if (App.IsDbSyncing)
71+
if (LiteDbHelper.IsDbBusy)
7272
{
7373
HcMessageBox.Show(
74-
Lang.ClosingInfoDbSyncing,
74+
Lang.ClosingInfoDbBusy,
7575
App.AppName,
7676
MessageBoxButton.OK,
7777
MessageBoxImage.Information,

IPConfig/Views/StatusBarView.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7-
xmlns:app="clr-namespace:IPConfig"
7+
xmlns:h="clr-namespace:IPConfig.Helpers"
88
xmlns:lang="clr-namespace:IPConfig.Languages"
99
xmlns:vm="clr-namespace:IPConfig.ViewModels"
1010
xmlns:v="clr-namespace:IPConfig.Views"
@@ -42,9 +42,9 @@
4242
Margin="0,0,4,0"
4343
d:Visibility="Visible"
4444
IsIndeterminate="True"
45-
ToolTip="{lang:Lang {x:Static lang:LangKey.DbSyncing_ToolTip}}"
45+
ToolTip="{lang:Lang {x:Static lang:LangKey.DbBusy_ToolTip}}"
4646
ToolTipService.ShowOnDisabled="True"
47-
Visibility="{Binding Path=(app:App.IsDbSyncing), Mode=OneWay, Converter={StaticResource Boolean2VisibilityConverter}}" />
47+
Visibility="{Binding Path=(h:LiteDbHelper.IsDbBusy), Mode=OneWay, Converter={StaticResource Boolean2VisibilityConverter}}" />
4848

4949
<v:IPConfigListSelectionCounterView />
5050
</hc:SimpleStackPanel>

0 commit comments

Comments
 (0)