Fix sing-box install loading state

This commit is contained in:
ushan0v
2026-06-09 01:29:05 +03:00
parent 1c08e60c0b
commit 1059730c25
3 changed files with 28 additions and 74 deletions
@@ -180,14 +180,14 @@ describe('applyUiStateToStore', () => {
});
});
it('preserves sing-box variant capabilities while a sing-box component action is running', () => {
it('keeps current sing-box variant while a different sing-box install action is running', () => {
store.set({
diagnosticsSystemInfo: {
...store.get().diagnosticsSystemInfo,
providerInfoLoaded: true,
sing_box_version: '1.13.12-extended-2.3.2',
sing_box_extended: 1,
sing_box_tiny: 0,
sing_box_version: '1.12.25',
sing_box_extended: 0,
sing_box_tiny: 1,
sing_box_compressed: 0,
sing_box_tailscale: 1,
zapret_installed: 0,
@@ -229,19 +229,22 @@ describe('applyUiStateToStore', () => {
expect(store.get().diagnosticsSystemInfo).toMatchObject({
providerInfoLoaded: true,
sing_box_version: '1.13.12-extended-2.3.2',
sing_box_extended: 1,
sing_box_tiny: 0,
sing_box_compressed: 1,
sing_box_tailscale: 1,
sing_box_version: '1.12.25',
sing_box_extended: 0,
sing_box_tiny: 1,
sing_box_compressed: 0,
sing_box_tailscale: 0,
zapret_installed: 1,
zapret2_installed: 1,
byedpi_installed: 0,
server_inbounds_enabled_count: 2,
});
expect(
store.get().updatesActions.singBoxInstallExtendedCompressed.loading,
).toBe(true);
});
it('uses the running sing-box install action as the immediate target variant', () => {
it('marks the running sing-box install action without pretending it is installed', () => {
applyUiStateToStore(
createUiState(
{
@@ -269,10 +272,13 @@ describe('applyUiStateToStore', () => {
);
expect(store.get().diagnosticsSystemInfo).toMatchObject({
sing_box_extended: 1,
sing_box_tiny: 0,
sing_box_extended: 0,
sing_box_tiny: 1,
sing_box_compressed: 0,
sing_box_tailscale: 1,
sing_box_tailscale: 0,
});
expect(store.get().updatesActions.singBoxInstallExtended.loading).toBe(
true,
);
});
});
@@ -43,9 +43,6 @@ function getEmptyDiagnosticsActions(): StoreType['diagnosticsActions'] {
function applyServiceState(uiState: Podkop.UiState) {
const currentSystemInfo = store.get().diagnosticsSystemInfo;
const singBoxComponentActionRunning = (uiState.actions.component || []).find(
(state) => state.component === 'sing_box' && state.running === true,
);
const nextSystemInfo = {
...currentSystemInfo,
providerInfoLoaded: true,
@@ -56,35 +53,11 @@ function applyServiceState(uiState: Podkop.UiState) {
uiState.capabilities.server_inbounds_enabled_count,
};
if (singBoxComponentActionRunning?.action === 'install_extended') {
nextSystemInfo.sing_box_extended = 1;
nextSystemInfo.sing_box_tiny = 0;
nextSystemInfo.sing_box_compressed = 0;
nextSystemInfo.sing_box_tailscale = 1;
} else if (
singBoxComponentActionRunning?.action === 'install_extended_compressed'
) {
nextSystemInfo.sing_box_extended = 1;
nextSystemInfo.sing_box_tiny = 0;
nextSystemInfo.sing_box_compressed = 1;
nextSystemInfo.sing_box_tailscale = 1;
} else if (singBoxComponentActionRunning?.action === 'install_stable') {
nextSystemInfo.sing_box_extended = 0;
nextSystemInfo.sing_box_tiny = 0;
nextSystemInfo.sing_box_compressed = 0;
nextSystemInfo.sing_box_tailscale = 1;
} else if (singBoxComponentActionRunning?.action === 'install_tiny') {
nextSystemInfo.sing_box_extended = 0;
nextSystemInfo.sing_box_tiny = 1;
nextSystemInfo.sing_box_compressed = 0;
nextSystemInfo.sing_box_tailscale = 0;
} else {
nextSystemInfo.sing_box_extended = uiState.capabilities.sing_box_extended;
nextSystemInfo.sing_box_tiny = uiState.capabilities.sing_box_tiny;
nextSystemInfo.sing_box_compressed =
uiState.capabilities.sing_box_compressed;
nextSystemInfo.sing_box_tailscale = uiState.capabilities.sing_box_tailscale;
}
nextSystemInfo.sing_box_extended = uiState.capabilities.sing_box_extended;
nextSystemInfo.sing_box_tiny = uiState.capabilities.sing_box_tiny;
nextSystemInfo.sing_box_compressed =
uiState.capabilities.sing_box_compressed;
nextSystemInfo.sing_box_tailscale = uiState.capabilities.sing_box_tailscale;
store.set({
servicesInfoWidget: {
@@ -4094,9 +4094,6 @@ function getEmptyDiagnosticsActions() {
}
function applyServiceState(uiState) {
const currentSystemInfo = store.get().diagnosticsSystemInfo;
const singBoxComponentActionRunning = (uiState.actions.component || []).find(
(state) => state.component === "sing_box" && state.running === true
);
const nextSystemInfo = {
...currentSystemInfo,
providerInfoLoaded: true,
@@ -4105,32 +4102,10 @@ function applyServiceState(uiState) {
byedpi_installed: uiState.capabilities.byedpi_installed,
server_inbounds_enabled_count: uiState.capabilities.server_inbounds_enabled_count
};
if (singBoxComponentActionRunning?.action === "install_extended") {
nextSystemInfo.sing_box_extended = 1;
nextSystemInfo.sing_box_tiny = 0;
nextSystemInfo.sing_box_compressed = 0;
nextSystemInfo.sing_box_tailscale = 1;
} else if (singBoxComponentActionRunning?.action === "install_extended_compressed") {
nextSystemInfo.sing_box_extended = 1;
nextSystemInfo.sing_box_tiny = 0;
nextSystemInfo.sing_box_compressed = 1;
nextSystemInfo.sing_box_tailscale = 1;
} else if (singBoxComponentActionRunning?.action === "install_stable") {
nextSystemInfo.sing_box_extended = 0;
nextSystemInfo.sing_box_tiny = 0;
nextSystemInfo.sing_box_compressed = 0;
nextSystemInfo.sing_box_tailscale = 1;
} else if (singBoxComponentActionRunning?.action === "install_tiny") {
nextSystemInfo.sing_box_extended = 0;
nextSystemInfo.sing_box_tiny = 1;
nextSystemInfo.sing_box_compressed = 0;
nextSystemInfo.sing_box_tailscale = 0;
} else {
nextSystemInfo.sing_box_extended = uiState.capabilities.sing_box_extended;
nextSystemInfo.sing_box_tiny = uiState.capabilities.sing_box_tiny;
nextSystemInfo.sing_box_compressed = uiState.capabilities.sing_box_compressed;
nextSystemInfo.sing_box_tailscale = uiState.capabilities.sing_box_tailscale;
}
nextSystemInfo.sing_box_extended = uiState.capabilities.sing_box_extended;
nextSystemInfo.sing_box_tiny = uiState.capabilities.sing_box_tiny;
nextSystemInfo.sing_box_compressed = uiState.capabilities.sing_box_compressed;
nextSystemInfo.sing_box_tailscale = uiState.capabilities.sing_box_tailscale;
store.set({
servicesInfoWidget: {
loading: false,