This commit is contained in:
2509_92447106 committed 2026-11-07 20:01:58 +08:00
1 parent d81ab2acaa
commit 639ff1ba57
15 files changed
+227 -151

No files matched your search

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
@@ -23,18 +22,26 @@ namespace EarthModelStudio.Services;
public sealed class GitCodeReleaseRemote : IModelRemote
{
private readonly GitCodeRemote _content;
private readonly HttpClient _http;
private readonly string _releasesUrl;
private readonly Dictionary<string, (string Url, string? Sha256, long Size, string Name)> _assets = new();
public GitCodeReleaseRemote(string? manifestUrl, string? repository, HttpClient? http = null)
// 共享静态 HttpClient:避免每次检查更新都创建新实例导致端口耗尽;
// headers 只在一处设置,多个线程并发读取是线程安全的。
private static readonly HttpClient Http = CreateHttp();
private static HttpClient CreateHttp()
{
var client = new HttpClient { Timeout = TimeSpan.FromSeconds(15) };
client.DefaultRequestHeaders.UserAgent.ParseAdd("EarthModelStudio-Updater/1.0");
client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
return client;
}
public GitCodeReleaseRemote(string? manifestUrl, string? repository)
{
_content = new GitCodeRemote(manifestUrl, repository);
var (owner, repo) = ParseOwnerRepo(repository);
_releasesUrl = $"https://api.gitcode.com/api/v5/repos/{owner}/{repo}/releases";
_http = http ?? new HttpClient { Timeout = TimeSpan.FromSeconds(15) };
_http.DefaultRequestHeaders.UserAgent.ParseAdd("EarthModelStudio-Updater/1.0");
_http.DefaultRequestHeaders.Accept.ParseAdd("application/json");
DisplayName = (string.IsNullOrWhiteSpace(repository)
? GitCodeRemote.DefaultRepository : repository!.TrimEnd('/')) + " (Release)";
}
@@ -77,7 +84,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);
timeout.CancelAfter(TimeSpan.FromSeconds(12));
var text = await _http.GetStringAsync(_releasesUrl, timeout.Token);
var text = await Http.GetStringAsync(_releasesUrl, timeout.Token);
var trimmed = text.TrimStart();
if (trimmed.Length == 0 || trimmed[0] != '[') return; // 可能是错误页/对象
@@ -20,13 +20,19 @@ public sealed class ReleaseInfo
/// <summary>从 tag_name / name 里抽出的版本号(去掉前缀 v、GC- 等)。</summary>
public string Version => NormalizeVersion(TagName, Name);
private static readonly string[] VersionPrefixes =
{ "v", "V", "GC-", "gc-", "release-", "Release-" };
private static readonly string[] PrereleaseTags =
{ "alpha", "beta", "rc", "pre", "dev", "snapshot" };
public static string NormalizeVersion(string tag, string name)
{
var raw = !string.IsNullOrWhiteSpace(tag) ? tag : name;
if (string.IsNullOrWhiteSpace(raw)) return "";
raw = raw!.Trim();
// "v1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分
foreach (var prefix in new[] { "v", "V", "GC-", "gc-", "release-", "Release-" })
foreach (var prefix in VersionPrefixes)
if (raw.StartsWith(prefix, StringComparison.Ordinal)) { raw = raw[prefix.Length..]; break; }
// 形如 GC-1.0.1-Win-amd64 时只取版本段;但 2.3.0-beta 这类预发布串要保留完整。
// 用「后缀是否常见预发布标签」区分,避免把 "-Win" 误当成预发布。
@@ -34,9 +40,7 @@ public sealed class ReleaseInfo
if (dash > 0 && System.Version.TryParse(raw[..dash], out _))
{
var tail = raw[(dash + 1)..].ToLowerInvariant();
bool isPrerelease = tail.StartsWith("alpha") || tail.StartsWith("beta") ||
tail.StartsWith("rc") || tail.StartsWith("pre") ||
tail.StartsWith("dev") || tail.StartsWith("snapshot");
var isPrerelease = Array.Exists(PrereleaseTags, p => tail.StartsWith(p, StringComparison.Ordinal));
if (!isPrerelease) raw = raw[..dash];
}
return raw;
@@ -25,6 +25,16 @@
<GradientStop Color="#1A3057" Offset="0.55" />
<GradientStop Color="#0E1A31" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="TitleBarBg" StartPoint="0%,0%" EndPoint="100%,100%">
<GradientStop Color="#101C33" Offset="0" />
<GradientStop Color="#0B1322" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="SideBgBrush" StartPoint="0%,0%" EndPoint="0%,100%">
<GradientStop Color="#0E1729" Offset="0" />
<GradientStop Color="#0A1120" Offset="1" />
</LinearGradientBrush>
</Styles.Resources>
<Style Selector="Window">
@@ -139,12 +149,6 @@
</Transitions>
</Setter>
</Style>
<Style Selector="Button:pointerover">
<Setter Property="RenderTransform" Value="translateY(-1px)" />
</Style>
<Style Selector="Button:pressed">
<Setter Property="RenderTransform" Value="translateY(1px)" />
</Style>
<Style Selector="Button.primary">
<Setter Property="Foreground" Value="White" />
</Style>
@@ -220,6 +224,8 @@
<Style Selector="Button.nav.active /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="#1C2C4C" />
<Setter Property="Foreground" Value="#FFFFFF" />
<Setter Property="BorderBrush" Value="{DynamicResource Accent}" />
<Setter Property="BorderThickness" Value="3,0,0,0" />
</Style>
<!-- 输入 -->
@@ -274,14 +280,19 @@
<Setter Property="Foreground" Value="#FFFFFF" />
</Style>
<!-- 所有按钮按下时的缩放反馈(MENU 按钮同样生效) -->
<!--
按下反馈用 TransformOperations 语法,与上面 Button 的
TransformOperationsTransition 保持一致;若改成 ScaleTransform 对象,
状态切换时过渡器无法转换类型,会导致悬停/按下时渲染异常。
-->
<Style Selector="Button">
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
</Style>
<Style Selector="Button:pointerover">
<Setter Property="RenderTransform" Value="scale(0.98)" />
</Style>
<Style Selector="Button:pressed">
<Setter Property="RenderTransform">
<ScaleTransform ScaleX="0.94" ScaleY="0.94" />
</Setter>
<Setter Property="RenderTransform" Value="scale(0.94)" />
</Style>
</Styles>
@@ -5,14 +5,20 @@
Title="{loc:Loc app.name}"
Width="1220" Height="800"
MinWidth="1040" MinHeight="700"
Background="{DynamicResource AppBg}"
Background="#0A1120"
TransparencyLevelHint="None"
SystemDecorations="None"
WindowStartupLocation="CenterScreen">
<!-- 禁用系统标题栏,改用自建标题栏(第 13/14 项) -->
<Grid RowDefinitions="44,*">
<!-- 禁用系统标题栏,改用自建标题栏;外层圆角容器让整个窗口四角变圆。
用深色不透明底,避免透明/亚克力在无边框窗口下露出系统白边。 -->
<Border CornerRadius="16" ClipToBounds="True"
Background="{DynamicResource AppBg}"
BorderBrush="#0A1120" BorderThickness="1"
BoxShadow="0 18 50 0 #400A1226">
<Grid RowDefinitions="44,*">
<!-- 自建标题栏 -->
<Border x:Name="TitleBar" Grid.Row="0" Background="{DynamicResource SideBg}"
<Border x:Name="TitleBar" Grid.Row="0" Background="{DynamicResource TitleBarBg}"
PointerPressed="OnTitleBarPointerPressed">
<Grid ColumnDefinitions="*,Auto,Auto" Margin="16,0,8,0">
<StackPanel Orientation="Horizontal" Spacing="10" VerticalAlignment="Center">
@@ -33,22 +39,16 @@
<!-- 原内容整体下移一行 -->
<Grid Grid.Row="1" ColumnDefinitions="236,*" RowDefinitions="*,Auto">
<!-- 侧栏 -->
<Border Grid.Column="0" Grid.RowSpan="2" Background="{DynamicResource SideBg}">
<Grid RowDefinitions="Auto,*,Auto" Margin="16,22,16,18">
<!-- 侧栏:品牌已在标题栏展示,这里只留一句副标题,避免重复 -->
<Border Grid.Column="0" Grid.RowSpan="2" Background="{DynamicResource SideBgBrush}">
<Grid RowDefinitions="Auto,*,Auto" Margin="16,20,16,18">
<StackPanel Orientation="Horizontal" Spacing="11">
<Border Width="38" Height="38" CornerRadius="12" Background="#1C2C4C">
<TextBlock Text="◎" FontSize="20" Foreground="#8FB6FF"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<StackPanel VerticalAlignment="Center" Spacing="1">
<TextBlock Text="{loc:Loc app.name}" Foreground="#F2F6FF" FontSize="13.5" FontWeight="SemiBold" />
<TextBlock Text="{loc:Loc app.tagline}" Foreground="#7C90B4" FontSize="10" />
</StackPanel>
<StackPanel Spacing="3" Margin="2,0,0,0">
<TextBlock Text="{loc:Loc app.tagline}" Foreground="#7C90B4" FontSize="10.5"
TextWrapping="Wrap" />
</StackPanel>
<StackPanel Grid.Row="1" Margin="0,30,0,0" Spacing="6">
<StackPanel Grid.Row="1" Margin="0,26,0,0" Spacing="6">
<TextBlock Text="MENU" Foreground="#4C5F80" FontSize="9.5" FontWeight="SemiBold" Margin="14,0,0,4" />
<Button Classes="nav" Classes.active="{Binding IsHomeActive}"
Command="{Binding GoHomeCommand}" Content="{loc:Loc nav.home}" />
@@ -95,4 +95,5 @@
</Border>
</Grid>
</Grid>
</Border>
</Window>
@@ -2,6 +2,7 @@ using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Media;
using System.Collections.Generic;
using EarthModelStudio.Models;
@@ -28,12 +29,65 @@ public sealed class PlayerWindow : Window
MinHeight = 680;
Background = new SolidColorBrush(Color.Parse("#05070F"));
WindowStartupLocation = WindowStartupLocation.CenterOwner;
Content = model.View;
// 与启动器一致:去掉系统标题栏,自己做一个极简顶栏(否则 Esc 之外无法关闭)
SystemDecorations = Avalonia.Controls.SystemDecorations.None;
var titleBar = new Border
{
Height = 34,
Background = new SolidColorBrush(Color.Parse("#0A1120")),
Child = new Grid
{
ColumnDefinitions = new ColumnDefinitions("*,Auto"),
Children =
{
new TextBlock
{
Text = package.LocalizedName,
Foreground = new SolidColorBrush(Color.Parse("#A9B8D4")),
FontSize = 11.5,
Margin = new Thickness(14, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center,
[Grid.ColumnProperty] = 0
},
new Button
{
Content = "✕",
Width = 40,
Height = 28,
Background = Brushes.Transparent,
Foreground = new SolidColorBrush(Color.Parse("#A9B8D4")),
BorderThickness = new Thickness(0),
FontSize = 13,
CornerRadius = new CornerRadius(7),
Margin = new Thickness(0, 0, 8, 0),
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
[Grid.ColumnProperty] = 1
}
}
}
};
titleBar.PointerPressed += OnTitleBarPointerPressed;
if (titleBar.Child is Grid g)
foreach (var child in g.Children)
if (child is Button b) b.Click += (_, _) => Close();
Content = new DockPanel { LastChildFill = true };
DockPanel.SetDock(titleBar, Dock.Top);
((DockPanel)Content).Children.Add(titleBar);
((DockPanel)Content).Children.Add(model.View);
KeyDown += OnKeyDown;
Closed += OnClosed;
}
private void OnTitleBarPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
BeginMoveDrag(e);
}
private void OnKeyDown(object? sender, KeyEventArgs e)
{
switch (e.Key)