Enriquece inventário do Windows e layout dos cards
This commit is contained in:
parent
26ae2aa8e5
commit
11390a9d83
2 changed files with 56 additions and 27 deletions
|
|
@ -202,6 +202,14 @@ function readNumber(record: Record<string, unknown>, ...keys: string[]): number
|
|||
return undefined
|
||||
}
|
||||
|
||||
function readText(record: Record<string, unknown>, ...keys: string[]): string | undefined {
|
||||
const stringValue = readString(record, ...keys)
|
||||
if (stringValue) return stringValue
|
||||
const numberValue = readNumber(record, ...keys)
|
||||
if (typeof numberValue === "number") return String(numberValue)
|
||||
return undefined
|
||||
}
|
||||
|
||||
function parseWindowsInstallDate(value: unknown): Date | null {
|
||||
if (!value) return null
|
||||
if (value instanceof Date) return value
|
||||
|
|
@ -265,6 +273,7 @@ type WindowsOsInfo = {
|
|||
editionId?: string
|
||||
displayVersion?: string
|
||||
releaseId?: string
|
||||
version?: string
|
||||
currentBuild?: string
|
||||
currentBuildNumber?: string
|
||||
licenseStatus?: number
|
||||
|
|
@ -278,26 +287,32 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null {
|
|||
const parseRecord = (value: Record<string, unknown>) => {
|
||||
const read = (k: string, ...alts: string[]) => readString(value, k, ...alts)
|
||||
const readNum = (...keys: string[]) => readNumber(value, ...keys)
|
||||
const readFlexible = (...keys: string[]) => readText(value, ...keys)
|
||||
|
||||
const family = read("Family")
|
||||
const edition = read("Edition")
|
||||
|
||||
const productName =
|
||||
read("ProductName", "productName", "Name", "name") ??
|
||||
(read("Family") && read("Edition") ? `${read("Family")} ${read("Edition")}` : undefined)
|
||||
readFlexible("ProductName", "productName", "Name", "name", "Caption", "caption") ??
|
||||
(family && edition ? `${family} ${edition}` : family ?? edition ?? undefined)
|
||||
|
||||
const editionId =
|
||||
read("EditionID", "editionId", "Edition", "edition", "SkuEdition", "skuEdition") ?? undefined
|
||||
readFlexible("EditionID", "editionId", "Edition", "edition", "SkuEdition", "skuEdition", "CompositionEditionID", "compositionEditionId") ??
|
||||
undefined
|
||||
|
||||
const displayVersion =
|
||||
read("DisplayVersion", "displayVersion", "Version", "version") ??
|
||||
read("ReleaseId", "releaseId")
|
||||
const displayVersion = readFlexible("DisplayVersion", "displayVersion")
|
||||
const versionValue =
|
||||
readFlexible("Version", "version", "ReleaseId", "releaseId") ?? displayVersion
|
||||
|
||||
const baseBuild =
|
||||
read("CurrentBuildNumber", "currentBuildNumber", "CurrentBuild", "currentBuild", "OSBuild", "osBuild") ??
|
||||
readFlexible("CurrentBuildNumber", "currentBuildNumber", "CurrentBuild", "currentBuild", "OSBuild", "osBuild", "BuildNumber", "buildNumber") ??
|
||||
undefined
|
||||
const ubr = read("UBR") ?? (readNum("UBR") ? String(readNum("UBR")) : undefined)
|
||||
const currentBuildNumber = baseBuild ? (ubr && /^\d+$/.test(ubr) ? `${baseBuild}.${ubr}` : baseBuild) : undefined
|
||||
const ubrRaw = readFlexible("UBR")
|
||||
const licenseStatus = readNum("LicenseStatus", "licenseStatus")
|
||||
const currentBuildNumber =
|
||||
baseBuild && ubrRaw && /^\d+$/.test(ubrRaw) ? `${baseBuild}.${ubrRaw}` : baseBuild ?? readFlexible("BuildNumber", "buildNumber")
|
||||
const currentBuild = baseBuild
|
||||
|
||||
const licenseStatus = readNum("LicenseStatus", "licenseStatus")
|
||||
const isActivatedRaw = value["IsActivated"] ?? value["isActivated"]
|
||||
const isActivated =
|
||||
typeof isActivatedRaw === "boolean"
|
||||
|
|
@ -313,13 +328,14 @@ function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null {
|
|||
parseWindowsInstallDate(value["InstalledOn"])
|
||||
|
||||
const experience =
|
||||
read("Experience", "experience", "FeatureExperiencePack", "featureExperiencePack") ??
|
||||
readFlexible("Experience", "experience", "FeatureExperiencePack", "featureExperiencePack") ??
|
||||
(currentBuildNumber ? `OS Build ${currentBuildNumber}` : undefined)
|
||||
|
||||
return {
|
||||
productName,
|
||||
editionId,
|
||||
displayVersion,
|
||||
version: versionValue,
|
||||
releaseId: read("ReleaseId", "releaseId"),
|
||||
currentBuild,
|
||||
currentBuildNumber,
|
||||
|
|
@ -845,7 +861,7 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
return []
|
||||
}, [windowsSoftwareRaw])
|
||||
const windowsEditionLabel = windowsOsInfo?.productName ?? windowsOsInfo?.editionId ?? null
|
||||
const windowsVersionLabel = windowsOsInfo?.displayVersion ?? windowsOsInfo?.releaseId ?? null
|
||||
const windowsVersionLabel = windowsOsInfo?.displayVersion ?? windowsOsInfo?.version ?? windowsOsInfo?.releaseId ?? null
|
||||
const windowsBuildLabel = windowsOsInfo?.currentBuildNumber ?? windowsOsInfo?.currentBuild ?? null
|
||||
const windowsInstallDateLabel = windowsOsInfo?.installDate ? formatAbsoluteDateTime(windowsOsInfo.installDate) : null
|
||||
const windowsExperienceLabel = windowsOsInfo?.experience ?? null
|
||||
|
|
@ -1487,12 +1503,12 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
<Card className="border-slate-200">
|
||||
<CardContent className="flex items-center gap-3 py-3">
|
||||
<Terminal className="size-5 text-slate-500" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-xs text-muted-foreground">Windows</p>
|
||||
<p className="truncate text-sm font-semibold text-foreground">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<p className="text-xs text-muted-foreground">Windows</p>
|
||||
<p className="break-words text-sm font-semibold text-foreground">
|
||||
{windowsEditionLabel ?? machine?.osName ?? "—"}
|
||||
</p>
|
||||
<p className="truncate text-xs text-muted-foreground">
|
||||
<p className="break-words text-xs text-muted-foreground">
|
||||
{windowsVersionLabel ?? windowsBuildLabel ?? "Versão desconhecida"}
|
||||
</p>
|
||||
</div>
|
||||
|
|
@ -1501,9 +1517,11 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
|
|||
<Card className="border-slate-200">
|
||||
<CardContent className="flex items-center gap-3 py-3">
|
||||
<Monitor className="size-5 text-slate-500" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-xs text-muted-foreground">GPU</p>
|
||||
<p className="truncate text-sm font-semibold text-foreground">{(windowsPrimaryGpu ?? primaryGpu)?.name ?? "—"}</p>
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<p className="text-xs text-muted-foreground">GPU</p>
|
||||
<p className="break-words text-sm font-semibold text-foreground">
|
||||
{(windowsPrimaryGpu ?? primaryGpu)?.name ?? "—"}
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue