mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-19 19:45:02 +03:00
166d5633cc
Stop sat next to Restart on the dashboard and fired on the first click. A mis-click cut every proxy connection, and when the panel itself is reached through that proxy the only way back was SSH (#7103). Stop now opens a confirmation with Cancel focused. When Xray is stopped the first button reads Start instead of Restart and Stop is disabled; in the crashed state Stop stays enabled, because setting the manual-stop flag is what halts the crash-recovery restart loop. Closes #7103
248 lines
7.1 KiB
TypeScript
248 lines
7.1 KiB
TypeScript
import { Fragment } from 'react';
|
|
import type { ReactNode } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button, Modal, Tag, Tooltip } from 'antd';
|
|
import {
|
|
ApiOutlined,
|
|
ArrowUpOutlined,
|
|
AreaChartOutlined,
|
|
BarsOutlined,
|
|
CloudDownloadOutlined,
|
|
CloudServerOutlined,
|
|
ControlOutlined,
|
|
FileTextOutlined,
|
|
PlayCircleOutlined,
|
|
PoweroffOutlined,
|
|
ReloadOutlined,
|
|
} from '@ant-design/icons';
|
|
|
|
import { formatPanelVersion } from '@/lib/panel-version';
|
|
import { activateOnKey } from '@/utils/a11y';
|
|
import type { Status } from '@/models/status';
|
|
|
|
interface OverviewActionBarProps {
|
|
status: Status;
|
|
isMobile: boolean;
|
|
accessLogEnable: boolean;
|
|
panelVersion: string;
|
|
latestVersion: string;
|
|
updateAvailable: boolean;
|
|
onStopXray: () => void | Promise<void>;
|
|
onRestartXray: () => void;
|
|
onOpenLogs: () => void;
|
|
onOpenXrayLogs: () => void;
|
|
onOpenAmneziaWGLogs: () => void;
|
|
onOpenConfig: () => void;
|
|
onOpenBackup: () => void;
|
|
onOpenSystemHistory: () => void;
|
|
onOpenXrayMetrics: () => void;
|
|
onOpenPanelUpdate: () => void;
|
|
onOpenVersionSwitch: () => void;
|
|
}
|
|
|
|
interface BarAction {
|
|
key: string;
|
|
icon: ReactNode;
|
|
text: string;
|
|
onClick: () => void;
|
|
primary?: boolean;
|
|
danger?: boolean;
|
|
disabled?: boolean;
|
|
hint?: string;
|
|
}
|
|
|
|
const XRAY_STATE_KEYS: Record<string, string> = {
|
|
running: 'pages.index.xrayStatusRunning',
|
|
stop: 'pages.index.xrayStatusStop',
|
|
error: 'pages.index.xrayStatusError',
|
|
};
|
|
|
|
export default function OverviewActionBar({
|
|
status,
|
|
isMobile,
|
|
accessLogEnable,
|
|
panelVersion,
|
|
latestVersion,
|
|
updateAvailable,
|
|
onStopXray,
|
|
onRestartXray,
|
|
onOpenLogs,
|
|
onOpenXrayLogs,
|
|
onOpenAmneziaWGLogs,
|
|
onOpenConfig,
|
|
onOpenBackup,
|
|
onOpenSystemHistory,
|
|
onOpenXrayMetrics,
|
|
onOpenPanelUpdate,
|
|
onOpenVersionSwitch,
|
|
}: OverviewActionBarProps) {
|
|
const { t } = useTranslation();
|
|
const [modal, modalContextHolder] = Modal.useModal();
|
|
const stateText = t(XRAY_STATE_KEYS[status.xray.state] ?? 'pages.index.xrayStatusUnknown');
|
|
const hasVersion = !!status.xray.version && status.xray.version !== 'Unknown';
|
|
const size = isMobile ? ('small' as const) : ('middle' as const);
|
|
const isStopped = status.xray.state === 'stop';
|
|
|
|
const actionGroups: BarAction[][] = [
|
|
[
|
|
{
|
|
key: 'restart',
|
|
icon: isStopped ? <PlayCircleOutlined aria-hidden /> : <ReloadOutlined aria-hidden />,
|
|
text: t(isStopped ? 'pages.index.startXray' : 'pages.index.restartXray'),
|
|
onClick: onRestartXray,
|
|
primary: true,
|
|
},
|
|
{
|
|
key: 'stop',
|
|
icon: <PoweroffOutlined aria-hidden />,
|
|
text: t('pages.index.stopXray'),
|
|
danger: true,
|
|
disabled: isStopped,
|
|
hint: isStopped ? t('pages.index.stopXrayDisabledHint') : undefined,
|
|
onClick: () =>
|
|
modal.confirm({
|
|
title: t('pages.index.stopXrayConfirmTitle'),
|
|
content: t('pages.index.stopXrayConfirmContent'),
|
|
okText: t('pages.index.stopXrayConfirmOk'),
|
|
okType: 'danger',
|
|
cancelText: t('cancel'),
|
|
focusable: { autoFocusButton: 'cancel' },
|
|
onOk: onStopXray,
|
|
}),
|
|
},
|
|
],
|
|
[
|
|
{
|
|
key: 'logs',
|
|
icon: <BarsOutlined aria-hidden />,
|
|
text: t('pages.index.logs'),
|
|
onClick: onOpenLogs,
|
|
},
|
|
...(accessLogEnable
|
|
? [
|
|
{
|
|
key: 'accessLogs',
|
|
icon: <FileTextOutlined aria-hidden />,
|
|
text: t('pages.index.accessLogs'),
|
|
onClick: onOpenXrayLogs,
|
|
},
|
|
]
|
|
: []),
|
|
...(status.amneziawg.configured
|
|
? [
|
|
{
|
|
key: 'amneziawgLogs',
|
|
icon: <ApiOutlined aria-hidden />,
|
|
text: t('pages.index.amneziawgLogs'),
|
|
onClick: onOpenAmneziaWGLogs,
|
|
},
|
|
]
|
|
: []),
|
|
{
|
|
key: 'config',
|
|
icon: <ControlOutlined aria-hidden />,
|
|
text: t('pages.index.config'),
|
|
onClick: onOpenConfig,
|
|
},
|
|
{
|
|
key: 'backup',
|
|
icon: <CloudServerOutlined aria-hidden />,
|
|
text: t('pages.index.backupTitle'),
|
|
onClick: onOpenBackup,
|
|
},
|
|
],
|
|
[
|
|
{
|
|
key: 'history',
|
|
icon: <AreaChartOutlined aria-hidden />,
|
|
text: t('pages.index.systemHistoryTitle'),
|
|
onClick: onOpenSystemHistory,
|
|
},
|
|
{
|
|
key: 'metrics',
|
|
icon: <ArrowUpOutlined aria-hidden />,
|
|
text: t('pages.index.xrayMetricsTitle'),
|
|
onClick: onOpenXrayMetrics,
|
|
},
|
|
],
|
|
];
|
|
|
|
const statePill = (
|
|
<span className="ov-state" data-state={status.xray.state}>
|
|
<span className="ov-state-dot" style={{ color: status.xray.color }} />
|
|
<span>{`${t('pages.index.xrayStatus')} · ${stateText}`}</span>
|
|
{hasVersion && (
|
|
<Tooltip title={t('pages.index.xraySwitch')}>
|
|
<button type="button" className="ov-state-version" onClick={onOpenVersionSwitch}>
|
|
{`v${status.xray.version}`}
|
|
</button>
|
|
</Tooltip>
|
|
)}
|
|
</span>
|
|
);
|
|
|
|
return (
|
|
<div className="ov-bar">
|
|
{modalContextHolder}
|
|
{status.xray.errorMsg ? (
|
|
<Tooltip title={<span className="ov-error-detail">{status.xray.errorMsg}</span>}>
|
|
{statePill}
|
|
</Tooltip>
|
|
) : (
|
|
statePill
|
|
)}
|
|
|
|
{status.xray.state === 'running' && status.xray.errorMsg ? (
|
|
<Tooltip title={<span className="ov-error-detail">{status.xray.errorMsg}</span>}>
|
|
<Tag color="error">{t('pages.index.xrayStatusError')}</Tag>
|
|
</Tooltip>
|
|
) : null}
|
|
|
|
{updateAvailable ? (
|
|
<Tag
|
|
className="ov-update-tag"
|
|
color="warning"
|
|
icon={<CloudDownloadOutlined aria-hidden />}
|
|
role="button"
|
|
tabIndex={0}
|
|
onClick={onOpenPanelUpdate}
|
|
onKeyDown={activateOnKey(onOpenPanelUpdate)}
|
|
>
|
|
{`${t('update')} ${formatPanelVersion(latestVersion)}`}
|
|
</Tag>
|
|
) : (
|
|
<Tooltip title={t('pages.index.updatePanel')}>
|
|
<button type="button" className="ov-panel-version ov-mono" onClick={onOpenPanelUpdate}>
|
|
{formatPanelVersion(panelVersion)}
|
|
</button>
|
|
</Tooltip>
|
|
)}
|
|
|
|
<div className="ov-bar-actions">
|
|
{actionGroups.map((group, groupIndex) => (
|
|
<Fragment key={group[0].key}>
|
|
{groupIndex > 0 && <span className="ov-bar-sep" />}
|
|
{group.map((action) => (
|
|
<Tooltip key={action.key} title={action.hint}>
|
|
<Button
|
|
type={action.primary ? undefined : 'text'}
|
|
color={action.primary ? 'primary' : undefined}
|
|
variant={action.primary ? 'outlined' : undefined}
|
|
size={size}
|
|
danger={action.danger}
|
|
disabled={action.disabled}
|
|
icon={action.icon}
|
|
aria-label={action.text}
|
|
onClick={action.onClick}
|
|
>
|
|
{isMobile ? undefined : action.text}
|
|
</Button>
|
|
</Tooltip>
|
|
))}
|
|
</Fragment>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|