add os detection

This commit is contained in:
Eduard Gert
2026-05-29 14:04:45 +02:00
parent 16570b3223
commit 1985caf993
4 changed files with 56 additions and 5 deletions
+8 -3
View File
@@ -13,16 +13,21 @@ import "react-loading-skeleton/dist/skeleton.css";
import { welcome } from "@/lib/welcome";
import LoginWaitingForBrowserDialog from "@/modules/login/LoginWaitingForBrowserDialog.tsx";
import { initI18n } from "@/lib/i18n";
import { initPlatform } from "@/lib/platform";
welcome();
initI18n()
.catch((e) => {
Promise.all([
initI18n().catch((e) => {
// Surface init failures in the console so a misconfigured glob
// doesn't quietly blank the UI; render anyway with i18next in
// whatever state it ended up in (t() will fall back to keys).
console.error("i18n init failed:", e);
})
}),
initPlatform().catch((e) => {
console.error("platform init failed:", e);
}),
])
.finally(() => {
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
+44
View File
@@ -0,0 +1,44 @@
import { System } from "@wailsio/runtime";
export type Platform = {
isWindows11: boolean;
isMacOS: boolean;
isOtherOS: boolean;
};
let cached: Platform | null = null;
// Windows 11 is Windows NT 10.0 with build number >= 22000.
function parseWindows11(version: string): boolean {
const match = version.match(/(\d+)\.(\d+)\.(\d+)/);
if (!match) return false;
return parseInt(match[3], 10) >= 22000;
}
export async function initPlatform(): Promise<void> {
if (cached) return;
const isMacOS = System.IsMac();
const isWindows = System.IsWindows();
let isWindows11 = false;
if (isWindows) {
const env = await System.Environment();
isWindows11 = parseWindows11(env.OSInfo?.Version ?? "");
}
cached = {
isWindows11,
isMacOS,
isOtherOS: !isMacOS && !isWindows11,
};
}
function get(): Platform {
if (!cached) {
throw new Error("platform: initPlatform() must complete before sync getters are used");
}
return cached;
}
export const getPlatform = (): Platform => get();
export const isWindows11 = (): boolean => get().isWindows11;
export const isMacOS = (): boolean => get().isMacOS;
export const isOtherOS = (): boolean => get().isOtherOS;