diff --git a/src/components/admin/machines/admin-machines-overview.tsx b/src/components/admin/machines/admin-machines-overview.tsx index 93e2a0b..5ece2a7 100644 --- a/src/components/admin/machines/admin-machines-overview.tsx +++ b/src/components/admin/machines/admin-machines-overview.tsx @@ -273,7 +273,13 @@ function parseWindowsInstallDate(value: unknown): Date | null { if (!value) return null if (value instanceof Date) return value if (typeof value === "number" && Number.isFinite(value)) { - return new Date(value) + if (value > 10_000_000_000) { + return new Date(value) + } + if (value > 1_000_000_000) { + return new Date(value * 1000) + } + return new Date(value * 1000) } if (typeof value !== "string") return null const trimmed = value.trim() @@ -329,6 +335,7 @@ function parseWindowsInstallDate(value: unknown): Date | null { type WindowsOsInfo = { productName?: string + caption?: string editionId?: string displayVersion?: string releaseId?: string @@ -355,10 +362,15 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null { const family = read("Family") const edition = read("Edition") + const captionRaw = readFlexible("Caption", "caption") + const captionNormalized = captionRaw ? captionRaw.replace(/^Microsoft\s+/i, "").trim() : undefined - const productName = - readFlexible("ProductName", "productName", "Name", "name", "Caption", "caption") ?? + let productName = + readFlexible("ProductName", "productName", "Name", "name") ?? (family && edition ? `${family} ${edition}` : family ?? edition ?? undefined) + if (captionNormalized && /windows/i.test(captionNormalized)) { + productName = captionNormalized + } const editionId = readFlexible("EditionID", "editionId", "Edition", "edition", "SkuEdition", "skuEdition", "CompositionEditionID", "compositionEditionId") ?? @@ -409,9 +421,16 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null { parseWindowsInstallDate(value["InstallDateTime"]) ?? parseWindowsInstallDate(value["InstalledOn"]) - const experience = - readFlexible("Experience", "experience", "FeatureExperiencePack", "featureExperiencePack") ?? - (currentBuildNumber ? `OS Build ${currentBuildNumber}` : undefined) + const experience = (() => { + const exp = readFlexible("Experience", "experience") + if (exp) return exp + const pack = readFlexible("FeatureExperiencePack", "featureExperiencePack") + if (pack) { + const trimmed = pack.trim() + if (trimmed) return `Pacote de experiência ${trimmed}` + } + return currentBuildNumber ? `OS Build ${currentBuildNumber}` : undefined + })() const productId = readFlexible("ProductID", "productID", "ProductId", "productId", "ProductKeyId", "productKeyId") const partialProductKey = readFlexible("PartialProductKey", "partialProductKey") @@ -435,6 +454,7 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null { registeredOwner, installDate, experience, + caption: captionNormalized ?? captionRaw ?? undefined, } } @@ -1209,7 +1229,15 @@ export function MachineDetails({ machine }: MachineDetailsProps) { return a.name.localeCompare(b.name, "pt-BR") }) }, [windowsSoftware]) - const windowsEditionLabel = windowsOsInfo?.productName ?? windowsOsInfo?.editionId ?? null + const windowsEditionLabel = useMemo(() => { + const raw = + windowsOsInfo?.productName ?? + windowsOsInfo?.caption ?? + windowsOsInfo?.editionId ?? + null + if (!raw) return null + return raw.replace(/^Microsoft\s+/i, "").trim() + }, [windowsOsInfo?.productName, windowsOsInfo?.caption, windowsOsInfo?.editionId]) const windowsVersionLabel = windowsOsInfo?.displayVersion ?? windowsOsInfo?.version ?? windowsOsInfo?.releaseId ?? null const windowsBuildLabel = windowsOsInfo?.currentBuildNumber ?? windowsOsInfo?.currentBuild ?? null const windowsInstallDateLabel = windowsOsInfo?.installDate ? formatAbsoluteDateTime(windowsOsInfo.installDate) : null @@ -1455,13 +1483,16 @@ export function MachineDetails({ machine }: MachineDetailsProps) { const base = machine?.osName?.trim() const edition = windowsEditionLabel?.trim() if (edition) { - if (base && edition.toLowerCase().includes(base.toLowerCase())) { + if (!base) return edition + const baseLower = base.toLowerCase() + const editionLower = edition.toLowerCase() + if (editionLower.includes(baseLower) || baseLower.includes(editionLower)) { return edition } - if (base) { - return `${base} ${edition}`.replace(/\s+/g, " ").trim() + if (baseLower.startsWith("windows") && editionLower.startsWith("windows")) { + return edition } - return edition + return `${base} ${edition}`.replace(/\s+/g, " ").trim() } return base ?? "" }, [machine?.osName, windowsEditionLabel])