From 1eb20edda71d19f5a23434602a1c3f0d043135a2 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Fri, 14 Aug 2026 14:22:29 +0200 Subject: [PATCH] =?UTF-8?q?fixup!=20=E2=9C=A8(frontend)=20introduce=20perf?= =?UTF-8?q?ormance=20mode=20with=20auto-detection=20and=20telemetry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/features/analytics/hardware.ts | 11 +-- .../components/ToastCpuConstrained.tsx | 68 +++++++++++-------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/frontend/src/features/analytics/hardware.ts b/src/frontend/src/features/analytics/hardware.ts index 51096fa9..add1e524 100644 --- a/src/frontend/src/features/analytics/hardware.ts +++ b/src/frontend/src/features/analytics/hardware.ts @@ -49,12 +49,15 @@ export const collectHardwareSnapshot = async (): Promise => { if (typeof nav.getBattery === 'function') { // getBattery can hang on some platforms — don't let it delay the event. + let timeoutId: ReturnType | undefined const battery = await Promise.race([ nav.getBattery(), - new Promise((resolve) => - setTimeout(() => resolve(null), BATTERY_TIMEOUT_MS) - ), - ]).catch(() => null) + new Promise((resolve) => { + timeoutId = setTimeout(() => resolve(null), BATTERY_TIMEOUT_MS) + }), + ]) + .catch(() => null) + .finally(() => clearTimeout(timeoutId)) if (battery) { snapshot.battery_level = battery.level snapshot.battery_charging = battery.charging diff --git a/src/frontend/src/features/notifications/components/ToastCpuConstrained.tsx b/src/frontend/src/features/notifications/components/ToastCpuConstrained.tsx index 7fb26660..6ded05f8 100644 --- a/src/frontend/src/features/notifications/components/ToastCpuConstrained.tsx +++ b/src/frontend/src/features/notifications/components/ToastCpuConstrained.tsx @@ -1,8 +1,9 @@ import { useToast } from 'react-aria' import { useRef } from 'react' +import { RiCloseLine } from '@remixicon/react' import { type ToastProps } from './Toast' -import { VStack } from '@/styled-system/jsx' +import { HStack, VStack } from '@/styled-system/jsx' import { useTranslation } from 'react-i18next' import { Button, Text } from '@/primitives' import { css } from '@/styled-system/css' @@ -10,13 +11,16 @@ import { StyledToastContainer } from './StyledToastContainer' import { disablePerformanceMode } from '@/stores/performanceMode' import { captureEvent } from '@/features/analytics/telemetry' -// todo - make it closable export function ToastCpuConstrained({ state, ...props }: Readonly) { const { t } = useTranslation('notifications', { keyPrefix: 'cpuConstrained', }) const ref = useRef(null) - const { toastProps, contentProps } = useToast(props, state, ref) + const { toastProps, contentProps, closeButtonProps } = useToast( + props, + state, + ref + ) const toast = props.toast const handleKeepQuality = () => { @@ -27,35 +31,39 @@ export function ToastCpuConstrained({ state, ...props }: Readonly) { return ( - - + - {t('message')} - - + + - + ) }