Skip to content

Commit 19b13fc

Browse files
committed
Added Credit page
Also made MultiRPCImages be remade on Language change and fixed Locator
1 parent 3ebe6cc commit 19b13fc

File tree

12 files changed

+279
-17
lines changed

12 files changed

+279
-17
lines changed

MultiRPC/Assets/Icons/Heart.svg

Lines changed: 1 addition & 0 deletions
Loading

MultiRPC/Assets/Icons/Shield.svg

Lines changed: 1 addition & 0 deletions
Loading

MultiRPC/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static Constants()
3838
/// <summary>
3939
/// Url to the MultiRPC's info + download page
4040
/// </summary>
41-
public const string WebsiteUrl = "https://fluxpoint.dev/multirpc";
41+
public const string WebsiteUrl = "https://multirpc.fluxpoint.dev/";
4242

4343
/// <summary>
4444
/// The app developer

MultiRPC/CreditsList.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace MultiRPC
2+
{
3+
public class CreditsList
4+
{
5+
public CreditsList(string[] admins, string[] patreon, string[] paypal)
6+
{
7+
Admins = admins;
8+
Patreon = patreon;
9+
Paypal = paypal;
10+
}
11+
12+
public string[] Admins { get; }
13+
public string[] Patreon { get; }
14+
public string[] Paypal { get; }
15+
}
16+
}

MultiRPC/Rpc/IDChecker.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
using System.Text.Json;
44
using System.Text.Json.Serialization;
55
using System.Threading.Tasks;
6+
using MultiRPC.UI;
67
using TinyUpdate.Http.Extensions;
78

89
namespace MultiRPC.Rpc
910
{
1011
public static class IDChecker
1112
{
12-
private static readonly HttpClient Client = new HttpClient();
13-
1413
/// <summary>
1514
/// This checks the ID that is given to us
1615
/// </summary>
@@ -20,7 +19,7 @@ public static class IDChecker
2019
public static async Task<(bool Successful, string? ResultMessage)> Check(long id)
2120
{
2221
var responseMessage =
23-
await Client.GetResponseMessage(
22+
await App.HttpClient.GetResponseMessage(
2423
new HttpRequestMessage(HttpMethod.Get,
2524
$"https://discordapp.com/api/v6/oauth2/applications/{id}/rpc")); ;
2625

MultiRPC/UI/App.axaml.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
using System.Runtime.InteropServices;
1+
using System.Net.Http;
22
using Avalonia;
3-
using Avalonia.Controls;
43
using Avalonia.Controls.ApplicationLifetimes;
54
using Avalonia.Markup.Xaml;
65
using MultiRPC.Rpc;
7-
using MultiRPC.Rpc.Page;
86
using MultiRPC.Setting;
97
using MultiRPC.Setting.Settings;
108
using MultiRPC.UI.Pages;
119
using MultiRPC.UI.Pages.Rpc;
1210
using MultiRPC.UI.Pages.Rpc.Custom;
11+
using MultiRPC.UI.Pages.Settings;
1312
using Splat;
13+
using TinyUpdate.Core.Update;
1414
using TinyUpdate.Binary;
1515
using TinyUpdate.Core.Extensions;
16-
using TinyUpdate.Core.Update;
1716
using TinyUpdate.Github;
18-
using SettingsPage = MultiRPC.UI.Pages.Settings.SettingsPage;
1917

2018
namespace MultiRPC.UI
2119
{
2220
public class App : Application
2321
{
22+
public static readonly HttpClient HttpClient = new HttpClient();
23+
2424
//TODO: Put this somewhere else, for now this works
2525
private UpdateClient? _updater;
2626

@@ -32,10 +32,9 @@ public override void Initialize()
3232
AvaloniaXamlLoader.Load(this);
3333

3434
//Add default settings here
35-
Locator.CurrentMutable.Register<Setting.Setting>(() => SettingManager<GeneralSettings>.Setting);
36-
Locator.CurrentMutable.Register<Setting.Setting>(() => SettingManager<DisableSettings>.Setting);
35+
Locator.CurrentMutable.RegisterLazySingleton<Setting.Setting>(() => SettingManager<GeneralSettings>.Setting);
36+
Locator.CurrentMutable.RegisterLazySingleton<Setting.Setting>(() => SettingManager<DisableSettings>.Setting);
3737

38-
//TODO: Replace with splat
3938
//Any new pages get added here
4039
PageManager.AddPage(new MultiRpcPage());
4140
PageManager.AddPage(new CustomPage());
@@ -46,7 +45,7 @@ public override void Initialize()
4645
PageManager.AddPage(new MissingPage());
4746

4847
//Anything else here
49-
Locator.CurrentMutable.Register(() => new RpcClient());
48+
Locator.CurrentMutable.RegisterLazySingleton(() => new RpcClient());
5049

5150
#if !DEBUG
5251
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))

MultiRPC/UI/MainWindow.axaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public MainWindow() : this(new MainPage())
4444
ToolTipText = Language.GetText("HideMultiRPC"),
4545
Command = new TrayCommand()
4646
};
47-
TrayIcon.SetIcons(this, new TrayIcons{ trayIcon });
47+
TrayIcon.SetIcons(this, new TrayIcons { trayIcon });
48+
this.Closing += (sender, args) =>
49+
{
50+
TrayIcon.GetIcons(this)[0].IsVisible = false;
51+
};
4852

4953
Language.LanguageChanged += (sender, args) => ChangeTrayIconText(trayIcon);
5054
this.GetObservable(WindowStateProperty).Subscribe(x =>

MultiRPC/UI/Pages/CreditsPage.axaml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,79 @@
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:pages="clr-namespace:MultiRPC.UI.Pages"
6+
xmlns:controls="clr-namespace:MultiRPC.UI.Controls"
67
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
78
x:Class="MultiRPC.UI.Pages.CreditsPage">
8-
Come back soon when Credits is readded!
9+
<UserControl.Styles>
10+
<Style Selector="Image">
11+
<Setter Property="Width" Value="20" />
12+
</Style>
13+
<Style Selector="ScrollViewer">
14+
<Setter Property="VerticalScrollBarVisibility" Value="Hidden" />
15+
</Style>
16+
<Style Selector="TextBlock">
17+
<Setter Property="VerticalAlignment" Value="Top" />
18+
<Setter Property="Margin" Value="10" />
19+
<Setter Property="TextWrapping" Value="Wrap" />
20+
</Style>
21+
<Style Selector="TextBlock.title">
22+
<Setter Property="FontSize" Value="12" />
23+
<Setter Property="VerticalAlignment" Value="Top" />
24+
<Setter Property="Margin" Value="10,0,0,0" />
25+
<Setter Property="FontWeight" Value="SemiBold" />
26+
</Style>
27+
</UserControl.Styles>
28+
<Grid RowDefinitions="*,Auto" ColumnDefinitions="*,10,*,10,*,10,*">
29+
30+
<Grid RowDefinitions="Auto,5,*">
31+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
32+
<Image Name="imgCommunityAdmins" Source="{SvgImage /Assets/Icons/Shield.svg}" />
33+
<TextBlock Name="tblCommunityAdminsTitle" Classes="title" Text="{Binding TextObservable^}" />
34+
</StackPanel>
35+
<Border Grid.Row="2" CornerRadius="15" Background="{DynamicResource ThemeAccentBrush}" />
36+
<ScrollViewer Grid.Row="2">
37+
<TextBlock Name="tblCommunityAdmins" />
38+
</ScrollViewer>
39+
</Grid>
40+
41+
<Grid RowDefinitions="Auto,5,*" Grid.Column="2">
42+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
43+
<Image Name="imgPatreonDonators" Source="{SvgImage /Assets/Icons/Heart.svg}" />
44+
<TextBlock Name="tblPatreonDonatorsTitle" Classes="title" Text="{Binding TextObservable^}" />
45+
</StackPanel>
46+
<Border Grid.Row="2" CornerRadius="15" Background="{DynamicResource ThemeAccentBrush}" />
47+
<ScrollViewer Grid.Row="2">
48+
<TextBlock Name="tblPatreonDonators" />
49+
</ScrollViewer>
50+
</Grid>
51+
52+
<Grid RowDefinitions="Auto,5,*" Grid.Column="4">
53+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
54+
<Image Name="imgPaypalDonators" Source="{SvgImage /Assets/Icons/Heart.svg}" />
55+
<TextBlock Name="tblPaypalDonatorsTitle" Classes="title" Text="{Binding TextObservable^}" />
56+
</StackPanel>
57+
<Border Grid.Row="2" CornerRadius="15" Background="{DynamicResource ThemeAccentBrush}" />
58+
<ScrollViewer Grid.Row="2">
59+
<TextBlock Name="tblPaypalDonators" />
60+
</ScrollViewer>
61+
</Grid>
62+
63+
<Grid RowDefinitions="Auto,5,*" Grid.Column="6">
64+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
65+
<Image Name="imgIconProviders" Source="{SvgImage /Assets/Icons/Heart.svg}" />
66+
<TextBlock Name="tblIconProvidersTitle" Classes="title" Text="{Binding TextObservable^}" />
67+
</StackPanel>
68+
<Border Grid.Row="2" CornerRadius="15" Background="{DynamicResource ThemeAccentBrush}" />
69+
<ScrollViewer Grid.Row="2">
70+
<StackPanel Margin="10">
71+
<controls:Hyperlink Margin="0" Uri="https://www.iconfinder.com/" Text="Iconfinder"/>
72+
<controls:Hyperlink Margin="0" Uri="https://icons8.com/" Text="Icons8" />
73+
<controls:Hyperlink Margin="0" Uri="https://www.flaticon.com/" Text="Flaticon" />
74+
<controls:Hyperlink Margin="0" Uri="https://www.onlinewebfonts.com/icon/" Text="OnlineWebFonts" />
75+
</StackPanel>
76+
</ScrollViewer>
77+
</Grid>
78+
79+
<TextBlock Name="tblLastUpdated" Grid.Row="1" Grid.ColumnSpan="7" Margin="0,5" />
80+
</Grid>
981
</pages:SidePage>
Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,129 @@
1-
using Avalonia;
1+
using System;
2+
using System.IO;
3+
using System.Net.Http;
4+
using System.Net.NetworkInformation;
5+
using System.Text.Json;
6+
using System.Threading.Tasks;
7+
using Avalonia;
28
using Avalonia.Controls;
39
using Avalonia.Markup.Xaml;
10+
using MultiRPC.Extensions;
11+
using MultiRPC.Utils;
12+
using TinyUpdate.Core.Logging;
13+
using TinyUpdate.Http.Extensions;
414

515
namespace MultiRPC.UI.Pages
616
{
717
public partial class CreditsPage : SidePage
818
{
919
public override string IconLocation => "Icons/Credits";
1020
public override string LocalizableName => "Credits";
11-
public override void Initialize(bool loadXaml) => InitializeComponent(loadXaml);
21+
public override void Initialize(bool loadXaml)
22+
{
23+
InitializeComponent(loadXaml);
24+
25+
tblCommunityAdminsTitle.DataContext = new Language("CommunityAdmins");
26+
tblPatreonDonatorsTitle.DataContext = new Language("PatreonDonators");
27+
tblPaypalDonatorsTitle.DataContext = new Language("PaypalDonators");
28+
tblIconProvidersTitle.DataContext = new Language("IconProviders");
29+
NetworkChange.NetworkAddressChanged += NetworkChangeOnNetworkAddressChanged;
30+
UpdateCredits();
31+
_ = DownloadAndShow();
32+
}
33+
34+
private async void NetworkChangeOnNetworkAddressChanged(object? sender, EventArgs e)
35+
{
36+
if (NetworkUtil.NetworkIsAvailable())
37+
{
38+
await DownloadAndShow();
39+
}
40+
}
41+
42+
private static readonly string CreditsFileLocation = Path.Combine(Constants.SettingsFolder, "Credits.json");
43+
private CreditsList? _creditsList;
44+
private bool _downloadedCredit;
45+
46+
private async Task DownloadAndShow()
47+
{
48+
await DownloadCredits();
49+
UpdateCredits();
50+
}
51+
52+
private void UpdateCredits()
53+
{
54+
var creditsFileInfo = new FileInfo(CreditsFileLocation);
55+
if (!creditsFileInfo.Exists)
56+
{
57+
return;
58+
}
59+
60+
using var reader = creditsFileInfo.OpenRead();
61+
_creditsList = JsonSerializer.Deserialize<CreditsList>(reader);
62+
if (_creditsList != null)
63+
{
64+
tblCommunityAdmins.Text = string.Join("\r\n\r\n", _creditsList.Admins);
65+
tblPatreonDonators.Text = string.Join("\r\n\r\n", _creditsList.Patreon);
66+
tblPaypalDonators.Text = string.Join("\r\n\r\n", _creditsList.Paypal);
67+
}
68+
69+
if (!NetworkUtil.NetworkIsAvailable() && !_downloadedCredit)
70+
{
71+
tblLastUpdated.Text = $"{Language.GetText("WaitingForInternetUpdate")}...";
72+
return;
73+
}
74+
75+
//TODO: Make this be updated on Lang change
76+
tblLastUpdated.Text = creditsFileInfo.LastWriteTime.Date == DateTime.Now.Date
77+
? $"{Language.GetText("LastUpdatedAt")}: {creditsFileInfo.LastWriteTime.ToShortTimeString()}"
78+
: $"{Language.GetText("LastUpdatedOn")}: {creditsFileInfo.LastWriteTime.ToLongDateString()}";
79+
}
80+
81+
private const string Url = Constants.WebsiteUrl + "Credits.json";
82+
private readonly ILogging _logger = LoggingCreator.CreateLogger(nameof(CreditsPage));
83+
private async Task DownloadCredits()
84+
{
85+
if (_downloadedCredit)
86+
{
87+
return;
88+
}
89+
90+
for (int i = 0; i < Constants.RetryCount; i++)
91+
{
92+
this.RunUILogic(() =>
93+
tblLastUpdated.Text = Language.GetText("CheckForUpdates").Replace("\r\n", " "));
94+
95+
var req = await App.HttpClient.GetResponseMessage(new HttpRequestMessage(HttpMethod.Get, Url));
96+
if (req is null || !req.IsSuccessStatusCode)
97+
{
98+
if (req == null)
99+
{
100+
_logger.Error("Credit request returned nothing");
101+
}
102+
else
103+
{
104+
_logger.Error("StatusCode: {0}, Reason: {1}", req.StatusCode, req.ReasonPhrase);
105+
}
106+
continue;
107+
}
108+
109+
var creditStream = await req.Content.ReadAsStreamAsync();
110+
if (creditStream.Length == 0)
111+
{
112+
_logger.Error("Credit stream contains nothing!");
113+
continue;
114+
}
115+
116+
if (File.Exists(CreditsFileLocation))
117+
{
118+
File.Delete(CreditsFileLocation);
119+
}
120+
var fileStream = File.OpenWrite(CreditsFileLocation);
121+
await creditStream.CopyToAsync(fileStream);
122+
await creditStream.DisposeAsync();
123+
await fileStream.DisposeAsync();
124+
_downloadedCredit = true;
125+
break;
126+
}
127+
}
12128
}
13129
}

MultiRPC/UI/Pages/Rpc/BaseRpcControl.axaml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ public void Initialize(bool loadXaml)
110110
}
111111
else
112112
{
113+
Language.LanguageChanged += (sender, args) =>
114+
{
115+
Data.MultiRPCImages = Data.MakeImagesDictionary();
116+
var largeKey = cboLargeKey.SelectedIndex;
117+
var smallKey = cboSmallKey.SelectedIndex;
118+
119+
cboLargeKey.Items = Data.MultiRPCImages.Keys;
120+
cboSmallKey.Items = Data.MultiRPCImages.Keys;
121+
cboLargeKey.SelectedIndex = largeKey;
122+
cboSmallKey.SelectedIndex = smallKey;
123+
};
113124
cboLargeKey.Items = Data.MultiRPCImages.Keys;
114125
cboSmallKey.Items = Data.MultiRPCImages.Keys;
115126
var largeKey = Data.MultiRPCImages.Keys.IndexOf(x => x?.ToLower() == RichPresence.Profile.LargeKey);
@@ -211,6 +222,11 @@ private static CheckResult Check(string s, int max)
211222

212223
private void CboLargeKey_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
213224
{
225+
if (e.AddedItems.Count == 0)
226+
{
227+
return;
228+
}
229+
214230
var key = e.AddedItems[0]?.ToString();
215231
RichPresence.Profile.LargeKey = cboLargeKey.SelectedIndex != 0 ?
216232
key?.ToLower() ?? string.Empty : string.Empty;
@@ -225,6 +241,11 @@ private void CboLargeKey_OnSelectionChanged(object? sender, SelectionChangedEven
225241

226242
private void CboSmallKey_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
227243
{
244+
if (e.AddedItems.Count == 0)
245+
{
246+
return;
247+
}
248+
228249
var key = e.AddedItems[0]?.ToString();
229250
RichPresence.Profile.SmallKey = cboSmallKey.SelectedIndex != 0 ?
230251
key?.ToLower() ?? string.Empty : string.Empty;

0 commit comments

Comments
 (0)