mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-22 14:49:10 +02:00
add os detection
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user