mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-04 04:04:44 -07:00
more consistent switch, show current config name in tray icon context menu
This commit is contained in:
parent
3d62d9d00c
commit
f657b7375a
6 changed files with 30 additions and 8 deletions
11
src/components/Switch.tsx
Normal file
11
src/components/Switch.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Switch as MantineSwitch, type SwitchProps } from '@mantine/core';
|
||||||
|
|
||||||
|
export const Switch = (props: SwitchProps) => (
|
||||||
|
<MantineSwitch
|
||||||
|
{...props}
|
||||||
|
styles={{
|
||||||
|
track: { transition: 'none' },
|
||||||
|
thumb: { transition: 'none' },
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
@ -5,6 +5,7 @@ import type { ConfigFile } from '@/types';
|
||||||
import { CreateConfigModal } from './CreateConfigModal';
|
import { CreateConfigModal } from './CreateConfigModal';
|
||||||
import { DeleteConfigModal } from './DeleteConfigModal';
|
import { DeleteConfigModal } from './DeleteConfigModal';
|
||||||
import { Select } from '@/components/Select';
|
import { Select } from '@/components/Select';
|
||||||
|
import { stripFileExtension } from '@/utils/format';
|
||||||
|
|
||||||
interface ConfigFileManagerProps {
|
interface ConfigFileManagerProps {
|
||||||
configFiles: ConfigFile[];
|
configFiles: ConfigFile[];
|
||||||
|
|
@ -29,10 +30,9 @@ export const ConfigFileManager = ({
|
||||||
const [deleteModalOpened, setDeleteModalOpened] = useState(false);
|
const [deleteModalOpened, setDeleteModalOpened] = useState(false);
|
||||||
const [configToDelete, setConfigToDelete] = useState<string | null>(null);
|
const [configToDelete, setConfigToDelete] = useState<string | null>(null);
|
||||||
|
|
||||||
const existingConfigNames = configFiles.map((file) => {
|
const existingConfigNames = configFiles.map((file) =>
|
||||||
const extension = file.name.split('.').pop() || '';
|
stripFileExtension(file.name).toLowerCase()
|
||||||
return file.name.replace(`.${extension}`, '').toLowerCase();
|
);
|
||||||
});
|
|
||||||
|
|
||||||
const handleOpenConfigModal = () => {
|
const handleOpenConfigModal = () => {
|
||||||
setConfigModalOpened(true);
|
setConfigModalOpened(true);
|
||||||
|
|
@ -78,7 +78,7 @@ export const ConfigFileManager = ({
|
||||||
|
|
||||||
const selectData = configFiles.map((file) => {
|
const selectData = configFiles.map((file) => {
|
||||||
const extension = file.name.split('.').pop() || '';
|
const extension = file.name.split('.').pop() || '';
|
||||||
const nameWithoutExtension = file.name.replace(`.${extension}`, '');
|
const nameWithoutExtension = stripFileExtension(file.name);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: file.name,
|
value: file.name,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { Text, Group, Button, Stack } from '@mantine/core';
|
import { Text, Group, Button, Stack } from '@mantine/core';
|
||||||
import { Modal } from '@/components/Modal';
|
import { Modal } from '@/components/Modal';
|
||||||
|
import { stripFileExtension } from '@/utils/format';
|
||||||
|
|
||||||
interface DeleteConfigModalProps {
|
interface DeleteConfigModalProps {
|
||||||
opened: boolean;
|
opened: boolean;
|
||||||
|
|
@ -14,7 +15,7 @@ export const DeleteConfigModal = ({
|
||||||
onConfirm,
|
onConfirm,
|
||||||
configName,
|
configName,
|
||||||
}: DeleteConfigModalProps) => {
|
}: DeleteConfigModalProps) => {
|
||||||
const displayName = configName?.replace(/\.[^/.]+$/, '') || '';
|
const displayName = configName ? stripFileExtension(configName) : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal opened={opened} onClose={onClose} title="Delete Configuration">
|
<Modal opened={opened} onClose={onClose} title="Delete Configuration">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { Stack, Text, Switch } from '@mantine/core';
|
import { Stack, Text } from '@mantine/core';
|
||||||
import { usePreferencesStore } from '@/stores/preferences';
|
import { usePreferencesStore } from '@/stores/preferences';
|
||||||
|
import { Switch } from '@/components/Switch';
|
||||||
|
|
||||||
export const GeneralTab = () => {
|
export const GeneralTab = () => {
|
||||||
const [enableSystemTray, setEnableSystemTray] = useState(false);
|
const [enableSystemTray, setEnableSystemTray] = useState(false);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { join } from 'path';
|
||||||
import { platform, resourcesPath } from 'process';
|
import { platform, resourcesPath } from 'process';
|
||||||
import { getEnableSystemTray } from './config';
|
import { getEnableSystemTray } from './config';
|
||||||
import { getMainWindow } from './window';
|
import { getMainWindow } from './window';
|
||||||
|
import { stripFileExtension } from '@/utils/format';
|
||||||
import type { CpuMetrics, MemoryMetrics, GpuMetrics } from './monitoring';
|
import type { CpuMetrics, MemoryMetrics, GpuMetrics } from './monitoring';
|
||||||
import type { Screen } from '@/types';
|
import type { Screen } from '@/types';
|
||||||
import { PRODUCT_NAME } from '@/constants';
|
import { PRODUCT_NAME } from '@/constants';
|
||||||
|
|
@ -142,8 +143,13 @@ function buildContextMenu() {
|
||||||
menuTemplate.push({ type: 'separator' });
|
menuTemplate.push({ type: 'separator' });
|
||||||
|
|
||||||
if (appState.currentScreen === 'launch' && !appState.isLaunched) {
|
if (appState.currentScreen === 'launch' && !appState.isLaunched) {
|
||||||
|
const configDisplayName = appState.currentConfig
|
||||||
|
? stripFileExtension(appState.currentConfig)
|
||||||
|
: null;
|
||||||
menuTemplate.push({
|
menuTemplate.push({
|
||||||
label: 'Launch with Current Config',
|
label: configDisplayName
|
||||||
|
? `Launch: ${configDisplayName}`
|
||||||
|
: 'Launch with Current Config',
|
||||||
enabled: !!appState.currentConfig,
|
enabled: !!appState.currentConfig,
|
||||||
click: () => {
|
click: () => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
|
|
|
||||||
|
|
@ -45,3 +45,6 @@ export const formatDeviceName = (deviceName: string) =>
|
||||||
.replace(/\s*\d+-core\s*/gi, '')
|
.replace(/\s*\d+-core\s*/gi, '')
|
||||||
.replace(/\s+/g, ' ')
|
.replace(/\s+/g, ' ')
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
|
export const stripFileExtension = (filename: string) =>
|
||||||
|
filename.replace(/\.[^/.]+$/, '');
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue