Skip to content

Commit 32eb23c

Browse files
committed
lot's of small changes
* Moved Pipe check to it's own Util file * Made Source Generator project and made TextEnumGen to make LanguageText enum * Made LanguageText overloads for Language * Use LanguageText overloads when possible * Use App's HttpClient for RpcView * Added IPC and use it to reopen the current instance if there is one * Use System.Text.Json for Lanuage again * Disabled some warnings on Component * Fixed the need for a while loop in Opening the MainWindow
1 parent 069cfa9 commit 32eb23c

30 files changed

+582
-231
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.0-6.final" PrivateAssets="all" />
11+
<PackageReference Include="Uno.Roslyn" Version="1.3.0-dev.12" PrivateAssets="all" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<!-- Package the generator in the analyzer directory of the nuget package -->
16+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
17+
</ItemGroup>
18+
19+
</Project>

MultiRPC.SourceGen/TextEnumGen.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Linq;
4+
using System.Text;
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.Text;
7+
using Uno.RoslynHelpers;
8+
9+
namespace MultiRPC.SourceGen
10+
{
11+
/// <summary>
12+
/// This takes our en-gb.json language and makes LanguageText for us!
13+
/// </summary>
14+
[Generator]
15+
public class TextEnumGen : ISourceGenerator
16+
{
17+
public void Initialize(GeneratorInitializationContext context) { }
18+
19+
public void Execute(GeneratorExecutionContext context)
20+
{
21+
var langFile = context.AdditionalFiles.First(at => at.Path.EndsWith("en-gb.json")).GetText();
22+
if (langFile == null)
23+
{
24+
return;
25+
}
26+
27+
var builder = new IndentedStringBuilder();
28+
using (builder.BlockInvariant("namespace MultiRPC"))
29+
{
30+
using (builder.BlockInvariant("public enum LanguageText"))
31+
{
32+
foreach (var line in langFile.Lines)
33+
{
34+
var firstLine = false;
35+
var startIndex = 0;
36+
var endIndex = 0;
37+
var s = line.ToString();
38+
for (int i = 0; i < s.Length; i++)
39+
{
40+
if (s[i] != '\"')
41+
{
42+
continue;
43+
}
44+
if (firstLine)
45+
{
46+
endIndex = i;
47+
break;
48+
}
49+
50+
firstLine = true;
51+
startIndex = i + 1;
52+
}
53+
54+
if (startIndex > 0 && endIndex > 0)
55+
{
56+
var li = s[startIndex..endIndex];
57+
builder.AppendLineInvariant(li + ",");
58+
}
59+
}
60+
}
61+
}
62+
63+
// inject the created source into the users compilation
64+
context.AddSource("MultiRPC.LanguageText.cs", SourceText.From(builder.ToString(), Encoding.UTF8));
65+
}
66+
}
67+
}

MultiRPC.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaGif", "ext\avalonia
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ext", "ext", "{B7AAF9E7-1C1E-4376-BAF6-D2FCA8B39CDF}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiRPC.SourceGen", "MultiRPC.SourceGen\MultiRPC.SourceGen.csproj", "{3369169D-31C0-4A74-A5A9-F2BB1EA80705}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -36,6 +38,12 @@ Global
3638
{D4EBB986-EDAC-4C0B-AB58-70E4A5C7D2A4}.Release|Any CPU.Build.0 = Release|Any CPU
3739
{D4EBB986-EDAC-4C0B-AB58-70E4A5C7D2A4}.WINSTORE|Any CPU.ActiveCfg = WINSTORE|Any CPU
3840
{D4EBB986-EDAC-4C0B-AB58-70E4A5C7D2A4}.WINSTORE|Any CPU.Build.0 = WINSTORE|Any CPU
41+
{3369169D-31C0-4A74-A5A9-F2BB1EA80705}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{3369169D-31C0-4A74-A5A9-F2BB1EA80705}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{3369169D-31C0-4A74-A5A9-F2BB1EA80705}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{3369169D-31C0-4A74-A5A9-F2BB1EA80705}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{3369169D-31C0-4A74-A5A9-F2BB1EA80705}.WINSTORE|Any CPU.ActiveCfg = Debug|Any CPU
46+
{3369169D-31C0-4A74-A5A9-F2BB1EA80705}.WINSTORE|Any CPU.Build.0 = Debug|Any CPU
3947
EndGlobalSection
4048
GlobalSection(SolutionProperties) = preSolution
4149
HideSolutionNode = FALSE

