Skip to content

Commit f3d3fd2

Browse files
RBridCopilot
andcommitted
feat(tray): consolidate app version + add user feedback to Check for Updates
Introduces OpenClaw.Shared.AppVersionInfo as the single source of truth for the app version (resolved at runtime from the tray assembly), and replaces ~9 duplicated version lookups across the UI. Rewrites the update-check flow as a two-stage pipeline (metadata gate + install flag) with bounded waits, fresh UpdateInfo writes, and catches for COM/Cancel/InvalidOperation exceptions. Adds a ContentDialog so 'Check for Updates' gives visible feedback when the app is current, when a check fails, or (DEBUG) when skipped. Adds 7 localized Update_* keys across en-us/fr-fr/nl-nl/zh-cn/zh-tw, with a LatinScriptInvariantResourceKeys allow-list so fr/nl keep 'OK' verbatim. Bumps version to 0.4.7. Co-authored-by: Copilot <[email protected]>
1 parent 45dccec commit f3d3fd2

18 files changed

Lines changed: 750 additions & 68 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,19 @@ jobs:
281281
- name: Patch MSIX manifest metadata
282282
shell: pwsh
283283
run: |
284-
$version = "${{ needs.test.outputs.majorMinorPatch }}.0"
284+
# NOTE: Identity/Version is auto-synced from /p:Version by the SyncAppxManifestVersion
285+
# target in OpenClaw.Tray.WinUI.csproj during the MSIX build below; we only patch the
286+
# alpha/non-alpha identity and display name here.
285287
$isAlpha = "${{ startsWith(github.ref, 'refs/tags/v') && contains(github.ref_name, '-') }}" -eq "true"
286288
$identityName = if ($isAlpha) { "OpenClaw.Companion.Alpha" } else { "OpenClaw.Companion" }
287289
$displayName = if ($isAlpha) { "OpenClaw Companion Alpha" } else { "OpenClaw Companion" }
288290
$manifest = "src/OpenClaw.Tray.WinUI/Package.appxmanifest"
289291
[xml]$xml = Get-Content $manifest
290292
$xml.Package.Identity.Name = $identityName
291-
$xml.Package.Identity.Version = $version
292293
$xml.Package.Properties.DisplayName = $displayName
293294
$xml.Package.Applications.Application.VisualElements.DisplayName = $displayName
294295
$xml.Save((Resolve-Path $manifest))
295-
Write-Host "Patched MSIX manifest to identity $identityName, display name '$displayName', version $version"
296+
Write-Host "Patched MSIX manifest to identity $identityName, display name '$displayName' (Version will be synced from /p:Version by msbuild target)"
296297
297298
- name: Build MSIX Package
298299
run: >

