Do not use watcher on value change for recovery mode switch but an explicit action handler

This commit is contained in:
Johannes Zellner
2025-05-02 16:40:05 +02:00
parent 8939f0dad7
commit be10718dfc

View File

@@ -1,6 +1,6 @@
<script setup>
import { ref, onMounted, watch, useTemplateRef } from 'vue';
import { ref, onMounted, useTemplateRef } from 'vue';
import { Button, Switch } from 'pankow';
import { taskNameFromInstallationState } from '../../utils.js';
import AppRepairDialog from '../AppRepairDialog.vue';
@@ -11,16 +11,26 @@ const props = defineProps([ 'app' ]);
const appsModel = AppsModel.create();
const busyRestart = ref(false);
const debugMode = ref(false);
const debugModeBusy = ref(false);
async function onDebugMode(newValue) {
debugModeBusy.value = true;
watch(debugMode, async (newValue) => {
const data = newValue ? {
readonlyRootfs: false,
cmd: [ '/bin/bash', '-c', 'echo "Repair mode. Use the webterminal or cloudron exec to repair. Sleeping" && sleep infinity' ]
} : null;
const [error] = await appsModel.configure(props.app.id, 'debug_mode', { debugMode: data });
if (error) return console.error(error);
});
if (error) {
debugModeBusy.value = false;
debugMode.value = !newValue;
return console.error(error);
}
// let the task start
setTimeout(() => { debugModeBusy.value = false; }, 2000);
}
const repairDialog = useTemplateRef('repairDialog');
async function onRepair() {
@@ -50,7 +60,7 @@ onMounted(() => {
<p v-html="$t('app.repair.recovery.description', { docsLink: 'https://docs.cloudron.io/troubleshooting/#unresponsive-app' })"></p>
<div style="display: flex; justify-content: space-between;">
<Switch v-model="debugMode" :disabled="app.error || app.taskId" v-tooltip="app.taskId ? (app.error ? 'App is in error state' : 'App is busy') : ''" label="Recovery Mode"/>
<Switch v-model="debugMode" @change="onDebugMode" :disabled="debugModeBusy || app.error || app.taskId" v-tooltip="app.taskId ? (app.error ? 'App is in error state' : 'App is busy') : ''" label="Recovery Mode"/>
<Button @click="onRestart()" :disabled="busyRestart || app.taskId || app.error || app.installationState === 'pending_restart'" :loading="busyRestart || app.installationState === 'pending_restart'" v-tooltip="app.error ? 'App is in error state' : (app.taskId ? 'App is busy' : '')">{{ $t('app.repair.recovery.restartAction') }}</Button>
</div>