Files
cloudron-box/dashboard/src/components/app/Repair.vue
T
2025-08-13 13:34:45 +02:00

82 lines
2.8 KiB
Vue

<script setup>
import { ref, onMounted } from 'vue';
import { Button, Switch } from '@cloudron/pankow';
import { taskNameFromInstallationState } from '../../utils.js';
import { ISTATES } from '../../constants.js';
import AppsModel from '../../models/AppsModel.js';
const props = defineProps([ 'app' ]);
const appsModel = AppsModel.create();
const busyRepair = ref(false);
const busyRestart = ref(false);
const debugMode = ref(false);
const debugModeBusy = ref(false);
async function onDebugMode(newValue) {
debugModeBusy.value = true;
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) {
debugModeBusy.value = false;
debugMode.value = !newValue;
return console.error(error);
}
// let the task start
setTimeout(() => { debugModeBusy.value = false; }, 4000);
}
async function onRepair() {
busyRepair.value = true;
const [error] = await appsModel.repair(props.app.id, {});
if (error) {
console.error(error);
busyRepair.value = false;
return;
}
setTimeout(() => { busyRepair.value = false; }, 4000);
}
async function onRestart() {
busyRestart.value = true;
const [error] = await appsModel.restart(props.app.id);
if (error) console.error(error);
busyRestart.value = false;
}
onMounted(() => {
debugMode.value = !!props.app.debugMode;
});
</script>
<template>
<div>
<label>{{ $t('app.repair.recovery.title') }}</label>
<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" @change="onDebugMode" :disabled="debugModeBusy || (app.error && app.error.details.installationState !== ISTATES.PENDING_DEBUG) || app.taskId" label="Recovery Mode"/>
<Button @click="onRestart()" :disabled="busyRestart || app.taskId || !!app.error" :loading="busyRestart || app.installationState === 'pending_restart'">{{ $t('app.repair.recovery.restartAction') }}</Button>
</div>
<hr/>
<label>{{ $t('app.repair.taskError.title') }}</label>
<p>{{ $t('app.repair.taskError.description') }}</p>
<p v-if="app.error">An error occurred during the <b>{{ taskNameFromInstallationState(app.error.details.installationState) }}</b> operation: <span class="text-danger"><b>{{ app.error.reason + ': ' + app.error.message }}</b></span></p>
<Button @click="onRepair()" :disabled="busyRepair || app.taskId || !app.error" :loading="busyRepair">{{ $t('app.repair.taskError.retryAction', { task: app.error ? taskNameFromInstallationState(app.error.details.installationState) : '' }) }}</Button>
</div>
</template>