mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-22 19:06:15 +08:00
[GUI] Last commit SHA (id) displayed on about section (#279)
* Latest commit info axamal structure * Link latest commit to text * Added localization for About>Last commit info * Made the commit hash a button that redirects you to the commit in github * Reorder about section * Commit and update icon in about section to have consistency in section
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 653 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
@@ -141,6 +141,8 @@
|
||||
"Options.About" : "About",
|
||||
"About.Github.Label": "GitHub",
|
||||
"About.Github.Desc": "Source code, issues and project development.",
|
||||
"About.Github.LatestCommitLabel": "Latest Commit",
|
||||
"About.Github.LatestCommitDescription": "Latest commit on the main branch",
|
||||
"About.Discord.Label": "Discord",
|
||||
"About.Discord.Desc": "Join the community, get support and follow development.",
|
||||
"About.GithubButton": "Contribute in GitHub!",
|
||||
|
||||
@@ -131,6 +131,8 @@
|
||||
"About.Github.Label": "GitHub",
|
||||
"About.Github.Desc": "Código fuente, issues y desarrollo del proyecto.",
|
||||
"About.Discord.Label": "Discord",
|
||||
"About.Github.LatestCommitLabel": "Último Commit",
|
||||
"About.Github.LatestCommitDescription": "Último commit en la rama main",
|
||||
"About.Discord.Desc": "Únete a la comunidad, recibe soporte y sigue el desarrollo.",
|
||||
"About.GithubButton": "Contribuye en GitHub!",
|
||||
"About.DiscordButton": "Únete a nuestro Discord!"
|
||||
|
||||
@@ -333,11 +333,35 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
||||
Classes="sectionTitle"
|
||||
Text="ABOUT" />
|
||||
|
||||
<!--Latest commit info-->
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Spacing="2" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="UpdateLabel" Text="Updates" FontSize="13" />
|
||||
<TextBlock x:Name="UpdateStatusText" Text="Current build: dev" FontSize="11"
|
||||
Foreground="{StaticResource MutedBrush}" TextWrapping="Wrap" />
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
|
||||
<Image Source="avares://SharpEmu.GUI/Assets/commit-icon.png"
|
||||
Width="24" Height="24" VerticalAlignment="Center" />
|
||||
<StackPanel Spacing="2" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="LatestCommitLabel" Text="Latest commit" FontSize="13"/>
|
||||
<TextBlock x:Name="LatestCommitDescription" Text="Latest commit on the main branch" FontSize="11" Foreground="{StaticResource MutedBrush}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1" x:Name="LatestCommitHashText" Classes="ghost"
|
||||
Content="Loading…" FontSize="12" FontFamily="Consolas,monospace"
|
||||
VerticalAlignment="Center" IsEnabled="False" />
|
||||
|
||||
</Grid>
|
||||
|
||||
<!--Update-->
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
|
||||
<Image Source="avares://SharpEmu.GUI/Assets/update-icon.png"
|
||||
Width="24"
|
||||
Height="24"
|
||||
VerticalAlignment="Center" />
|
||||
<StackPanel Spacing="2" VerticalAlignment="Center">
|
||||
<TextBlock x:Name="UpdateLabel" Text="Updates" FontSize="13" />
|
||||
<TextBlock x:Name="UpdateStatusText" Text="Current build: dev" FontSize="11"
|
||||
Foreground="{StaticResource MutedBrush}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<Button Grid.Column="1" x:Name="UpdateButton" Classes="ghost"
|
||||
Content="Check for updates" VerticalAlignment="Center" />
|
||||
|
||||
@@ -20,6 +20,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace SharpEmu.GUI;
|
||||
|
||||
@@ -78,6 +79,10 @@ public partial class MainWindow : Window
|
||||
private long _navUpNextAt;
|
||||
private long _navDownNextAt;
|
||||
|
||||
//Github http client for latest commit
|
||||
private static readonly HttpClient GithubHttpClient = CreateGithubHttpClient();
|
||||
private string? _latestCommitSha;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -195,6 +200,21 @@ public partial class MainWindow : Window
|
||||
UseShellExecute = true
|
||||
});
|
||||
};
|
||||
|
||||
LatestCommitHashText.Click += (_, _) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_latestCommitSha))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName =
|
||||
$"https://github.com/sharpemu/sharpemu/commit/{_latestCommitSha}",
|
||||
UseShellExecute = true
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -236,6 +256,91 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Github http client config ----
|
||||
// This is for getting lash commit id
|
||||
private static HttpClient CreateGithubHttpClient()
|
||||
{
|
||||
var client = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(15)
|
||||
};
|
||||
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("SharpEmu/1.0");
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/vnd.github.sha"));
|
||||
|
||||
client.DefaultRequestHeaders.Add(
|
||||
"X-GitHub-Api-Version",
|
||||
"2026-03-10");
|
||||
|
||||
return client;
|
||||
}
|
||||
private async Task LoadLatestCommitAsync()
|
||||
{
|
||||
const string apiUrl =
|
||||
"https://api.github.com/repos/sharpemu/sharpemu/commits/main";
|
||||
|
||||
_latestCommitSha = null;
|
||||
LatestCommitHashText.Content = "Loading…";
|
||||
LatestCommitHashText.IsEnabled = false;
|
||||
|
||||
try
|
||||
{
|
||||
using var response = await GithubHttpClient.GetAsync(apiUrl);
|
||||
var responseBody =
|
||||
(await response.Content.ReadAsStringAsync()).Trim();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LatestCommitHashText.Content =
|
||||
$"HTTP {(int)response.StatusCode}";
|
||||
|
||||
ToolTip.SetTip(
|
||||
LatestCommitHashText,
|
||||
string.IsNullOrWhiteSpace(responseBody)
|
||||
? response.ReasonPhrase
|
||||
: responseBody);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (responseBody.Length < 7)
|
||||
{
|
||||
LatestCommitHashText.Content = "Invalid response";
|
||||
ToolTip.SetTip(LatestCommitHashText, responseBody);
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep the complete SHA for the URL.
|
||||
_latestCommitSha = responseBody;
|
||||
|
||||
// Display only the short SHA.
|
||||
LatestCommitHashText.Content =
|
||||
responseBody[..Math.Min(7, responseBody.Length)];
|
||||
|
||||
LatestCommitHashText.IsEnabled = true;
|
||||
|
||||
ToolTip.SetTip(
|
||||
LatestCommitHashText,
|
||||
$"Open commit {_latestCommitSha}");
|
||||
}
|
||||
catch (TaskCanceledException ex)
|
||||
{
|
||||
LatestCommitHashText.Content = "Timeout";
|
||||
ToolTip.SetTip(LatestCommitHashText, ex.Message);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
LatestCommitHashText.Content = "Connection error";
|
||||
ToolTip.SetTip(LatestCommitHashText, ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LatestCommitHashText.Content = "Error";
|
||||
ToolTip.SetTip(LatestCommitHashText, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Controller navigation ----
|
||||
|
||||
private void PollGamepad()
|
||||
@@ -381,6 +486,8 @@ public partial class MainWindow : Window
|
||||
ApplySettingsToControls();
|
||||
LocateEmulator();
|
||||
UpdateDiscordPresence();
|
||||
_ = LoadLatestCommitAsync();
|
||||
|
||||
if (_settings.CheckForUpdatesOnStartup)
|
||||
{
|
||||
_ = CheckForUpdatesAsync();
|
||||
@@ -516,6 +623,8 @@ public partial class MainWindow : Window
|
||||
GithubButton.Content = loc.Get("About.GithubButton");
|
||||
DiscordButton.Content = loc.Get("About.DiscordButton");
|
||||
UpdateLabel.Text = loc.Get("Updater.Label");
|
||||
LatestCommitLabel.Text = loc.Get("About.Github.LatestCommitLabel");
|
||||
LatestCommitDescription.Text = loc.Get("About.Github.LatestCommitDescription");
|
||||
RefreshUpdateText();
|
||||
|
||||
UpdateEmptyStateTexts();
|
||||
|
||||
@@ -32,6 +32,8 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
||||
<AvaloniaResource Include="..\..\assets\images\SharpEmu.ico" Link="Assets/SharpEmu.ico" />
|
||||
<AvaloniaResource Include="..\..\assets\images\github.png" Link="Assets/github.png" />
|
||||
<AvaloniaResource Include="..\..\assets\images\discord.png" Link="Assets/discord.png" />
|
||||
<AvaloniaResource Include="..\..\assets\images\update-icon.png" Link="Assets/update-icon.png" />
|
||||
<AvaloniaResource Include="..\..\assets\images\commit-icon.png" Link="Assets/commit-icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user