Skip to content

Commit c2d2793

Browse files
committed
feat: show reconnect counting down and a manually reconnect button on data source group title. #395
1 parent 7590224 commit c2d2793

28 files changed

+352
-93
lines changed

Ui/Controls/NoteDisplay/NoteDisplayAndEditor.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private static void OnServerChanged(DependencyObject d, DependencyPropertyChange
3030
if (e.NewValue is ProtocolBase server1)
3131
{
3232
server1.PropertyChanged += control.ServerOnPropertyChanged;
33-
control.EditEnable = control.EditEnable && server1.GetDataSource()?.IsWritable == true;
33+
control.EditEnable = control.EditEnable && server1.DataSource?.IsWritable == true;
3434
}
3535
}
3636
}

Ui/Controls/NoteDisplay/NoteIcon.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public NoteIcon(ProtocolBase server)
5959
Server = Server,
6060
Width = 400,
6161
Height = 300,
62-
EditEnable = Server.GetDataSource()?.IsWritable == true,
62+
EditEnable = Server.DataSource?.IsWritable == true,
6363
CloseEnable = false,
6464
};
6565
});

Ui/Controls/ServerCardItem.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ServerCardItem()
4141

4242
private void BtnSettingMenu_OnClick(object sender, RoutedEventArgs e)
4343
{
44-
ProtocolBaseViewModel.Actions = ProtocolBaseViewModel.Server.GetActions();
44+
ProtocolBaseViewModel.Actions = ProtocolBaseViewModel.GetActions();
4545
PopupCardSettingMenu.IsOpen = true;
4646
}
4747

Ui/Controls/ServerListItem.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public ServerListItem()
5353

5454
private void BtnSettingMenu_OnClick(object sender, RoutedEventArgs e)
5555
{
56-
ProtocolBaseViewModel.Actions = ProtocolBaseViewModel.Server.GetActions();
56+
ProtocolBaseViewModel.Actions = ProtocolBaseViewModel.GetActions();
5757
PopupCardSettingMenu.IsOpen = true;
5858
}
5959

