mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-10-31 18:23:59 +01:00
151 lines
3.8 KiB
TypeScript
151 lines
3.8 KiB
TypeScript
import { LuGlobe } from "react-icons/lu";
|
|
import { SiBrave, SiOpera, SiVivaldi } from "react-icons/si";
|
|
/**
|
|
* Browser utility functions
|
|
* Centralized helpers for browser name mapping, icons, etc.
|
|
*/
|
|
|
|
import {
|
|
FaAndroid,
|
|
FaApple,
|
|
FaChrome,
|
|
FaEdge,
|
|
FaExclamationTriangle,
|
|
FaFire,
|
|
FaFirefox,
|
|
FaLinux,
|
|
FaSafari,
|
|
FaWindows,
|
|
} from "react-icons/fa";
|
|
import { LuLock } from "react-icons/lu";
|
|
import { getCurrentOS } from "@/lib/platform";
|
|
|
|
export { getCurrentOS } from "@/lib/platform";
|
|
|
|
/**
|
|
* Map internal browser names to display names
|
|
*/
|
|
export function getBrowserDisplayName(browserType: string): string {
|
|
const browserNames: Record<string, string> = {
|
|
wayfern: "Wayfern",
|
|
};
|
|
|
|
return browserNames[browserType] || browserType;
|
|
}
|
|
|
|
/**
|
|
* Get the appropriate icon component for a browser type
|
|
* Anti-detect browsers get their base browser icons
|
|
* Other browsers get a warning icon to indicate they're not anti-detect
|
|
*/
|
|
export function getBrowserIcon(browserType: string) {
|
|
switch (browserType) {
|
|
case "wayfern":
|
|
return FaChrome;
|
|
default:
|
|
return FaExclamationTriangle;
|
|
}
|
|
}
|
|
|
|
/** Source browsers are identities, not warnings about the destination runtime. */
|
|
export function getSourceBrowserIcon(browserType: string) {
|
|
switch (browserType.toLowerCase()) {
|
|
case "chrome":
|
|
case "chrome-beta":
|
|
case "chrome-dev":
|
|
case "chrome-canary":
|
|
case "chromium":
|
|
case "wayfern":
|
|
return FaChrome;
|
|
case "edge":
|
|
case "msedge":
|
|
return FaEdge;
|
|
case "brave":
|
|
return SiBrave;
|
|
case "vivaldi":
|
|
return SiVivaldi;
|
|
case "opera":
|
|
case "opera-gx":
|
|
return SiOpera;
|
|
case "firefox":
|
|
return FaFirefox;
|
|
case "safari":
|
|
return FaSafari;
|
|
default:
|
|
return LuGlobe;
|
|
}
|
|
}
|
|
|
|
export function getProfileIcon(profile: {
|
|
browser: string;
|
|
ephemeral?: boolean;
|
|
password_protected?: boolean;
|
|
}) {
|
|
// `password_protected` and `ephemeral` are mutually exclusive (the backend
|
|
// rejects setting a password on an ephemeral profile), so the order here
|
|
// doesn't matter — checking lock first only matters if the invariant is
|
|
// ever violated, in which case showing the lock is the safer default.
|
|
if (profile.password_protected) return LuLock;
|
|
if (profile.ephemeral) return FaFire;
|
|
return getBrowserIcon(profile.browser);
|
|
}
|
|
|
|
/**
|
|
* The OS a fingerprint without an explicit `os` was generated for: the machine
|
|
* that created the profile. Mirrors `BrowserProfile::native_os`, without its
|
|
* fallback to this computer, so callers can tell "unknown" apart.
|
|
*/
|
|
export function getProfileNativeOs(profile: {
|
|
host_os?: string;
|
|
}): "macos" | "windows" | "linux" | undefined {
|
|
const os = profile.host_os;
|
|
return os === "macos" || os === "windows" || os === "linux" ? os : undefined;
|
|
}
|
|
|
|
/**
|
|
* Whether a profile cannot run on this computer because a browser bound to
|
|
* its OS created it elsewhere. Mirrors `BrowserProfile::is_cross_os`: a
|
|
* Wayfern profile runs on every OS, so it is never cross-OS.
|
|
*/
|
|
export function isCrossOsProfile(profile: {
|
|
browser: string;
|
|
host_os?: string;
|
|
wayfern_config?: { os?: string };
|
|
}): boolean {
|
|
if (profile.browser === "wayfern") return false;
|
|
const profileOs = profile.host_os || profile.wayfern_config?.os;
|
|
if (!profileOs) return false;
|
|
return profileOs !== getCurrentOS();
|
|
}
|
|
|
|
export function getOSDisplayName(os: string): string {
|
|
switch (os) {
|
|
case "macos":
|
|
return "macOS";
|
|
case "windows":
|
|
return "Windows";
|
|
case "linux":
|
|
return "Linux";
|
|
case "android":
|
|
return "Android";
|
|
case "ios":
|
|
return "iOS";
|
|
default:
|
|
return os;
|
|
}
|
|
}
|
|
|
|
export function getOSIcon(os: string) {
|
|
switch (os) {
|
|
case "macos":
|
|
case "ios":
|
|
return FaApple;
|
|
case "windows":
|
|
return FaWindows;
|
|
case "android":
|
|
return FaAndroid;
|
|
default:
|
|
return FaLinux;
|
|
}
|
|
}
|