Normalize Windows edition and install date parsing
This commit is contained in:
parent
694bda22cd
commit
6a8f7a63aa
1 changed files with 42 additions and 11 deletions
|
|
@ -273,8 +273,14 @@ function parseWindowsInstallDate(value: unknown): Date | null {
|
|||
if (!value) return null
|
||||
if (value instanceof Date) return value
|
||||
if (typeof value === "number" && Number.isFinite(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()
|
||||
if (!trimmed) return null
|
||||
|
|
@ -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,14 +1483,17 @@ 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 (baseLower.startsWith("windows") && editionLower.startsWith("windows")) {
|
||||
return edition
|
||||
}
|
||||
if (base) {
|
||||
return `${base} ${edition}`.replace(/\s+/g, " ").trim()
|
||||
}
|
||||
return edition
|
||||
}
|
||||
return base ?? ""
|
||||
}, [machine?.osName, windowsEditionLabel])
|
||||
const linuxLsblk = linuxExt?.lsblk ?? []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue