Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Azyyyyyy committed Nov 27, 2021
1 parent 79db88d commit 74b9631
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 28 deletions.
3 changes: 2 additions & 1 deletion MultiRPC/Assets/Language/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,6 @@
"NA": "N/A",
"Administrator": "Administrator",
"DiscordClientCheck": "Discord client check. Was checking for {discordProcess} (found: {wasFound})",
"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"
"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",
"ToAdd": "To Add"
}
14 changes: 12 additions & 2 deletions MultiRPC/IPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,18 @@ private async Task ProcessLinesAsync(Socket socket)

while (true)
{
ReadResult result = await reader.ReadAsync();
ReadOnlySequence<byte> buffer = result.Buffer;
ReadResult result;
ReadOnlySequence<byte> buffer;
try
{
result = await reader.ReadAsync();
buffer = result.Buffer;
}
catch (Exception e)
{
_logger.Error(e);
break;
}

while (TryReadLine(ref buffer, out ReadOnlySequence<byte> line))
{
Expand Down
4 changes: 4 additions & 0 deletions MultiRPC/UI/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Http;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
Expand All @@ -10,7 +11,10 @@
using MultiRPC.UI.Pages.Rpc.Custom;
using MultiRPC.UI.Pages.Settings;
using Splat;
using TinyUpdate.Binary;
using TinyUpdate.Core.Extensions;
using TinyUpdate.Core.Update;
using TinyUpdate.Github;

namespace MultiRPC.UI
{
Expand Down
1 change: 1 addition & 0 deletions MultiRPC/UI/Pages/Settings/AboutSettingsTab.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:settings="clr-namespace:MultiRPC.UI.Pages.Settings"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Margin="10"
x:Class="MultiRPC.UI.Pages.Settings.AboutSettingsTab">
<UserControl.Styles>
<Style Selector="TextBlock.title">
Expand Down
6 changes: 3 additions & 3 deletions MultiRPC/UI/Pages/Settings/AboutSettingsTab.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private async void BtnAdmin_OnClick(object? sender, RoutedEventArgs e)

try
{
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
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
{
UseShellExecute = true,
Verb = "runas"
Expand All @@ -121,12 +121,12 @@ private async void BtnAdmin_OnClick(object? sender, RoutedEventArgs e)

private async void BtnChangelog_OnClick(object? sender, RoutedEventArgs e)
{
await MessageBox.Show("TO ADD");
await MessageBox.Show(Language.GetText(LanguageText.ToAdd));
}

private async void BtnCheckUpdate_OnClick(object? sender, RoutedEventArgs e)
{
await MessageBox.Show("TO ADD");
await MessageBox.Show(Language.GetText(LanguageText.ToAdd));
}

private void ImgGithub_OnPointerPressed(object? sender, PointerPressedEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions MultiRPC/UI/Pages/Settings/SettingsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:MultiRPC.UI.Pages"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Background="{DynamicResource ThemeAccentBrush}"
x:Class="MultiRPC.UI.Pages.Settings.SettingsPage">
</pages:SidePage>
11 changes: 10 additions & 1 deletion MultiRPC/UI/Pages/Settings/SettingsPage.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Reflection;
using Avalonia;
using Avalonia.Media;
using MultiRPC.Setting;
using MultiRPC.Setting.Settings.Attributes;
using MultiRPC.UI.Controls;
Expand All @@ -19,7 +21,10 @@ public partial class SettingsPage : SidePage
public override void Initialize(bool loadXaml)
{
InitializeComponent(loadXaml);
ContentPadding = new Thickness(0);

var tabPage = new TabsPage();
tabPage.Background = (IBrush)Application.Current.Resources["ThemeAccentBrush"]!;
tabPage.AddTabs(new AboutSettingsTab());

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

settingPage ??= new SettingsTab { TabName = new Language(setting.Name) };
settingPage ??= new SettingsTab
{
TabName = new Language(setting.Name),
Margin = new Thickness(10)
};
if (settingProperty.PropertyType.BaseType == typeof(Enum))
{
var enumDropdown = new EnumDropdown(settingProperty.PropertyType, name, setting, getMethod, setMethod);
Expand Down
5 changes: 5 additions & 0 deletions MultiRPC/UI/Pages/Settings/SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace MultiRPC.UI.Pages.Settings
{
public class SettingsTab : StackPanel, ITabPage
{
public SettingsTab()
{
Spacing = 7;
}

public Language? TabName { get; init; }
public bool IsDefaultPage { get; }
public void Initialize(bool loadXaml) { }
Expand Down
45 changes: 24 additions & 21 deletions MultiRPC/UI/Views/RpcView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Net.Http;
using System.Threading.Tasks;
using System.Timers;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
Expand Down Expand Up @@ -48,7 +49,14 @@ public RpcView()
tblText1.DataContext = _tblText1;
tblText2.DataContext = _tblText2;
ViewType = ViewType.Default;
_rpcClient.Disconnected += (sender, args) => _timerTime = null;
_timer = new Timer(1000);
_timer.Elapsed += TimerOnElapsed;
_rpcClient.Disconnected += (sender, args) =>
{
_timer.Stop();
_timerTime = null;
tblTime.Text = string.Empty;
};
}

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

private DateTime? _timerTime;
private readonly Timer _timer;
private void RpcClientOnPresenceUpdated(object? sender, PresenceMessage e) => this.RunUILogic(() =>
{
_timerTime = e.Presence.Timestamps?.Start;
_ = RunTimer();
if (_timerTime != null)
{
_timer.Start();
}
else
{
_timer.Stop();
tblTime.Text = string.Empty;
}
tblTitle.Text = e.Name;
tblText1.Text = e.Presence.Details;
Expand Down Expand Up @@ -201,27 +218,13 @@ private async Task UpdateSmallImage(Uri? uri)
}
}

private bool _timerRunning;
private async Task RunTimer()
private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
{
if (_timerRunning)
{
return;
}
_timerRunning = true;

while (_timerTime.HasValue)
{
var ts = DateTime.UtcNow.Subtract(_timerTime.Value);

var text = ts.Hours > 0 ? ts.Hours.ToString("00") + ":" : string.Empty;
text += $"{ts.Minutes:00}:{ts.Seconds:00}";
tblTime.Text = text;
await Task.Delay(1000);
}
var ts = DateTime.UtcNow.Subtract(_timerTime.Value);

_timerRunning = false;
tblText1.Text = string.Empty;
var text = ts.Hours > 0 ? ts.Hours.ToString("00") + ":" : string.Empty;
text += $"{ts.Minutes:00}:{ts.Seconds:00}";
this.RunUILogic(() => tblTime.Text = text);
}

private async Task<bool> ProcessUri(Uri uri)
Expand Down

0 comments on commit 74b9631

Please sign in to comment.