Skip to content

Commit 74b9631

Browse files
committed
Fixes
* Timer in the UI doesn't get stuck anymore * First line of text doesn't disappear anymore on client disconnect * More styling on Settings page (More to be done) * Added try/catch in IPC so we can handle forceful disconnects
1 parent 79db88d commit 74b9631

File tree

9 files changed

+62
-28
lines changed

9 files changed

+62
-28
lines changed

MultiRPC/Assets/Language/en-gb.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,6 @@
239239
"NA": "N/A",
240240
"Administrator": "Administrator",
241241
"DiscordClientCheck": "Discord client check. Was checking for {discordProcess} (found: {wasFound})",
242-
"AdminWarning": "Running MultiRPC with elevated permissions is NOT recommended and is only intended if you can't get any connection without it (Contact us on the discord server and we'll see if we can fix the connection without elevated permissions).\r\n\r\nNote that it's also NOT recommended to have discord open with elevated permissions, only press 'Ok' if this is the only way for a connection"
242+
"AdminWarning": "Running MultiRPC with elevated permissions is NOT recommended and is only intended if you can't get any connection without it (Contact us on the discord server and we'll see if we can fix the connection without elevated permissions).\r\n\r\nNote that it's also NOT recommended to have discord open with elevated permissions, only press 'Ok' if this is the only way for a connection",
243+
"ToAdd": "To Add"
243244
}

MultiRPC/IPC.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,18 @@ private async Task ProcessLinesAsync(Socket socket)
167167

168168
while (true)
169169
{
170-
ReadResult result = await reader.ReadAsync();
171-
ReadOnlySequence<byte> buffer = result.Buffer;
170+
ReadResult result;
171+
ReadOnlySequence<byte> buffer;
172+
try
173+
{
174+
result = await reader.ReadAsync();
175+
buffer = result.Buffer;
176+
}
177+
catch (Exception e)
178+
{
179+
_logger.Error(e);
180+
break;
181+
}
172182

173183
while (TryReadLine(ref buffer, out ReadOnlySequence<byte> line))
174184
{

MultiRPC/UI/App.axaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net.Http;
2+
using System.Runtime.InteropServices;
23
using Avalonia;
34
using Avalonia.Controls.ApplicationLifetimes;
45
using Avalonia.Markup.Xaml;
@@ -10,7 +11,10 @@
1011
using MultiRPC.UI.Pages.Rpc.Custom;
1112
using MultiRPC.UI.Pages.Settings;
1213
using Splat;
14+
using TinyUpdate.Binary;
15+
using TinyUpdate.Core.Extensions;
1316
using TinyUpdate.Core.Update;
17+
using TinyUpdate.Github;
1418

1519
namespace MultiRPC.UI
1620
{

MultiRPC/UI/Pages/Settings/AboutSettingsTab.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:settings="clr-namespace:MultiRPC.UI.Pages.Settings"
66
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
7+
Margin="10"
78
x:Class="MultiRPC.UI.Pages.Settings.AboutSettingsTab">
89
<UserControl.Styles>
910
<Style Selector="TextBlock.title">

MultiRPC/UI/Pages/Settings/AboutSettingsTab.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private async void BtnAdmin_OnClick(object? sender, RoutedEventArgs e)
100100

101101
try
102102
{
103-
var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase.Replace(".dll", ".exe")) //Net Core tell's us the location of the dll, not the exe so we point it back to the exe
103+
var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe")) //Net Core tell's us the location of the dll, not the exe so we point it back to the exe
104104
{
105105
UseShellExecute = true,
106106
Verb = "runas"
@@ -121,12 +121,12 @@ private async void BtnAdmin_OnClick(object? sender, RoutedEventArgs e)
121121

122122
private async void BtnChangelog_OnClick(object? sender, RoutedEventArgs e)
123123
{
124-
await MessageBox.Show("TO ADD");
124+
await MessageBox.Show(Language.GetText(LanguageText.ToAdd));
125125
}
126126

127127
private async void BtnCheckUpdate_OnClick(object? sender, RoutedEventArgs e)
128128
{
129-
await MessageBox.Show("TO ADD");
129+
await MessageBox.Show(Language.GetText(LanguageText.ToAdd));
130130
}
131131

132132
private void ImgGithub_OnPointerPressed(object? sender, PointerPressedEventArgs e)

MultiRPC/UI/Pages/Settings/SettingsPage.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:pages="clr-namespace:MultiRPC.UI.Pages"
66
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
7+
Background="{DynamicResource ThemeAccentBrush}"
78
x:Class="MultiRPC.UI.Pages.Settings.SettingsPage">
89
</pages:SidePage>

MultiRPC/UI/Pages/Settings/SettingsPage.axaml.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Reflection;
3+
using Avalonia;
4+
using Avalonia.Media;
35
using MultiRPC.Setting;
46
using MultiRPC.Setting.Settings.Attributes;
57
using MultiRPC.UI.Controls;
@@ -19,7 +21,10 @@ public partial class SettingsPage : SidePage
1921
public override void Initialize(bool loadXaml)
2022
{
2123
InitializeComponent(loadXaml);
24+
ContentPadding = new Thickness(0);
25+
2226
var tabPage = new TabsPage();
27+
tabPage.Background = (IBrush)Application.Current.Resources["ThemeAccentBrush"]!;
2328
tabPage.AddTabs(new AboutSettingsTab());
2429

2530
foreach (var setting in Locator.Current.GetServices<BaseSetting>())
@@ -68,7 +73,11 @@ public override void Initialize(bool loadXaml)
6873
continue;
6974
}
7075

71-
settingPage ??= new SettingsTab { TabName = new Language(setting.Name) };
76+
settingPage ??= new SettingsTab
77+
{
78+
TabName = new Language(setting.Name),
79+
Margin = new Thickness(10)
80+
};
7281
if (settingProperty.PropertyType.BaseType == typeof(Enum))
7382
{
7483
var enumDropdown = new EnumDropdown(settingProperty.PropertyType, name, setting, getMethod, setMethod);

MultiRPC/UI/Pages/Settings/SettingsTab.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ namespace MultiRPC.UI.Pages.Settings
66
{
77
public class SettingsTab : StackPanel, ITabPage
88
{
9+
public SettingsTab()
10+
{
11+
Spacing = 7;
12+
}
13+
914
public Language? TabName { get; init; }
1015
public bool IsDefaultPage { get; }
1116
public void Initialize(bool loadXaml) { }

MultiRPC/UI/Views/RpcView.axaml.cs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.ComponentModel;
44
using System.Net.Http;
55
using System.Threading.Tasks;
6+
using System.Timers;
67
using Avalonia;
78
using Avalonia.Controls;
89
using Avalonia.Data;
@@ -48,7 +49,14 @@ public RpcView()
4849
tblText1.DataContext = _tblText1;
4950
tblText2.DataContext = _tblText2;
5051
ViewType = ViewType.Default;
51-
_rpcClient.Disconnected += (sender, args) => _timerTime = null;
52+
_timer = new Timer(1000);
53+
_timer.Elapsed += TimerOnElapsed;
54+
_rpcClient.Disconnected += (sender, args) =>
55+
{
56+
_timer.Stop();
57+
_timerTime = null;
58+
tblTime.Text = string.Empty;
59+
};
5260
}
5361

5462
private static readonly Dictionary<Uri, IBrush> CachedImages = new Dictionary<Uri, IBrush>();
@@ -111,10 +119,19 @@ private async void PresenceOnPropertyChanged(object? sender, PropertyChangedEven
111119
}
112120

113121
private DateTime? _timerTime;
122+
private readonly Timer _timer;
114123
private void RpcClientOnPresenceUpdated(object? sender, PresenceMessage e) => this.RunUILogic(() =>
115124
{
116125
_timerTime = e.Presence.Timestamps?.Start;
117-
_ = RunTimer();
126+
if (_timerTime != null)
127+
{
128+
_timer.Start();
129+
}
130+
else
131+
{
132+
_timer.Stop();
133+
tblTime.Text = string.Empty;
134+
}
118135

119136
tblTitle.Text = e.Name;
120137
tblText1.Text = e.Presence.Details;
@@ -201,27 +218,13 @@ private async Task UpdateSmallImage(Uri? uri)
201218
}
202219
}
203220

204-
private bool _timerRunning;
205-
private async Task RunTimer()
221+
private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
206222
{
207-
if (_timerRunning)
208-
{
209-
return;
210-
}
211-
_timerRunning = true;
212-
213-
while (_timerTime.HasValue)
214-
{
215-
var ts = DateTime.UtcNow.Subtract(_timerTime.Value);
216-
217-
var text = ts.Hours > 0 ? ts.Hours.ToString("00") + ":" : string.Empty;
218-
text += $"{ts.Minutes:00}:{ts.Seconds:00}";
219-
tblTime.Text = text;
220-
await Task.Delay(1000);
221-
}
223+
var ts = DateTime.UtcNow.Subtract(_timerTime.Value);
222224

223-
_timerRunning = false;
224-
tblText1.Text = string.Empty;
225+
var text = ts.Hours > 0 ? ts.Hours.ToString("00") + ":" : string.Empty;
226+
text += $"{ts.Minutes:00}:{ts.Seconds:00}";
227+
this.RunUILogic(() => tblTime.Text = text);
225228
}
226229

227230
private async Task<bool> ProcessUri(Uri uri)

0 commit comments

Comments
 (0)