修复
This commit is contained in:
1 parent
ab39c5103d
commit
d81ab2acaa
20 files changed
+312
-66
No files matched your search
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"app.name": "Earth Model Studio",
|
||||
"app.name": "Morris GC",
|
||||
"app.tagline": "Astronomy teaching models · visual launcher",
|
||||
"app.version": "Version",
|
||||
"app.platform": "Platform",
|
||||
@@ -74,6 +74,7 @@
|
||||
"set.memory.current": "In use",
|
||||
"set.memory.unit": "MB",
|
||||
"set.memory.hint": "2048 MB or more is recommended; 1024 MB for low-end devices.",
|
||||
"set.memory.auto": "Auto (allocate based on device memory)",
|
||||
"set.preallocate": "Preload land data at startup",
|
||||
"set.preallocate.desc": "Faster first frame, slightly slower startup.",
|
||||
"set.sources": "Model sources",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"app.name": "地球模型工作室",
|
||||
"app.name": "Morris GC",
|
||||
"app.tagline": "天文教学模型 · 可视化启动器",
|
||||
"app.version": "版本",
|
||||
"app.platform": "平台",
|
||||
@@ -74,6 +74,7 @@
|
||||
"set.memory.current": "当前占用",
|
||||
"set.memory.unit": "MB",
|
||||
"set.memory.hint": "建议 2048 MB 以上,低配设备可选 1024 MB。",
|
||||
"set.memory.auto": "自动(根据设备内存分配)",
|
||||
"set.preallocate": "启动时预加载模型地表数据",
|
||||
"set.preallocate.desc": "打开后首帧更快,启动耗时略增。",
|
||||
"set.sources": "模型源",
|
||||
|
||||
@@ -13,12 +13,15 @@ public sealed class AppSettings
|
||||
/// <summary>light | dark</summary>
|
||||
public string Theme { get; set; } = "light";
|
||||
|
||||
/// <summary>渲染帧率:24 / 30 / 60</summary>
|
||||
public int RenderFps { get; set; } = 30;
|
||||
/// <summary>渲染帧率:24 / 30 / 60 / 90 / 120(上限 120,关闭 VSync 同步)</summary>
|
||||
public int RenderFps { get; set; } = 120;
|
||||
|
||||
/// <summary>启动时运行内存分配(MB)——决定场景缓存/纹理预算。</summary>
|
||||
public int MemoryMb { get; set; } = 2048;
|
||||
|
||||
/// <summary>自动模式:根据设备可用内存自动计算预算(忽略 MemoryMb)。</summary>
|
||||
public bool MemoryAuto { get; set; } = true;
|
||||
|
||||
/// <summary>启动时检查模型源更新。</summary>
|
||||
public bool CheckSourceOnStartup { get; set; }
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ public sealed class AppServices
|
||||
|
||||
var services = new AppServices(paths);
|
||||
L.I.Initialize(services.Settings.Current.Language);
|
||||
services.Memory.Apply(services.Settings.Current.MemoryMb);
|
||||
services.Memory.ApplyAuto(services.Settings.Current.MemoryAuto,
|
||||
services.Settings.Current.MemoryMb);
|
||||
|
||||
Current = services;
|
||||
return services;
|
||||
|
||||
@@ -25,7 +25,7 @@ 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)> _assets = new();
|
||||
private readonly Dictionary<string, (string Url, string? Sha256, long Size, string Name)> _assets = new();
|
||||
|
||||
public GitCodeReleaseRemote(string? manifestUrl, string? repository, HttpClient? http = null)
|
||||
{
|
||||
@@ -101,7 +101,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote
|
||||
if (rid == null || string.IsNullOrWhiteSpace(asset.Url)) continue;
|
||||
// 同名平台取第一个有效附件
|
||||
if (!_assets.ContainsKey(rid))
|
||||
_assets[rid] = (asset.Url, asset.Sha256, asset.Size);
|
||||
_assets[rid] = (asset.Url, asset.Sha256, asset.Size, asset.Name);
|
||||
}
|
||||
|
||||
// 把附件地址写回 packages:有附件就用附件的直链与校验值,
|
||||
@@ -114,6 +114,7 @@ public sealed class GitCodeReleaseRemote : IModelRemote
|
||||
version.Launcher.Packages[rid] = pkg;
|
||||
}
|
||||
pkg.Url = info.Url;
|
||||
pkg.AssetName = info.Name;
|
||||
if (!string.IsNullOrWhiteSpace(info.Sha256)) pkg.Sha256 = info.Sha256;
|
||||
if (info.Size > 0) pkg.Size = info.Size;
|
||||
}
|
||||
@@ -141,13 +142,17 @@ public sealed class GitCodeReleaseRemote : IModelRemote
|
||||
{
|
||||
foreach (var a in assets.EnumerateArray())
|
||||
{
|
||||
// 跳过 GitCode 自动生成的源码包(type=source),只取真正的发布附件
|
||||
var type = Str(a, "type");
|
||||
if (string.Equals(type, "source", StringComparison.OrdinalIgnoreCase)) continue;
|
||||
info.Assets.Add(new ReleaseAsset
|
||||
{
|
||||
Name = Str(a, "name") ?? Str(a, "file_name") ?? "",
|
||||
BrowserDownloadUrl = Str(a, "browser_download_url"),
|
||||
DownloadUrl = Str(a, "download_url") ?? Str(a, "url"),
|
||||
Size = Num(a, "size"),
|
||||
Sha256 = Str(a, "sha256") ?? Str(a, "digest")
|
||||
Sha256 = Str(a, "sha256") ?? Str(a, "digest"),
|
||||
Type = type
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,27 @@ public sealed class MemoryBudget
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动预算:取设备可用物理内存的一部分(约 1/4),
|
||||
/// 夹在 512–8192 MB 之间,低配设备也不会因为预算过大而卡顿。
|
||||
/// </summary>
|
||||
public static int AutoComputeMb()
|
||||
{
|
||||
try
|
||||
{
|
||||
var info = GC.GetGCMemoryInfo();
|
||||
var totalMb = info.TotalAvailableMemoryBytes / (1024.0 * 1024.0);
|
||||
if (totalMb > 0)
|
||||
return (int)Math.Clamp(Math.Round(totalMb / 4.0 / 256.0) * 256, 512, 8192);
|
||||
}
|
||||
catch { /* 平台不支持时回退默认值 */ }
|
||||
return 2048;
|
||||
}
|
||||
|
||||
/// <summary>按设置应用:auto 时自动计算,否则用手动值。</summary>
|
||||
public void ApplyAuto(bool auto, int manualMb)
|
||||
=> Apply(auto ? AutoComputeMb() : manualMb);
|
||||
|
||||
/// <summary>内存情况变化(例如模型窗口开关)时刷新展示。</summary>
|
||||
public void Refresh() => Changed?.Invoke();
|
||||
|
||||
|
||||
@@ -28,9 +28,17 @@ public sealed class ReleaseInfo
|
||||
// "v1.0.1" / "GC-1.0.1" / "release-1.0.1" -> 取第一段像版本号的部分
|
||||
foreach (var prefix in new[] { "v", "V", "GC-", "gc-", "release-", "Release-" })
|
||||
if (raw.StartsWith(prefix, StringComparison.Ordinal)) { raw = raw[prefix.Length..]; break; }
|
||||
// 形如 GC-1.0.1-Win-amd64 时只取版本段
|
||||
// 形如 GC-1.0.1-Win-amd64 时只取版本段;但 2.3.0-beta 这类预发布串要保留完整。
|
||||
// 用「后缀是否常见预发布标签」区分,避免把 "-Win" 误当成预发布。
|
||||
var dash = raw.IndexOf('-');
|
||||
if (dash > 0 && System.Version.TryParse(raw[..dash], out _)) raw = raw[..dash];
|
||||
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");
|
||||
if (!isPrerelease) raw = raw[..dash];
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
@@ -41,11 +49,43 @@ public sealed class ReleaseAsset
|
||||
public string? BrowserDownloadUrl { get; set; }
|
||||
public string? DownloadUrl { get; set; }
|
||||
public long Size { get; set; }
|
||||
public string? Sha256 { get; set; }
|
||||
/// <summary>附件类型:GitCode 用 "source" 表示自动生成的源码压缩包,需跳过。</summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
private string? _sha256;
|
||||
/// <summary>
|
||||
/// 校验值。真实 Release 的 digest 形如 "sha256:899fc1...",
|
||||
/// 这里统一剥掉算法前缀,只留 hex,便于与 SHA256.HashData 结果比较。
|
||||
/// </summary>
|
||||
public string? Sha256
|
||||
{
|
||||
get => _sha256;
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value)) { _sha256 = null; return; }
|
||||
var v = value!.Trim();
|
||||
var colon = v.IndexOf(':');
|
||||
if (colon > 0 && v[..colon].Equals("sha256", StringComparison.OrdinalIgnoreCase))
|
||||
v = v[(colon + 1)..];
|
||||
_sha256 = v.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public string Url => BrowserDownloadUrl ?? DownloadUrl ?? "";
|
||||
|
||||
/// <summary>单文件发布包(.exe 等)不能走解压,需要直接作为 payload 内容。</summary>
|
||||
public bool IsSingleFile
|
||||
{
|
||||
get
|
||||
{
|
||||
var n = Name.ToLowerInvariant();
|
||||
return !n.EndsWith(".zip", StringComparison.Ordinal) &&
|
||||
!n.EndsWith(".tar.gz", StringComparison.Ordinal) &&
|
||||
!n.EndsWith(".tgz", StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>解析附件名里的系统/架构,映射到 .NET RID。</summary>
|
||||
/// <returns>如 win-x64 / win-arm64 / osx-arm64;无法识别返回 null。</returns>
|
||||
public string? RidFromName(string fullName)
|
||||
@@ -60,8 +100,12 @@ public sealed class ReleaseAsset
|
||||
if (!win && !mac && !linux) return null;
|
||||
|
||||
bool arm64 = lower.Contains("arm64") || lower.Contains("aarch64") || lower.Contains("win-arm");
|
||||
bool x86 = lower.Contains("x86") && !lower.Contains("x64") && !lower.Contains("amd64") && !arm64;
|
||||
// amd64 / x64 / x86_64 都视为 x64
|
||||
// x86_64 / x86-64 / amd64 / x64 都是 64 位;只有裸 "x86"/"win-x86" 才是 32 位
|
||||
bool is64 = lower.Contains("x64") || lower.Contains("amd64") ||
|
||||
lower.Contains("x86-64") || lower.Contains("x86_64");
|
||||
bool x86 = !is64 && !arm64 &&
|
||||
(lower.Contains("x86") || lower.Contains("win32") || lower.Contains("i386"));
|
||||
// 其余(未显式标注 32 位)一律按 64 位处理,覆盖 "GC-1.0.1-Windows.zip" 这类简写
|
||||
var arch = arm64 ? "arm64" : x86 ? "x86" : "x64";
|
||||
|
||||
if (win) return "win-" + arch;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using EarthModelStudio.Models;
|
||||
|
||||
namespace EarthModelStudio.Services;
|
||||
@@ -17,24 +18,40 @@ public sealed class SettingsService
|
||||
public void Load()
|
||||
{
|
||||
Current = Json.Read<AppSettings>(_paths.SettingsFile) ?? new AppSettings();
|
||||
if (Current.Sources.Count == 0) SeedSources();
|
||||
SeedDefaultSource();
|
||||
if (Current.MemoryMb < 256) Current.MemoryMb = 2048;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动更新由 UpdateService 负责(版本清单 version.json),这里不预置任何在线源;
|
||||
/// 只给「下载」页留一条空的自定义源占位。
|
||||
/// 默认下载源(gitcode 官方仓库)始终内置在列表里,且不允许删除:
|
||||
/// 它是启动器自动更新的同源仓库,用户清掉会导致模型无法回退。
|
||||
/// 老配置里没有这条时自动补上;已有的用户自定义源保持不变。
|
||||
/// </summary>
|
||||
private void SeedSources()
|
||||
public const string DefaultSourceId = "gitcode-official";
|
||||
public const string DefaultSourceUrl = "https://gitcode.com/2509_92447106/GC";
|
||||
|
||||
private void SeedDefaultSource()
|
||||
{
|
||||
Current.Sources.Add(new ModelSource
|
||||
var existing = Current.Sources.FirstOrDefault(s =>
|
||||
string.Equals(s.Id, DefaultSourceId, StringComparison.OrdinalIgnoreCase));
|
||||
if (existing == null)
|
||||
{
|
||||
Id = "custom",
|
||||
Name = "自定义源",
|
||||
Url = "",
|
||||
Enabled = false
|
||||
});
|
||||
Save();
|
||||
Current.Sources.Insert(0, new ModelSource
|
||||
{
|
||||
Id = DefaultSourceId,
|
||||
Name = "Morris GC (GitCode)",
|
||||
Url = DefaultSourceUrl,
|
||||
Enabled = true,
|
||||
BuiltIn = true
|
||||
});
|
||||
Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 强制保证内置标记与地址,避免旧配置被用户改坏后失去保护
|
||||
existing.BuiltIn = true;
|
||||
if (string.IsNullOrWhiteSpace(existing.Url)) existing.Url = DefaultSourceUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
|
||||
@@ -32,6 +32,8 @@ public sealed class RepoPackage
|
||||
public string? Path { get; set; }
|
||||
public string? Sha256 { get; set; }
|
||||
public long Size { get; set; }
|
||||
/// <summary>Release 附件名(用于判断是 zip 还是单文件 exe / .app.zip)。</summary>
|
||||
public string? AssetName { get; set; }
|
||||
}
|
||||
|
||||
public sealed class RepoModel
|
||||
|
||||
@@ -314,24 +314,36 @@ public sealed class UpdateService
|
||||
Directory.CreateDirectory(_paths.UpdateRoot);
|
||||
var payload = Path.Combine(_paths.UpdateRoot, "payload");
|
||||
if (Directory.Exists(payload)) Directory.Delete(payload, true);
|
||||
var zip = Path.Combine(_paths.CacheRoot, "launcher-" + Safe(launcher.Version) + ".zip");
|
||||
await File.WriteAllBytesAsync(zip, bytes, ct);
|
||||
try
|
||||
Directory.CreateDirectory(payload);
|
||||
|
||||
// 单文件发布包(.exe / .app.zip 里的可执行文件不在此列)就是程序本体,不能解压。
|
||||
// 直接按附件原名放进 payload,脚本会把 payload/ 整体覆盖到安装目录。
|
||||
var assetName = package!.AssetName;
|
||||
bool singleFile = !string.IsNullOrWhiteSpace(assetName) &&
|
||||
!assetName!.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) &&
|
||||
!assetName.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase);
|
||||
string executableName;
|
||||
if (singleFile)
|
||||
{
|
||||
ZipSafety.ExtractToDirectory(zip, payload);
|
||||
executableName = Path.GetFileName(assetName!);
|
||||
await File.WriteAllBytesAsync(Path.Combine(payload, executableName), bytes, ct);
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
try { File.Delete(zip); } catch { }
|
||||
var zip = Path.Combine(_paths.CacheRoot, "launcher-" + Safe(launcher.Version) + ".zip");
|
||||
await File.WriteAllBytesAsync(zip, bytes, ct);
|
||||
try { ZipSafety.ExtractToDirectory(zip, payload); }
|
||||
finally { try { File.Delete(zip); } catch { } }
|
||||
FlattenPayload(payload);
|
||||
executableName = Path.GetFileName(Environment.ProcessPath ?? "");
|
||||
}
|
||||
FlattenPayload(payload);
|
||||
|
||||
Json.Write(Path.Combine(_paths.UpdateRoot, "pending.json"), new PendingUpdate
|
||||
{
|
||||
Version = launcher.Version,
|
||||
Rid = rid,
|
||||
InstallDirectory = _paths.InstallDirectory,
|
||||
Executable = Path.GetFileName(Environment.ProcessPath ?? ""),
|
||||
Executable = executableName,
|
||||
Payload = "payload",
|
||||
DownloadedAt = DateTime.UtcNow.ToString("O")
|
||||
});
|
||||
|
||||
@@ -246,4 +246,42 @@
|
||||
<Setter Property="FontSize" Value="12.5" />
|
||||
</Style>
|
||||
|
||||
<!-- 自建标题栏按钮 -->
|
||||
<Style Selector="Button.titlebtn">
|
||||
<Setter Property="Width" Value="38" />
|
||||
<Setter Property="Height" Value="30" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Foreground" Value="#A9B8D4" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
<Setter Property="CornerRadius" Value="7" />
|
||||
<Setter Property="Margin" Value="2,0" />
|
||||
<Setter Property="Transitions">
|
||||
<Transitions>
|
||||
<DoubleTransition Property="Opacity" Duration="0:0:0.12" />
|
||||
<BrushTransition Property="Background" Duration="0:0:0.12" />
|
||||
</Transitions>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style Selector="Button.titlebtn:pointerover">
|
||||
<Setter Property="Background" Value="#223252" />
|
||||
<Setter Property="Foreground" Value="#FFFFFF" />
|
||||
</Style>
|
||||
<Style Selector="Button.titlebtn.close:pointerover">
|
||||
<Setter Property="Background" Value="#D64545" />
|
||||
<Setter Property="Foreground" Value="#FFFFFF" />
|
||||
</Style>
|
||||
|
||||
<!-- 所有按钮按下时的缩放反馈(MENU 按钮同样生效) -->
|
||||
<Style Selector="Button">
|
||||
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
|
||||
</Style>
|
||||
<Style Selector="Button:pressed">
|
||||
<Setter Property="RenderTransform">
|
||||
<ScaleTransform ScaleX="0.94" ScaleY="0.94" />
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</Styles>
|
||||
@@ -93,6 +93,7 @@ public partial class DownloadViewModel : ObservableObject
|
||||
|
||||
internal void RemoveSource(SourceItemViewModel source)
|
||||
{
|
||||
if (source.Model.BuiltIn) return; // 内置默认源不允许删除
|
||||
_services.Settings.Current.Sources.Remove(source.Model);
|
||||
_services.Settings.Save();
|
||||
var wasSelected = SelectedSource == source;
|
||||
@@ -325,6 +326,8 @@ public partial class SourceItemViewModel : ObservableObject
|
||||
public string Name => string.IsNullOrWhiteSpace(Model.Name) ? Model.Id : Model.Name;
|
||||
public string HostText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.DisplayHost;
|
||||
public bool HasUrl => !string.IsNullOrWhiteSpace(Model.Url);
|
||||
/// <summary>内置默认源不可删除(下载页隐藏删除按钮)。</summary>
|
||||
public bool CanRemove => !Model.BuiltIn;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
|
||||
@@ -24,11 +24,12 @@ public partial class SettingsViewModel : ObservableObject
|
||||
|
||||
public ObservableCollection<SettingsSourceViewModel> Sources { get; } = new();
|
||||
public ObservableCollection<LanguageOption> Languages { get; } = new();
|
||||
public int[] FrameRates { get; } = { 24, 30, 60 };
|
||||
public int[] FrameRates { get; } = { 24, 30, 60, 90, 120 };
|
||||
|
||||
[ObservableProperty] private LanguageOption? _selectedLanguage;
|
||||
[ObservableProperty] private int _selectedFps = 30;
|
||||
[ObservableProperty] private int _selectedFps = 120;
|
||||
[ObservableProperty] private double _memoryValue = 2048;
|
||||
[ObservableProperty] private bool _memoryAuto = true;
|
||||
[ObservableProperty] private string _statusMessage = "";
|
||||
[ObservableProperty] private bool _autoUpdate = true;
|
||||
|
||||
@@ -46,7 +47,9 @@ public partial class SettingsViewModel : ObservableObject
|
||||
public string PendingText => string.IsNullOrWhiteSpace(_services.Settings.Current.PendingLauncherVersion)
|
||||
? L.I["update.none"] : _services.Settings.Current.PendingLauncherVersion!;
|
||||
|
||||
public string MemoryValueText => $"{(int)Math.Round(MemoryValue)} MB";
|
||||
public string MemoryValueText => MemoryAuto
|
||||
? $"{L.I["set.memory.auto"]} ({_services.Memory.BudgetMb} MB)"
|
||||
: $"{(int)Math.Round(MemoryValue)} MB";
|
||||
public string UsageText => _services.Memory.UsageText;
|
||||
public string ModelRoot => _services.Paths.ModelRoot;
|
||||
public string DataRoot => _services.Paths.DataRoot;
|
||||
@@ -69,6 +72,7 @@ public partial class SettingsViewModel : ObservableObject
|
||||
var settings = _services.Settings.Current;
|
||||
SelectedFps = settings.RenderFps;
|
||||
MemoryValue = settings.MemoryMb;
|
||||
MemoryAuto = settings.MemoryAuto;
|
||||
AutoUpdate = settings.AutoUpdateOnStartup;
|
||||
|
||||
Sources.Clear();
|
||||
@@ -133,6 +137,15 @@ public partial class SettingsViewModel : ObservableObject
|
||||
OnPropertyChanged(nameof(UsageText));
|
||||
}
|
||||
|
||||
partial void OnMemoryAutoChanged(bool value)
|
||||
{
|
||||
if (_loading) return;
|
||||
_services.Settings.Apply(s => s.MemoryAuto = value);
|
||||
_services.Memory.ApplyAuto(value, (int)Math.Round(MemoryValue));
|
||||
OnPropertyChanged(nameof(MemoryValueText));
|
||||
OnPropertyChanged(nameof(UsageText));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenModelFolder() => Shell.OpenFolder(_services.Paths.ModelRoot);
|
||||
|
||||
@@ -160,6 +173,7 @@ public partial class SettingsViewModel : ObservableObject
|
||||
|
||||
internal void RemoveSource(SettingsSourceViewModel source)
|
||||
{
|
||||
if (source.Model.BuiltIn) return; // 内置默认源不允许删除
|
||||
_services.Settings.Current.Sources.Remove(source.Model);
|
||||
_services.Settings.Save();
|
||||
Sources.Remove(source);
|
||||
@@ -184,6 +198,8 @@ public partial class SettingsSourceViewModel : ObservableObject
|
||||
|
||||
public string Name => string.IsNullOrWhiteSpace(Model.Name) ? Model.Id : Model.Name;
|
||||
public string UrlText => string.IsNullOrWhiteSpace(Model.Url) ? L.I["dl.noSource"] : Model.Url;
|
||||
/// <summary>内置默认源不可删除。</summary>
|
||||
public bool CanRemove => !Model.BuiltIn;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<TextBlock Text="{Binding HostText}" Classes="faint" TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
<Button Grid.Column="1" Classes="ghost small" Content="✕"
|
||||
Command="{Binding RemoveCommand}" VerticalAlignment="Center" />
|
||||
IsVisible="{Binding CanRemove}" Command="{Binding RemoveCommand}" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
@@ -6,9 +6,32 @@
|
||||
Width="1220" Height="800"
|
||||
MinWidth="1040" MinHeight="700"
|
||||
Background="{DynamicResource AppBg}"
|
||||
SystemDecorations="None"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Grid ColumnDefinitions="236,*" RowDefinitions="*,Auto">
|
||||
<!-- 禁用系统标题栏,改用自建标题栏(第 13/14 项) -->
|
||||
<Grid RowDefinitions="44,*">
|
||||
<!-- 自建标题栏 -->
|
||||
<Border x:Name="TitleBar" Grid.Row="0" Background="{DynamicResource SideBg}"
|
||||
PointerPressed="OnTitleBarPointerPressed">
|
||||
<Grid ColumnDefinitions="*,Auto,Auto" Margin="16,0,8,0">
|
||||
<StackPanel Orientation="Horizontal" Spacing="10" VerticalAlignment="Center">
|
||||
<Border Width="22" Height="22" CornerRadius="7" Background="#1C2C4C">
|
||||
<TextBlock Text="◎" FontSize="13" Foreground="#8FB6FF"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
<TextBlock Text="{loc:Loc app.name}" Foreground="#F2F6FF" FontSize="12.5"
|
||||
FontWeight="SemiBold" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<Button x:Name="MinimizeButton" Grid.Column="1" Classes="titlebtn"
|
||||
Content="—" Click="OnMinimizeClick" />
|
||||
<Button x:Name="CloseButton" Grid.Column="2" Classes="titlebtn close"
|
||||
Content="✕" Click="OnCloseClick" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 原内容整体下移一行 -->
|
||||
<Grid Grid.Row="1" ColumnDefinitions="236,*" RowDefinitions="*,Auto">
|
||||
|
||||
<!-- 侧栏 -->
|
||||
<Border Grid.Column="0" Grid.RowSpan="2" Background="{DynamicResource SideBg}">
|
||||
@@ -70,5 +93,6 @@
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -8,6 +8,7 @@ using Avalonia.Animation.Easings;
|
||||
using Avalonia.Threading;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using EarthModelStudio.Models;
|
||||
using EarthModelStudio.Services;
|
||||
@@ -144,6 +145,35 @@ public partial class MainWindow : Window
|
||||
window.Activate();
|
||||
}
|
||||
|
||||
// ---- 自建标题栏 ------------------------------------------------------
|
||||
private void OnTitleBarPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
|
||||
private void OnMinimizeClick(object? sender, global::Avalonia.Interactivity.RoutedEventArgs e)
|
||||
=> WindowState = WindowState.Minimized;
|
||||
|
||||
// 关闭动画:先淡出再真正 Close(第 4 项)
|
||||
private async void OnCloseClick(object? sender, global::Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (_isClosing) return;
|
||||
Opacity = 1;
|
||||
Transitions = new Transitions
|
||||
{
|
||||
new DoubleTransition
|
||||
{
|
||||
Property = OpacityProperty,
|
||||
Duration = TimeSpan.FromMilliseconds(180),
|
||||
Easing = new CubicEaseIn()
|
||||
}
|
||||
};
|
||||
Opacity = 0;
|
||||
await Task.Delay(190);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
_isClosing = true;
|
||||
|
||||
@@ -50,7 +50,10 @@
|
||||
Foreground="{DynamicResource Accent}" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
<TextBlock Classes="muted" Text="{loc:Loc set.memory.desc}" TextWrapping="Wrap" />
|
||||
<CheckBox Content="{loc:Loc set.memory.auto}" IsChecked="{Binding MemoryAuto}"
|
||||
Margin="0,2,0,0" />
|
||||
<Slider Minimum="512" Maximum="8192" TickFrequency="256" IsSnapToTickEnabled="False"
|
||||
IsEnabled="{Binding !MemoryAuto}"
|
||||
Value="{Binding MemoryValue}" Margin="0,4,0,0" />
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<TextBlock Classes="faint" Text="{loc:Loc set.memory.hint}" TextWrapping="Wrap" />
|
||||
@@ -75,7 +78,7 @@
|
||||
<TextBlock Text="{Binding UrlText}" Classes="faint" TextTrimming="CharacterEllipsis" MaxWidth="520" />
|
||||
</StackPanel>
|
||||
<Button Grid.Column="2" Classes="ghost small" Content="✕"
|
||||
Command="{Binding RemoveCommand}" VerticalAlignment="Center" />
|
||||
IsVisible="{Binding CanRemove}" Command="{Binding RemoveCommand}" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
@@ -143,14 +146,6 @@
|
||||
<TextBlock Classes="h3" Text="{loc:Loc set.version}" />
|
||||
<TextBlock Grid.Column="1" Classes="muted" Text="{Binding VersionText}" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="200,*">
|
||||
<TextBlock Classes="h3" Text="{loc:Loc set.platform}" />
|
||||
<TextBlock Grid.Column="1" Classes="muted" Text="{Binding PlatformText}" TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="200,*">
|
||||
<TextBlock Classes="h3" Text="{loc:Loc set.modelFormat}" />
|
||||
<TextBlock Grid.Column="1" Classes="muted" Text="{loc:Loc set.modelFormat.desc}" TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="200,*">
|
||||
<TextBlock Classes="h3" Text="{loc:Loc set.license}" />
|
||||
<TextBlock Grid.Column="1" Classes="muted" Text="{loc:Loc set.licenseValue}" />
|
||||
|
||||
Reference in new issue
Block a user