feat: actualize system actions behavior

This commit is contained in:
divocat
2025-10-15 21:13:52 +03:00
parent c35a174708
commit c0b35c865d
7 changed files with 184 additions and 116 deletions

View File

@@ -0,0 +1,29 @@
import { PodkopShellMethods } from '../methods';
import { store } from '../services';
export async function fetchServicesInfo() {
const [podkop, singbox] = await Promise.all([
PodkopShellMethods.getStatus(),
PodkopShellMethods.getSingBoxStatus(),
]);
if (!podkop.success || !singbox.success) {
store.set({
servicesInfoWidget: {
loading: false,
failed: true,
data: { singbox: 0, podkop: 0 },
},
});
}
if (podkop.success && singbox.success) {
store.set({
servicesInfoWidget: {
loading: false,
failed: false,
data: { singbox: singbox.data.running, podkop: podkop.data.enabled },
},
});
}
}

View File

@@ -0,0 +1 @@
export * from './fetchServicesInfo';

View File

@@ -7,6 +7,7 @@ import { prettyBytes } from '../../../helpers/prettyBytes';
import { CustomPodkopMethods, PodkopShellMethods } from '../../methods';
import { socket, store, StoreType } from '../../services';
import { renderSections, renderWidget } from './partials';
import { fetchServicesInfo } from '../../fetchers';
// Fetchers
@@ -36,33 +37,6 @@ async function fetchDashboardSections() {
});
}
async function fetchServicesInfo() {
const [podkop, singbox] = await Promise.all([
PodkopShellMethods.getStatus(),
PodkopShellMethods.getSingBoxStatus(),
]);
if (!podkop.success || !singbox.success) {
store.set({
servicesInfoWidget: {
loading: false,
failed: true,
data: { singbox: 0, podkop: 0 },
},
});
}
if (podkop.success && singbox.success) {
store.set({
servicesInfoWidget: {
loading: false,
failed: false,
data: { singbox: singbox.data.running, podkop: podkop.data.enabled },
},
});
}
}
async function connectToClashSockets() {
socket.subscribe(
`${getClashWsUrl()}/traffic?token=`,

View File

@@ -40,10 +40,10 @@ export async function runDnsCheck() {
Boolean(data.dns_status);
const atLeastOneGood =
Boolean(data.dns_on_router) ||
Boolean(data.dhcp_has_dns_server) ||
Boolean(data.bootstrap_dns_status) ||
Boolean(data.dns_status);
Boolean(data.dns_on_router) ||
Boolean(data.dhcp_has_dns_server) ||
Boolean(data.bootstrap_dns_status) ||
Boolean(data.dns_status);
console.log('dnsChecks', dnsChecks);
@@ -88,7 +88,7 @@ export async function runDnsCheck() {
},
{
state: data.dhcp_has_dns_server ? 'success' : 'error',
key: _('Dhcp has dns server'),
key: _('DHCP has DNS server'),
value: '',
},
],

View File

@@ -12,6 +12,7 @@ import {
renderSystemInfo,
} from './partials';
import { PodkopShellMethods } from '../../methods';
import { fetchServicesInfo } from '../../fetchers';
function renderDiagnosticsChecks() {
console.log('renderDiagnosticsChecks');
@@ -59,13 +60,15 @@ async function handleRestart() {
} catch (e) {
console.log('handleRestart - e', e);
} finally {
store.set({
diagnosticsActions: {
...diagnosticsActions,
restart: { loading: false },
},
});
location.reload();
setTimeout(async () => {
await fetchServicesInfo();
store.set({
diagnosticsActions: {
...diagnosticsActions,
restart: { loading: false },
},
});
}, 5000);
}
}
@@ -83,13 +86,13 @@ async function handleStop() {
} catch (e) {
console.log('handleStop - e', e);
} finally {
await fetchServicesInfo();
store.set({
diagnosticsActions: {
...diagnosticsActions,
stop: { loading: false },
},
});
// TODO actualize dashboard
}
}
@@ -107,13 +110,15 @@ async function handleStart() {
} catch (e) {
console.log('handleStart - e', e);
} finally {
store.set({
diagnosticsActions: {
...diagnosticsActions,
start: { loading: false },
},
});
location.reload();
setTimeout(async () => {
await fetchServicesInfo();
store.set({
diagnosticsActions: {
...diagnosticsActions,
start: { loading: false },
},
});
}, 5000);
}
}
@@ -131,13 +136,13 @@ async function handleEnable() {
} catch (e) {
console.log('handleEnable - e', e);
} finally {
await fetchServicesInfo();
store.set({
diagnosticsActions: {
...diagnosticsActions,
enable: { loading: false },
},
});
//TODO actualize dashboard
}
}
@@ -155,20 +160,29 @@ async function handleDisable() {
} catch (e) {
console.log('handleDisable - e', e);
} finally {
await fetchServicesInfo();
store.set({
diagnosticsActions: {
...diagnosticsActions,
disable: { loading: false },
},
});
//TODO actualize dashboard
}
}
function renderDiagnosticAvailableActionsWidget() {
const diagnosticsActions = store.get().diagnosticsActions;
const servicesInfoWidget = store.get().servicesInfoWidget;
console.log('renderDiagnosticActionsWidget');
const podkopEnabled = Boolean(servicesInfoWidget.data.podkop);
const singBoxRunning = Boolean(servicesInfoWidget.data.singbox);
const atLeastOneServiceCommandLoading =
servicesInfoWidget.loading ||
diagnosticsActions.restart.loading ||
diagnosticsActions.start.loading ||
diagnosticsActions.stop.loading;
const container = document.getElementById('pdk_diagnostic-page-actions');
const renderedActions = renderAvailableActions({
@@ -176,41 +190,49 @@ function renderDiagnosticAvailableActionsWidget() {
loading: diagnosticsActions.restart.loading,
visible: true,
onClick: handleRestart,
disabled: atLeastOneServiceCommandLoading,
},
start: {
loading: diagnosticsActions.start.loading,
visible: true,
visible: !singBoxRunning,
onClick: handleStart,
disabled: atLeastOneServiceCommandLoading,
},
stop: {
loading: diagnosticsActions.stop.loading,
visible: true,
visible: singBoxRunning,
onClick: handleStop,
disabled: atLeastOneServiceCommandLoading,
},
enable: {
loading: diagnosticsActions.enable.loading,
visible: true,
visible: !podkopEnabled,
onClick: handleEnable,
disabled: atLeastOneServiceCommandLoading,
},
disable: {
loading: diagnosticsActions.disable.loading,
visible: true,
visible: podkopEnabled,
onClick: handleDisable,
disabled: atLeastOneServiceCommandLoading,
},
globalCheck: {
loading: diagnosticsActions.globalCheck.loading,
visible: true,
onClick: () => {},
disabled: atLeastOneServiceCommandLoading,
},
viewLogs: {
loading: diagnosticsActions.viewLogs.loading,
visible: true,
onClick: () => {},
disabled: atLeastOneServiceCommandLoading,
},
showSingBoxConfig: {
loading: diagnosticsActions.showSingBoxConfig.loading,
visible: true,
onClick: () => {},
disabled: atLeastOneServiceCommandLoading,
},
});
@@ -267,7 +289,7 @@ async function onStoreUpdate(
renderDiagnosticRunActionWidget();
}
if (diff.diagnosticsActions) {
if (diff.diagnosticsActions || diff.servicesInfoWidget) {
renderDiagnosticAvailableActionsWidget();
}
}
@@ -313,5 +335,8 @@ export async function initController(): Promise<void> {
// Initial system info render
renderDiagnosticSystemInfoWidget();
// Initial services info fetch
fetchServicesInfo();
});
}