Ui/Model/GlobalData.cs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
using System.Collections.ObjectModel;
44
using System.Diagnostics;
55
using System.Linq;
6+
using System.Text;
67
using System.Timers;
7-
using System.Windows.Interop;
8-
using System.Windows.Media;
98
using _1RM.Model.Protocol.Base;
109
using _1RM.Service;
1110
using _1RM.Service.DataSource;
@@ -202,7 +201,7 @@ public Result UpdateServer(ProtocolBase protocolServer)
202201
try
203202
{
204203
Debug.Assert(protocolServer.IsTmpSession() == false);
205-
var source = protocolServer.GetDataSource();
204+
var source = protocolServer.DataSource;
206205
if (source == null)
207206
{
208207
return Result.Fail(info, protocolServer.DataSource, $"`{protocolServer.DataSource}` is not initialized yet");
@@ -249,7 +248,7 @@ public Result UpdateServer(IEnumerable<ProtocolBase> protocolServers)
249248
var failMsgs = new List<string>();
250249
foreach (var groupedServer in groupedServers)
251250
{
252-
var source = groupedServer.First().GetDataSource();
251+
var source = groupedServer.First().DataSource;
253252
if (source?.IsWritable == true)
254253
{
255254
needReload |= source.NeedRead();
@@ -315,11 +314,12 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
315314
var failMsgs = new List<string>();
316315
foreach (var groupedServer in groupedServers)
317316
{
318-
var source = groupedServer.First().GetDataSource();
317+
var source = groupedServer.First().DataSource;
319318
if (source?.IsWritable == true)
320319
{
321320
needReload |= source.NeedRead();
322321
var tmp = source.Database_DeleteServer(groupedServer.Select(x => x.Id));
322+
SimpleLogHelper.Debug($"DeleteServer: {string.Join('、', groupedServer.Select(x => x.Id))}, needReload = {needReload}, tmp.IsSuccess = {tmp.IsSuccess}");
323323
if (tmp.IsSuccess)
324324
{
325325
isAnySuccess = true;
@@ -331,15 +331,19 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
331331
var old = GetItemById(source.DataSourceName, protocolServer.Id);
332332
if (old != null)
333333
{
334+
SimpleLogHelper.Debug($"Remote server {old.DisplayName} of `{old.DataSourceName}` removed from GlobalData");
334335
VmItemList.Remove(old);
336+
IoC.Get<ServerListPageViewModel>().DeleteServer(old); // invoke main list ui change
335337
Execute.OnUIThread(() =>
336338
{
337-
if (IoC.Get<ServerListPageViewModel>().VmServerList.Contains(old))
338-
IoC.Get<ServerListPageViewModel>().VmServerList.Remove(old); // invoke main list ui change
339339
if (IoC.Get<ServerSelectionsViewModel>().VmServerList.Contains(old))
340340
IoC.Get<ServerSelectionsViewModel>().VmServerList.Remove(old); // invoke launcher ui change
341341
});
342342
}
343+
else
344+
{
345+
SimpleLogHelper.Warning($"Remote server {protocolServer.DisplayName} of `{source.DataSourceName}` removed from GlobalData but not found in VmItemList");
346+
}
343347
}
344348
}
345349
}
@@ -355,7 +359,7 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
355359
{
356360
if (needReload)
357361
{
358-
ReloadServerList();
362+
ReloadServerList(needReload);
359363
}
360364
else
361365
{
@@ -406,6 +410,39 @@ public void StartTick()
406410
}
407411
}
408412

413+
/// <summary>
414+
/// return time string like 1d 2h 3m 4s
415+
/// </summary>
416+
/// <param name="seconds"></param>
417+
/// <returns></returns>
418+
private static string GetTime(int seconds)
419+
{
420+
var sb = new StringBuilder();
421+
if (seconds > 86400)
422+
{
423+
sb.Append($"{seconds / 86400}d ");
424+
seconds %= 86400;
425+
}
426+
427+
if (seconds > 3600)
428+
{
429+
sb.Append($"{seconds / 3600}h ");
430+
seconds %= 3600;
431+
}
432+
433+
if (seconds > 60)
434+
{
435+
sb.Append($"{seconds / 60}m ");
436+
seconds %= 60;
437+
}
438+
439+
if (seconds > 0)
440+
{
441+
sb.Append($"{seconds}s ");
442+
}
443+
return sb.ToString();
444+
}
445+
409446
public DateTime CheckUpdateTime;
410447
private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
411448
{
@@ -427,9 +464,10 @@ private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
427464
|| listPageViewModel.VmServerList.Any(x => x.IsSelected)
428465
|| launcherWindowViewModel?.View?.IsVisible == true)
429466
{
467+
var pause = IoC.Get<LanguageService>().Translate("Pause");
430468
foreach (var s in ds)
431469
{
432-
s.ReconnectInfo = "TXT: pause";
470+
s.ReconnectInfo = pause;
433471
}
434472
return;
435473
}
@@ -455,21 +493,27 @@ private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
455493

456494
var minEtc = Math.Min(checkUpdateEtc, minReconnectEtc);
457495

496+
497+
var msgUpdating = IoC.Get<LanguageService>().Translate("Updating");
498+
var msgNextUpdate = IoC.Get<LanguageService>().Translate("Next update check");
499+
var msgNextReconnect = IoC.Get<LanguageService>().Translate("Next auto reconnect");
500+
var msgReconnecting = IoC.Get<LanguageService>().Translate("Reconnecting");
501+
458502
var msg = minEtc > 0
459-
? $"TXT: check update in {minEtc}s"
460-
: "TXT: checking";
503+
? $"{msgNextUpdate} {GetTime(minEtc)}"
504+
: msgUpdating;
461505

462506
foreach (var s in ds)
463507
{
464508
if (s.Status != EnumDatabaseStatus.OK)
465509
{
466510
if ((s.ReconnectTime - DateTime.Now).Seconds > 0)
467511
{
468-
s.ReconnectInfo = $"TXT: reconnect in {(s.ReconnectTime - DateTime.Now).Seconds}s";
512+
s.ReconnectInfo = $"{msgNextReconnect} {GetTime((s.ReconnectTime - DateTime.Now).Seconds)}";
469513
}
470514
else
471515
{
472-
s.ReconnectInfo = $"TXT: reconnecting";
516+
s.ReconnectInfo = msgReconnecting;
473517
}
474518
}
475519
else

Ui/Model/GlobalEventHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Interop;
55
using _1RM.Model.Protocol;
66
using _1RM.Model.Protocol.Base;
7+
using _1RM.Service.DataSource.Model;
78
using _1RM.View;
89

910
namespace _1RM.Model
@@ -22,8 +23,7 @@ public static class GlobalEventHelper
2223
/// Go to server edit by server id, if id == 0 goto add page
2324
/// </summary>
2425
/// <param name="presetTagNames">preset tag names</param>
25-
/// <param name="showAnimation">show in animation?</param>
26-
public delegate void OnGoToServerAddPageDelegate(List<string>? presetTagNames = null, bool showAnimation = true);
26+
public delegate void OnGoToServerAddPageDelegate(List<string>? presetTagNames = null, DataSourceBase? assignDataSource = null);
2727
public static OnGoToServerAddPageDelegate? OnGoToServerAddPage { get; set; } = null;
2828

2929
public delegate void OnRequestGoToServerDuplicatePageDelegate(ProtocolBase server, bool showAnimation = true);

Ui/Model/Protocol/Dummy.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using _1RM.Model.Protocol.Base;
4+
using Shawn.Utils;
5+
6+
namespace _1RM.Model.Protocol
7+
{
8+
public class Dummy : ProtocolBase
9+
{
10+
public static string ProtocolName = "";
11+
public Dummy() : base(ProtocolName, "", "")
12+
{
13+
}
14+
15+
public override bool IsOnlyOneInstance()
16+
{
17+
return true;
18+
}
19+
20+
public override ProtocolBase? CreateFromJsonString(string jsonString)
21+
{
22+
return null;
23+
}
24+
25+
protected override string GetSubTitle()
26+
{
27+
return "";
28+
}
29+
30+
public override double GetListOrder()
31+
{
32+
return -1;
33+
}
34+
}
35+
}

Ui/Model/ProtocolAction.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using _1RM.Model.ProtocolRunner.Default;
88
using _1RM.Service;
99
using _1RM.Service.DataSource;
10+
using _1RM.Service.DataSource.DAO;
1011
using _1RM.Utils;
1112
using _1RM.View;
1213
using _1RM.View.Launcher;
@@ -35,9 +36,10 @@ public ProtocolAction(string actionName, Action action)
3536

3637
public static class ProtocolActionHelper
3738
{
38-
public static List<ProtocolAction> GetActions(this ProtocolBase server)
39+
public static List<ProtocolAction> GetActions(this ProtocolBaseViewModel vm)
3940
{
40-
bool writable = server.GetDataSource()?.IsWritable != false;
41+
var server = vm.Server;
42+
bool writable = server.DataSource?.IsWritable != false;
4143
#region Build Actions
4244
var actions = new List<ProtocolAction>();
4345
{
@@ -77,7 +79,7 @@ public static List<ProtocolAction> GetActions(this ProtocolBase server)
7779
}
7880
}
7981

80-
if (writable)
82+
if (writable && (vm.DataSource == null || vm.DataSource.Status == EnumDatabaseStatus.OK))
8183
{
8284
actions.Add(new ProtocolAction(IoC.Get<ILanguageService>().Translate("Edit"), () =>
8385
{

Ui/Resources/Languages/cs-cz.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,9 @@
275275
<s:String x:Key="We can not select from database:">Nemůžeme vybrat z databáze:</s:String>
276276
<s:String x:Key="We can not delete from database:">Nemůžeme odstranit z databáze:</s:String>
277277
<s:String x:Key="because:">protože:</s:String>
278+
<s:String x:Key="Pause">Pauza</s:String>
279+
<s:String x:Key="Updating">Aktualizace</s:String>
280+
<s:String x:Key="Reconnecting">Opětovné připojení</s:String>
281+
<s:String x:Key="Next update check">Další kontrola aktualizace</s:String>
282+
<s:String x:Key="Next auto reconnect">Další automatické opětovné připojení</s:String>
278283
</ResourceDictionary>

0 commit comments

Comments
 (0)