‎docs/VERSIONING.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ By removing the hardcoded `FileVersion` and `AssemblyVersion` properties, they n
7070
2. **Let GitVersion and CI control the version** - the csproj's `<Version>` is just a fallback for local development builds
7171
3. **Test version detection** - after building, check the EXE properties to ensure FileVersion matches expectations
7272
4. **Use semantic versioning** - tags should follow `v{major}.{minor}.{patch}` format (e.g., `v0.4.0`)
73+
5. **Use `OpenClaw.Shared.AppVersionInfo` for any user-visible or wire-exposed version string** - never re-roll
74+
`typeof(...).Assembly.GetName().Version` or hardcode literals like `"v0.1.0"`. `AppVersionInfo` is the single
75+
source of truth driven by `<Version>`, used by the About page, Update dialog, support-context dump,
76+
`device.info` capability, MCP `serverVersion` handshake, and the update-check diagnostics.
77+
78+
## Runtime Version Resolution (AppVersionInfo)
79+
80+
`src/OpenClaw.Shared/AppVersionInfo.cs` exposes:
81+
82+
- `AppVersionInfo.Version` → bare string, e.g. `"0.4.7"`
83+
- `AppVersionInfo.DisplayVersion` → `"v"` prefix, e.g. `"v0.4.7"`
84+
85+
It resolves the version by:
86+
87+
1. Looking for the `OpenClaw.Tray.WinUI` assembly in the current `AppDomain` (so `dotnet test` and CLI siblings
88+
still report the tray's version rather than the testhost / dotnet host).
89+
2. Falling back to `Assembly.GetEntryAssembly()`, then to the Shared assembly.
90+
3. Reading `AssemblyInformationalVersionAttribute` (preferred) or `AssemblyVersion`.
91+
4. Stripping SourceLink build metadata (`+abc123`) **and** the SemVer pre-release suffix (`-beta.1`) so the
92+
displayed value matches what Updatum compares (Updatum reads the numeric `AssemblyVersion` only).
93+
94+
For tests that need a deterministic value regardless of host process, set the `internal` test hook:
95+
96+
```csharp
97+
AppVersionInfo.TestOverride = "9.9.9";
98+
```
7399

74100
## References
75101

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using System.Reflection;
3+
4+
namespace OpenClaw.Shared;
5+
6+
/// <summary>
7+
/// Single source of truth for the OpenClaw Companion app version that is
8+
/// surfaced to users. Reads <see cref="AssemblyInformationalVersionAttribute"/>
9+
/// (or falls back to <c>AssemblyVersion</c>) from the tray executable so every
10+
/// UI/diagnostic/handshake site reports the same number driven by the csproj
11+
/// <c>&lt;Version&gt;</c> property.
12+
/// </summary>
13+
/// <remarks>
14+
/// Under <c>dotnet test</c> and inside CLI siblings, <see cref="Assembly.GetEntryAssembly"/>
15+
/// is the host process (testhost / dotnet), not the tray exe — so we first
16+
/// search the current <see cref="AppDomain"/> for the tray assembly by name.
17+
/// Tests that need a deterministic value can set <see cref="TestOverride"/>.
18+
/// </remarks>
19+
public static class AppVersionInfo
20+
{
21+
private const string TrayAssemblyName = "OpenClaw.Tray.WinUI";
22+
23+
private static readonly string _version = ResolveVersion();
24+
25+
/// <summary>
26+
/// Test-only override. When non-null, <see cref="Version"/> returns this
27+
/// value instead of the reflected one, giving tests a deterministic
28+
/// version string regardless of the host process.
29+
/// </summary>
30+
internal static string? TestOverride { get; set; }
31+
32+
/// <summary>Bare version string, e.g. <c>"0.4.7"</c>.</summary>
33+
public static string Version => TestOverride ?? _version;
34+
35+
/// <summary>Version prefixed with <c>v</c>, e.g. <c>"v0.4.7"</c>.</summary>
36+
public static string DisplayVersion => "v" + Version;
37+
38+
private static string ResolveVersion()
39+
{
40+
try
41+
{
42+
var assembly = FindTrayAssembly()
43+
?? Assembly.GetEntryAssembly()
44+
?? typeof(AppVersionInfo).Assembly;
45+
46+
var informational = assembly
47+
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
48+
?.InformationalVersion;
49+
if (!string.IsNullOrWhiteSpace(informational))
50+
{
51+
return NormalizeSemVer(informational);
52+
}
53+
54+
var name = assembly.GetName().Version;
55+
if (name != null)
56+
{
57+
// System.Version uses -1 for unspecified components; coerce to 0.
58+
var build = Math.Max(0, name.Build);
59+
var revision = Math.Max(0, name.Revision);
60+
return revision == 0
61+
? $"{name.Major}.{name.Minor}.{build}"
62+
: $"{name.Major}.{name.Minor}.{build}.{revision}";
63+
}
64+
65+
return "0.0.0";
66+
}
67+
catch
68+
{
69+
// Never let the type initializer fail — a TypeInitializationException
70+
// would poison every future access from every caller.
71+
return "0.0.0";
72+
}
73+
}
74+
75+
private static Assembly? FindTrayAssembly()
76+
{
77+
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
78+
{
79+
if (string.Equals(asm.GetName().Name, TrayAssemblyName, StringComparison.Ordinal))
80+
return asm;
81+
}
82+
return null;
83+
}
84+
85+
private static string NormalizeSemVer(string s)
86+
{
87+
// Strip SourceLink build metadata, e.g. "0.4.7+abc123" -> "0.4.7".
88+
var plus = s.IndexOf('+');
89+
if (plus >= 0) s = s.Substring(0, plus);
90+
91+
// Strip the SemVer pre-release suffix, e.g. "0.4.7-beta.1" -> "0.4.7".
92+
// This keeps the UI string aligned with Updatum, which compares the
93+
// numeric AssemblyVersion only. Revisit if pre-release labels should
94+
// ever be surfaced to users.
95+
var dash = s.IndexOf('-');
96+
if (dash >= 0) s = s.Substring(0, dash);
97+
98+
return s;
99+
}
100+
}
101+

‎src/OpenClaw.Shared/Capabilities/DeviceCapability.cs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Linq;
66
using System.Net.NetworkInformation;
7-
using System.Reflection;
87
using System.Runtime.InteropServices;
98
using System.Threading.Tasks;
109

@@ -53,10 +52,7 @@ private NodeInvokeResponse HandleInfo()
5352
{
5453
Logger.Info("device.info");
5554

56-
var assembly = typeof(DeviceCapability).Assembly;
57-
var version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
58-
?? assembly.GetName().Version?.ToString()
59-
?? "unknown";
55+
var version = AppVersionInfo.Version;
6056

6157
return Success(new
6258
{
@@ -65,7 +61,7 @@ private NodeInvokeResponse HandleInfo()
6561
systemName = OperatingSystem.IsWindows() ? "Windows" : RuntimeInformation.OSDescription,
6662
systemVersion = RuntimeInformation.OSDescription,
6763
appVersion = version,
68-
appBuild = assembly.GetName().Version?.ToString() ?? version,
64+
appBuild = version,
6965
locale = CultureInfo.CurrentCulture.Name
7066
});
7167
}

0 commit comments

Comments
 (0)