feat: update checks displaying

This commit is contained in:
divocat
2025-10-23 18:59:23 +03:00
parent c4078c8242
commit 8301f4c271
13 changed files with 280 additions and 551 deletions

View File

@@ -1,3 +1,5 @@
import { getCheckTitle } from '../helpers/getCheckTitle';
export enum DIAGNOSTICS_CHECKS {
DNS = 'DNS',
SINGBOX = 'SINGBOX',
@@ -11,22 +13,22 @@ export const DIAGNOSTICS_CHECKS_MAP: Record<
> = {
[DIAGNOSTICS_CHECKS.DNS]: {
order: 1,
title: _('DNS checks'),
title: getCheckTitle('DNS'),
code: DIAGNOSTICS_CHECKS.DNS,
},
[DIAGNOSTICS_CHECKS.SINGBOX]: {
order: 2,
title: _('Sing-box checks'),
title: getCheckTitle('Sing-box'),
code: DIAGNOSTICS_CHECKS.SINGBOX,
},
[DIAGNOSTICS_CHECKS.NFT]: {
order: 3,
title: _('Nftables checks'),
title: getCheckTitle('Nftables'),
code: DIAGNOSTICS_CHECKS.NFT,
},
[DIAGNOSTICS_CHECKS.FAKEIP]: {
order: 4,
title: _('FakeIP checks'),
title: getCheckTitle('FakeIP'),
code: DIAGNOSTICS_CHECKS.FAKEIP,
},
};

View File

@@ -3,6 +3,7 @@ import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { PodkopShellMethods } from '../../../methods';
import { IDiagnosticsChecksItem } from '../../../services';
import { updateCheckStore } from './updateCheckStore';
import { getMeta } from '../helpers/getMeta';
export async function runDnsCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.DNS;
@@ -11,7 +12,7 @@ export async function runDnsCheck() {
order,
code,
title,
description: _('Checking dns, please wait'),
description: _('Checking, please wait'),
state: 'loading',
items: [],
});
@@ -23,7 +24,7 @@ export async function runDnsCheck() {
order,
code,
title,
description: _('Cannot receive DNS checks result'),
description: _('Cannot receive checks result'),
state: 'error',
items: [],
});
@@ -45,27 +46,19 @@ export async function runDnsCheck() {
Boolean(data.bootstrap_dns_status) ||
Boolean(data.dns_status);
function getStatus() {
if (allGood) {
return 'success';
}
if (atLeastOneGood) {
return 'warning';
}
return 'error';
}
const { state, description } = getMeta({ atLeastOneGood, allGood });
updateCheckStore({
order,
code,
title,
description: _('DNS checks passed'),
state: getStatus(),
description,
state,
items: [
...insertIf<IDiagnosticsChecksItem>(
data.dns_type === 'doh' || data.dns_type === 'dot',
data.dns_type === 'doh' ||
data.dns_type === 'dot' ||
!data.bootstrap_dns_status,
[
{
state: data.bootstrap_dns_status ? 'success' : 'error',

View File

@@ -3,6 +3,7 @@ import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { PodkopShellMethods, RemoteFakeIPMethods } from '../../../methods';
import { IDiagnosticsChecksItem } from '../../../services';
import { updateCheckStore } from './updateCheckStore';
import { getMeta } from '../helpers/getMeta';
export async function runFakeIPCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.FAKEIP;
@@ -11,7 +12,7 @@ export async function runFakeIPCheck() {
order,
code,
title,
description: _('Checking FakeIP, please wait'),
description: _('Checking, please wait'),
state: 'loading',
items: [],
});
@@ -34,31 +35,7 @@ export async function runFakeIPCheck() {
const atLeastOneGood =
checks.router && checks.browserFakeIP && checks.differentIP;
function getMeta(): {
description: string;
state: 'loading' | 'warning' | 'success' | 'error' | 'skipped';
} {
if (allGood) {
return {
state: 'success',
description: _('FakeIP checks passed'),
};
}
if (atLeastOneGood) {
return {
state: 'warning',
description: _('FakeIP checks partially passed'),
};
}
return {
state: 'error',
description: _('FakeIP checks failed'),
};
}
const { state, description } = getMeta();
const { state, description } = getMeta({ atLeastOneGood, allGood });
updateCheckStore({
order,

View File

@@ -1,6 +1,7 @@
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { RemoteFakeIPMethods, PodkopShellMethods } from '../../../methods';
import { updateCheckStore } from './updateCheckStore';
import { getMeta } from '../helpers/getMeta';
export async function runNftCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.NFT;
@@ -9,7 +10,7 @@ export async function runNftCheck() {
order,
code,
title,
description: _('Checking nftables, please wait'),
description: _('Checking, please wait'),
state: 'loading',
items: [],
});
@@ -24,7 +25,7 @@ export async function runNftCheck() {
order,
code,
title,
description: _('Cannot receive nftables checks result'),
description: _('Cannot receive checks result'),
state: 'error',
items: [],
});
@@ -54,26 +55,14 @@ export async function runNftCheck() {
Boolean(data.rules_proxy_counters) ||
!data.rules_other_mark_exist;
function getStatus() {
if (allGood) {
return 'success';
}
if (atLeastOneGood) {
return 'warning';
}
return 'error';
}
const { state, description } = getMeta({ atLeastOneGood, allGood });
updateCheckStore({
order,
code,
title,
description: allGood
? _('Nftables checks passed')
: _('Nftables checks partially passed'),
state: getStatus(),
description,
state,
items: [
{
state: data.table_exist ? 'success' : 'error',

View File

@@ -1,6 +1,7 @@
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { PodkopShellMethods } from '../../../methods';
import { updateCheckStore } from './updateCheckStore';
import { getMeta } from '../helpers/getMeta';
export async function runSingBoxCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.SINGBOX;
@@ -9,7 +10,7 @@ export async function runSingBoxCheck() {
order,
code,
title,
description: _('Checking sing-box, please wait'),
description: _('Checking, please wait'),
state: 'loading',
items: [],
});
@@ -21,7 +22,7 @@ export async function runSingBoxCheck() {
order,
code,
title,
description: _('Cannot receive Sing-box checks result'),
description: _('Cannot receive checks result'),
state: 'error',
items: [],
});
@@ -47,24 +48,14 @@ export async function runSingBoxCheck() {
Boolean(data.sing_box_process_running) ||
Boolean(data.sing_box_ports_listening);
function getStatus() {
if (allGood) {
return 'success';
}
if (atLeastOneGood) {
return 'warning';
}
return 'error';
}
const { state, description } = getMeta({ atLeastOneGood, allGood });
updateCheckStore({
order,
code,
title,
description: _('Sing-box checks passed'),
state: getStatus(),
description,
state,
items: [
{
state: data.sing_box_installed ? 'success' : 'error',

View File

@@ -0,0 +1,3 @@
export function getCheckTitle(name: string) {
return `${name} ${_('checks')}`;
}

View File

@@ -0,0 +1,28 @@
interface IGetMetaProps {
allGood: boolean;
atLeastOneGood: boolean;
}
export function getMeta({ allGood, atLeastOneGood }: IGetMetaProps): {
description: string;
state: 'loading' | 'warning' | 'success' | 'error' | 'skipped';
} {
if (allGood) {
return {
state: 'success',
description: _('Checks passed'),
};
}
if (atLeastOneGood) {
return {
state: 'warning',
description: _('Checks partially passed'),
};
}
return {
state: 'error',
description: _('Checks failed'),
};
}