View File

@@ -14,6 +14,7 @@ import { insertIf } from '../../../../helpers';
interface ActionProps {
loading: boolean;
visible: boolean;
disabled: boolean;
onClick: () => void;
}
@@ -47,6 +48,7 @@ export function renderAvailableActions({
icon: renderRotateCcwIcon24,
text: 'Restart podkop',
loading: restart.loading,
disabled: restart.disabled,
}),
]),
...insertIf(stop.visible, [
@@ -56,6 +58,7 @@ export function renderAvailableActions({
icon: renderCircleStopIcon24,
text: 'Stop podkop',
loading: stop.loading,
disabled: stop.disabled,
}),
]),
...insertIf(start.visible, [
@@ -65,6 +68,7 @@ export function renderAvailableActions({
icon: renderCirclePlayIcon24,
text: 'Start podkop',
loading: start.loading,
disabled: start.disabled,
}),
]),
...insertIf(disable.visible, [
@@ -72,8 +76,9 @@ export function renderAvailableActions({
classNames: ['cbi-button-remove'],
onClick: disable.onClick,
icon: renderPauseIcon24,
text: 'Disable podkop',
text: 'Disable autostart',
loading: disable.loading,
disabled: disable.disabled,
}),
]),
...insertIf(enable.visible, [
@@ -81,8 +86,9 @@ export function renderAvailableActions({
classNames: ['cbi-button-save'],
onClick: enable.onClick,
icon: renderPlayIcon24,
text: 'Enable podkop',
text: 'Enable autostart',
loading: enable.loading,
disabled: enable.disabled,
}),
]),
...insertIf(globalCheck.visible, [
@@ -91,6 +97,7 @@ export function renderAvailableActions({
icon: renderCircleCheckBigIcon24,
text: 'Get global check',
loading: globalCheck.loading,
disabled: globalCheck.disabled,
}),
]),
...insertIf(viewLogs.visible, [
@@ -99,6 +106,7 @@ export function renderAvailableActions({
icon: renderSquareChartGanttIcon24,
text: 'View logs',
loading: viewLogs.loading,
disabled: viewLogs.disabled,
}),
]),
...insertIf(showSingBoxConfig.visible, [
@@ -107,6 +115,7 @@ export function renderAvailableActions({
icon: renderCogIcon24,
text: 'Show sing-box config',
loading: showSingBoxConfig.loading,
disabled: showSingBoxConfig.disabled,
}),
]),
]);