mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-02 02:34:42 +08:00
fix(support-info): show Windows marketing name in support info
This commit is contained in:
@@ -32,10 +32,33 @@ export function formatSupportInfoRuntime(runtime: AppSupportInfo["runtime"], lab
|
||||
return labels.unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a Windows NT kernel version (`major.minor.build[.ubr]`) to its marketing name.
|
||||
*
|
||||
* Windows 11 still reports kernel `10.0.x`; the build number is what distinguishes it
|
||||
* (build >= 22000 is Windows 11). Returns null for non-`10.0` versions (e.g. legacy 6.x)
|
||||
* so callers keep the raw string instead of guessing.
|
||||
*/
|
||||
export function windowsMarketingName(version: string | null | undefined): string | null {
|
||||
const trimmed = version?.trim();
|
||||
if (!trimmed) return null;
|
||||
const parts = trimmed.split(".");
|
||||
if (parts.length < 3) return null;
|
||||
const major = Number(parts[0]);
|
||||
const build = Number(parts[2]);
|
||||
if (!Number.isInteger(major) || !Number.isInteger(build)) return null;
|
||||
if (major !== 10) return null;
|
||||
return build >= 22000 ? "Windows 11" : "Windows 10";
|
||||
}
|
||||
|
||||
export function formatSupportInfoOperatingSystem(info: AppSupportInfo, unknownLabel: string): string {
|
||||
const name = info.osName?.trim();
|
||||
const version = info.osVersion?.trim();
|
||||
if (!name && !version) return unknownLabel;
|
||||
if (name?.toLowerCase() === "windows") {
|
||||
const marketing = windowsMarketingName(version);
|
||||
if (marketing) return version ? `${marketing} (${version})` : marketing;
|
||||
}
|
||||
return [name, version].filter(Boolean).join(" ");
|
||||
}
|
||||
|
||||
|
||||
+32
-1
@@ -1,6 +1,6 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import { test } from "vitest";
|
||||
import { buildAppSupportInfoRows, formatAppSupportInfoForClipboard, normalizeSupportInfoVersion } from "../../apps/desktop/src/lib/app/supportInfo.ts";
|
||||
import { buildAppSupportInfoRows, formatAppSupportInfoForClipboard, formatSupportInfoOperatingSystem, normalizeSupportInfoVersion, windowsMarketingName } from "../../apps/desktop/src/lib/app/supportInfo.ts";
|
||||
import type { AppSupportInfoLabels } from "../../apps/desktop/src/lib/app/supportInfo.ts";
|
||||
import type { AppSupportInfo } from "../../apps/desktop/src/lib/backend/tauri.ts";
|
||||
|
||||
@@ -49,3 +49,34 @@ test("formats support info clipboard text in stable issue-friendly order", () =>
|
||||
["DBX Version: v0.5.50", "Runtime: Desktop", "Operating System: macOS 15.5", "Architecture: aarch64"].join("\n"),
|
||||
);
|
||||
});
|
||||
|
||||
test("maps Windows kernel build to its marketing name", () => {
|
||||
assert.equal(windowsMarketingName("10.0.26200.9457"), "Windows 11");
|
||||
assert.equal(windowsMarketingName("10.0.22000.1"), "Windows 11");
|
||||
assert.equal(windowsMarketingName("10.0.19045.5011"), "Windows 10");
|
||||
assert.equal(windowsMarketingName("6.1.7601"), null);
|
||||
assert.equal(windowsMarketingName(""), null);
|
||||
assert.equal(windowsMarketingName("10.0"), null);
|
||||
});
|
||||
|
||||
test("shows Windows marketing name while keeping the raw build for diagnostics", () => {
|
||||
assert.equal(
|
||||
formatSupportInfoOperatingSystem({ appVersion: "0.6.22", runtime: "desktop", osName: "Windows", osVersion: "10.0.26200.9457", arch: "x86_64" }, labels.unknown),
|
||||
"Windows 11 (10.0.26200.9457)",
|
||||
);
|
||||
assert.equal(
|
||||
formatSupportInfoOperatingSystem({ appVersion: "0.6.22", runtime: "desktop", osName: "Windows", osVersion: "10.0.19045.5011", arch: "x64" }, labels.unknown),
|
||||
"Windows 10 (10.0.19045.5011)",
|
||||
);
|
||||
});
|
||||
|
||||
test("leaves non-10.0 Windows and other platforms unchanged", () => {
|
||||
assert.equal(
|
||||
formatSupportInfoOperatingSystem({ appVersion: "x", runtime: "desktop", osName: "Windows", osVersion: "6.1.7601", arch: "x86" }, labels.unknown),
|
||||
"Windows 6.1.7601",
|
||||
);
|
||||
assert.equal(
|
||||
formatSupportInfoOperatingSystem({ appVersion: "x", runtime: "desktop", osName: "macOS", osVersion: "15.5", arch: "aarch64" }, labels.unknown),
|
||||
"macOS 15.5",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user