Do not use repair route to fixup start/stop errors

This commit is contained in:
Johannes Zellner
2025-07-23 16:07:32 +02:00
parent 68a8c964ea
commit b14e6a7860
+27 -22
View File
@@ -17,36 +17,41 @@ const inputDialog = useTemplateRef('inputDialog');
const props = defineProps([ 'app' ]);
const latestBackup = ref(null);
function isAppStopped() {
if (props.app.error) {
if (props.app.error.details.installationState === ISTATES.PENDING_START) return true;
else return false;
} else if (props.app.installationState === ISTATES.PENDING_START || props.app.installationState === ISTATES.PENDING_STOP) {
return props.app.installationState === ISTATES.PENDING_START;
const TARGET_RUN_STATE = {
START: Symbol('start'),
STOP: Symbol('stop'),
};
function targetRunState() {
const app = props.app;
// if we have an error, we want to retry the pending state, otherwise toggle the runstate
if (app.error) {
if (app.error.details.installationState === ISTATES.PENDING_START) return TARGET_RUN_STATE.START;
else return TARGET_RUN_STATE.STOP;
} else {
return props.app.runState === RSTATES.STOPPED;
if (app.runState === RSTATES.STOPPED) return TARGET_RUN_STATE.START;
else return TARGET_RUN_STATE.STOP;
}
}
const toggleRunStateBusy = ref(false);
async function onToggleRunState() {
// on error just retry
if (props.app.error) {
toggleRunStateBusy.value = true;
const [error] = await appsModel.repair(props.app.id, {});
if (error) return console.error(error);
}
const app = props.app;
if (isAppStopped()) {
toggleRunStateBusy.value = true;
const [error] = await appsModel.start(props.app.id);
if (error) return console.error(error);
toggleRunStateBusy.value = true;
let error;
if (targetRunState() === TARGET_RUN_STATE.START) [error] = await appsModel.start(app.id);
else [error] = await appsModel.stop(app.id);
if (error) {
toggleRunStateBusy.value = false;
console.error(error);
} else {
const [error] = await appsModel.stop(props.app.id);
if (error) return console.error(error);
setTimeout(() => toggleRunStateBusy.value = false, 3000);
}
setTimeout(() => toggleRunStateBusy.value = false, 2000);
}
async function onUninstall() {
@@ -105,7 +110,7 @@ onMounted(async () => {
:disabled="toggleRunStateBusy || app.taskId || (app.error && (app.error.details.installationState !== 'pending_start' && app.error.details.installationState !== 'pending_stop')) || app.installationState === 'pending_start' || app.installationState === 'pending_stop'"
:loading="toggleRunStateBusy || app.installationState === 'pending_start' || app.installationState === 'pending_stop'"
>
{{ $t(isAppStopped() ? 'app.uninstall.startStop.startAction' : 'app.uninstall.startStop.stopAction') }}
{{ $t(targetRunState() === TARGET_RUN_STATE.START ? 'app.uninstall.startStop.startAction' : 'app.uninstall.startStop.stopAction') }}
</Button>
</div>