Files
cline-multi-mirror/webview-ui/src/utils/platformUtils.ts
T
Bee 1b7f971c34 refactor: banner system with data-driven architecture [ENG-1426] (#8140)
* refactor: banner system with data-driven architecture

Add new banner data structures and types to support a flexible, backend-driven
banner system. This enables dynamic banner management while maintaining
consistent UI rendering.

Changes:
- Add BannerCardData interface for banner configuration with support for icons,
  severity levels, actions, and platform/user filtering
- Add BannerActionType enum defining action handlers (link, settings, CLI
  install, model selection)
- Add BannerAction interface for button/link definitions
- Refactor banner rendering logic to use data-driven approach instead of
  hardcoded implementations
- Update BannerCarousel component to handle new action types dynamically

This allows the backend to construct banner JSON that the frontend renders
consistently through the BannerCarousel component when ready.

* apply feedback

* update e2e test

* Add BackendBanner struct with converter

* clean up types

* clean up
2025-12-19 12:58:36 -08:00

67 lines
1.5 KiB
TypeScript

export interface NavigatorUAData {
platform: string
brands: { brand: string; version: string }[]
}
export const unknown = "Unknown"
const platforms = {
windows: /win32/,
mac: /darwin/,
linux: /linux/,
}
export const detectOS = (platform: string) => {
let detectedOs = unknown
if (platform.match(platforms.windows)) {
detectedOs = "windows"
} else if (platform.match(platforms.mac)) {
detectedOs = "mac"
} else if (platform.match(platforms.linux)) {
detectedOs = "linux"
}
return detectedOs
}
export const detectMetaKeyChar = (platform: string) => {
if (platform.match(platforms.mac)) {
return "CMD"
} else if (platform.match(platforms.windows)) {
return "Win"
} else if (platform.match(platforms.linux)) {
return "Alt"
} else {
return "CMD"
}
}
const userAgent = navigator?.userAgent || ""
export const isChrome = userAgent.indexOf("Chrome") >= 0
export const isSafari = !isChrome && userAgent.indexOf("Safari") >= 0
/**
* Gets the current platform: 'windows', 'mac', or 'linux'
* Defaults to 'linux' if platform cannot be determined
*/
export function getCurrentPlatform() {
// Fallback to linux if platform is not available
switch (process?.platform) {
case "win32":
return "windows"
case "darwin":
return "mac"
default:
return "linux"
}
}
/**
* Checks if the platform is macOS or Linux
* @returns true if platform is darwin (macOS) or linux
*/
export const isMacOSOrLinux = (): boolean => {
return getCurrentPlatform() !== "windows" // Non-Windows
}