Files
Reims-Go/frontend/src/macos/macosRelease.ts
T

38 lines
1.1 KiB
TypeScript

// Which macOS major version a VM runs, for its icon. The release comes from
// GetVMMacOS (.reims-go-macos, written at creation: "26.7.3" or "tahoe");
// VMs without one are guessed from their name or display name.
const CODENAMES: [string, number][] = [
['tahoe', 26],
['sequoia', 15],
['sonoma', 14],
['ventura', 13],
['monterey', 12],
['bigsur', 11],
['big sur', 11],
['big-sur', 11],
]
function fromText(text: string): number | null {
const s = text.trim().toLowerCase()
if (!s) return null
const ver = /^(\d{2})(?:\.\d+)*$/.exec(s)
if (ver) return Number(ver[1])
for (const [name, major] of CODENAMES) if (s.includes(name)) return major
const tagged = /macos[\s_-]*(\d{2})(?!\d)/.exec(s)
if (tagged) {
const n = Number(tagged[1])
if (n >= 10 && n <= 60) return n
}
return null
}
/** The major version (26, 15, …) from the recorded release, else from the hints. */
export function macOSMajor(release: string | undefined, ...hints: (string | undefined)[]): number | null {
for (const text of [release, ...hints]) {
const n = text ? fromText(text) : null
if (n !== null) return n
}
return null
}