MultiRPC/Assets/Language/en-gb.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,6 @@
235235
"MajorOutage": "Major outage!",
236236
"LogLevel": "Log Level",
237237
"GithubTooltip": "Access all the source code",
238-
"FluxpointTooltip": "Look at the other services that Fluxpoint offer!"
238+
"FluxpointTooltip": "Look at the other services that Fluxpoint offer!",
239+
"NA": "N/A"
239240
}

MultiRPC/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ static Constants()
5050
/// </summary>
5151
public const string ServerInviteCode = "TjF6QDC";
5252

53+
/// <summary>
54+
/// Url for the discord server
55+
/// </summary>
56+
public const string DiscordServerUrl = "https://discord.gg/" + ServerInviteCode;
57+
5358
/// <summary>
5459
/// Serializer for JSON
5560
/// </summary>

MultiRPC/Data.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static Dictionary<string, string> MakeImagesDictionary()
1111
{
1212
return new Dictionary<string, string>
1313
{
14-
{Language.GetText("NoImage"), ""},
14+
{Language.GetText(LanguageText.NoImage), ""},
1515
{"Discord", "https://i.imgur.com/QN5WA4W.png"},
1616
{"MultiRPC", "https://i.imgur.com/d6OLF2z.png"},
1717
{"Firefox", "https://i.imgur.com/oTuovMT.png"},
@@ -28,12 +28,12 @@ public static Dictionary<string, string> MakeImagesDictionary()
2828
{"Pepe", "https://i.imgur.com/7ybyrw7.png"},
2929
{"Trollface", "https://i.imgur.com/tanLvrt.png"},
3030
{"Doge", "https://i.imgur.com/ytpmvjg.png"},
31-
{Language.GetText("Christmas"), "https://i.imgur.com/NF2enEO.png"},
32-
{Language.GetText("Present"), "https://i.imgur.com/qMfJKt6.png"},
31+
{Language.GetText(LanguageText.Christmas), "https://i.imgur.com/NF2enEO.png"},
32+
{Language.GetText(LanguageText.Present), "https://i.imgur.com/qMfJKt6.png"},
3333
{"Neko", "https://i.imgur.com/l2RsYY7.png"},
34-
{Language.GetText("Popcorn"), "https://i.imgur.com/xplfztu.png"},
34+
{Language.GetText(LanguageText.Popcorn), "https://i.imgur.com/xplfztu.png"},
3535
{"Skype", "https://i.imgur.com/PjQFB6d.png"},
36-
{Language.GetText("Games"), "https://i.imgur.com/lPrT5BG.png"},
36+
{Language.GetText(LanguageText.Games), "https://i.imgur.com/lPrT5BG.png"},
3737
{"Steam", "https://i.imgur.com/bKxJ7Lj.png"},
3838
{"Minecraft", "https://i.imgur.com/vnw6Z8X.png"},
3939
{"Coke", "https://i.imgur.com/GAsmn3P.png"}

MultiRPC/Discord/IDChecker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ await App.HttpClient.GetResponseMessage(
2525

2626
if (responseMessage is null or { IsSuccessStatusCode: false })
2727
{
28-
return (false, Language.GetText("DiscordAPIDown"));
28+
return (false, Language.GetText(LanguageText.DiscordAPIDown));
2929
}
3030
if (responseMessage.StatusCode == HttpStatusCode.BadRequest)
3131
{
32-
return (false, Language.GetText("ClientIDIsNotValid"));
32+
return (false, Language.GetText(LanguageText.ClientIDIsNotValid));
3333
}
3434

3535
var response = JsonSerializer.Deserialize<ClientCheckResult>(await responseMessage.Content.ReadAsStreamAsync());
3636

3737
return !string.IsNullOrEmpty(response?.Message) ?
38-
(false, $"{Language.GetText("ClientIDIsNotValid")}\r\n{response?.Message}")
38+
(false, $"{Language.GetText(LanguageText.ClientIDIsNotValid)}\r\n{response?.Message}")
3939
: (true, response!.Name);
4040
}
4141
}
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,79 @@
11
using System;
22
using System.Text.Json.Serialization;
33

4+
// ReSharper disable UnusedAutoPropertyAccessor.Global
5+
#pragma warning disable CS8618
46
namespace MultiRPC.Discord.Status
57
{
68
/*public class Page
79
{
810
[JsonPropertyName("id")]
9-
public string Id { get; set; }
11+
public string Id { get; init; }
1012
1113
[JsonPropertyName("name")]
12-
public string Name { get; set; }
14+
public string Name { get; init; }
1315
1416
[JsonPropertyName("url")]
15-
public string Url { get; set; }
17+
public string Url { get; init; }
1618
1719
[JsonPropertyName("time_zone")]
18-
public string TimeZone { get; set; }
20+
public string TimeZone { get; init; }
1921
2022
[JsonPropertyName("updated_at")]
21-
public DateTime UpdatedAt { get; set; }
23+
public DateTime UpdatedAt { get; init; }
2224
}*/
2325

2426
public class Component
2527
{
2628
[JsonPropertyName("id")]
27-
public string Id { get; set; }
29+
public string Id { get; init; }
2830

2931
[JsonPropertyName("name")]
30-
public string Name { get; set; }
32+
public string Name { get; init; }
3133

3234
[JsonPropertyName("status")]
33-
public string Status { get; set; }
35+
public string Status { get; init; }
3436

3537
[JsonPropertyName("created_at")]
36-
public DateTime CreatedAt { get; set; }
38+
public DateTime CreatedAt { get; init; }
3739

3840
[JsonPropertyName("updated_at")]
39-
public DateTime UpdatedAt { get; set; }
41+
public DateTime UpdatedAt { get; init; }
4042

4143
[JsonPropertyName("position")]
42-
public int Position { get; set; }
44+
public int Position { get; init; }
4345

4446
[JsonPropertyName("description")]
45-
public string Description { get; set; }
47+
public string Description { get; init; }
4648

4749
[JsonPropertyName("showcase")]
48-
public bool Showcase { get; set; }
50+
public bool Showcase { get; init; }
4951

5052
[JsonPropertyName("start_date")]
51-
public string StartDate { get; set; }
53+
public string StartDate { get; init; }
5254

5355
[JsonPropertyName("group_id")]
54-
public string GroupId { get; set; }
56+
public string GroupId { get; init; }
5557

5658
[JsonPropertyName("page_id")]
57-
public string PageId { get; set; }
59+
public string PageId { get; init; }
5860

5961
[JsonPropertyName("group")]
60-
public bool Group { get; set; }
62+
public bool Group { get; init; }
6163

6264
[JsonPropertyName("only_show_if_degraded")]
63-
public bool OnlyShowIfDegraded { get; set; }
65+
public bool OnlyShowIfDegraded { get; init; }
6466

6567
[JsonPropertyName("components")]
66-
public string[] Components { get; set; }
68+
public string[] Components { get; init; }
6769
}
6870

6971
public class Data
7072
{
7173
//[JsonPropertyName("page")]
72-
//public Page Page { get; set; }
74+
//public Page Page { get; init; }
7375

7476
[JsonPropertyName("components")]
75-
public Component[] Components { get; set; }
77+
public Component[] Components { get; init; }
7678
}
7779
}

0 commit comments

Comments
 (0)