From f657b7375a1bb967667f74c1aaa1d04f97169c58 Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 1 Oct 2025 13:14:34 -0700 Subject: [PATCH] more consistent switch, show current config name in tray icon context menu --- src/components/Switch.tsx | 11 +++++++++++ src/components/screens/Launch/ConfigFileManager.tsx | 10 +++++----- src/components/screens/Launch/DeleteConfigModal.tsx | 3 ++- src/components/settings/GeneralTab.tsx | 3 ++- src/main/modules/tray.ts | 8 +++++++- src/utils/format.ts | 3 +++ 6 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 src/components/Switch.tsx diff --git a/src/components/Switch.tsx b/src/components/Switch.tsx new file mode 100644 index 0000000..4562098 --- /dev/null +++ b/src/components/Switch.tsx @@ -0,0 +1,11 @@ +import { Switch as MantineSwitch, type SwitchProps } from '@mantine/core'; + +export const Switch = (props: SwitchProps) => ( + +); diff --git a/src/components/screens/Launch/ConfigFileManager.tsx b/src/components/screens/Launch/ConfigFileManager.tsx index 1213578..15e29fb 100644 --- a/src/components/screens/Launch/ConfigFileManager.tsx +++ b/src/components/screens/Launch/ConfigFileManager.tsx @@ -5,6 +5,7 @@ import type { ConfigFile } from '@/types'; import { CreateConfigModal } from './CreateConfigModal'; import { DeleteConfigModal } from './DeleteConfigModal'; import { Select } from '@/components/Select'; +import { stripFileExtension } from '@/utils/format'; interface ConfigFileManagerProps { configFiles: ConfigFile[]; @@ -29,10 +30,9 @@ export const ConfigFileManager = ({ const [deleteModalOpened, setDeleteModalOpened] = useState(false); const [configToDelete, setConfigToDelete] = useState(null); - const existingConfigNames = configFiles.map((file) => { - const extension = file.name.split('.').pop() || ''; - return file.name.replace(`.${extension}`, '').toLowerCase(); - }); + const existingConfigNames = configFiles.map((file) => + stripFileExtension(file.name).toLowerCase() + ); const handleOpenConfigModal = () => { setConfigModalOpened(true); @@ -78,7 +78,7 @@ export const ConfigFileManager = ({ const selectData = configFiles.map((file) => { const extension = file.name.split('.').pop() || ''; - const nameWithoutExtension = file.name.replace(`.${extension}`, ''); + const nameWithoutExtension = stripFileExtension(file.name); return { value: file.name, diff --git a/src/components/screens/Launch/DeleteConfigModal.tsx b/src/components/screens/Launch/DeleteConfigModal.tsx index 232b6f4..6a84fef 100644 --- a/src/components/screens/Launch/DeleteConfigModal.tsx +++ b/src/components/screens/Launch/DeleteConfigModal.tsx @@ -1,5 +1,6 @@ import { Text, Group, Button, Stack } from '@mantine/core'; import { Modal } from '@/components/Modal'; +import { stripFileExtension } from '@/utils/format'; interface DeleteConfigModalProps { opened: boolean; @@ -14,7 +15,7 @@ export const DeleteConfigModal = ({ onConfirm, configName, }: DeleteConfigModalProps) => { - const displayName = configName?.replace(/\.[^/.]+$/, '') || ''; + const displayName = configName ? stripFileExtension(configName) : ''; return ( diff --git a/src/components/settings/GeneralTab.tsx b/src/components/settings/GeneralTab.tsx index 23dcab2..f96e2a9 100644 --- a/src/components/settings/GeneralTab.tsx +++ b/src/components/settings/GeneralTab.tsx @@ -1,6 +1,7 @@ import { useState, useEffect } from 'react'; -import { Stack, Text, Switch } from '@mantine/core'; +import { Stack, Text } from '@mantine/core'; import { usePreferencesStore } from '@/stores/preferences'; +import { Switch } from '@/components/Switch'; export const GeneralTab = () => { const [enableSystemTray, setEnableSystemTray] = useState(false); diff --git a/src/main/modules/tray.ts b/src/main/modules/tray.ts index 88ea449..b5ec7ef 100644 --- a/src/main/modules/tray.ts +++ b/src/main/modules/tray.ts @@ -9,6 +9,7 @@ import { join } from 'path'; import { platform, resourcesPath } from 'process'; import { getEnableSystemTray } from './config'; import { getMainWindow } from './window'; +import { stripFileExtension } from '@/utils/format'; import type { CpuMetrics, MemoryMetrics, GpuMetrics } from './monitoring'; import type { Screen } from '@/types'; import { PRODUCT_NAME } from '@/constants'; @@ -142,8 +143,13 @@ function buildContextMenu() { menuTemplate.push({ type: 'separator' }); if (appState.currentScreen === 'launch' && !appState.isLaunched) { + const configDisplayName = appState.currentConfig + ? stripFileExtension(appState.currentConfig) + : null; menuTemplate.push({ - label: 'Launch with Current Config', + label: configDisplayName + ? `Launch: ${configDisplayName}` + : 'Launch with Current Config', enabled: !!appState.currentConfig, click: () => { const mainWindow = getMainWindow(); diff --git a/src/utils/format.ts b/src/utils/format.ts index f06fa53..009fa60 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -45,3 +45,6 @@ export const formatDeviceName = (deviceName: string) => .replace(/\s*\d+-core\s*/gi, '') .replace(/\s+/g, ' ') .trim(); + +export const stripFileExtension = (filename: string) => + filename.replace(/\.[^/.]+$/, '');