From e8e9c6916081f3592bc4b05657a36cb8c0d8156a Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Tue, 24 Oct 2023 16:21:33 -0300 Subject: [PATCH] Try to prevent user from closing Cockpit during video record --- .../mini-widgets/MiniVideoRecorder.vue | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/components/mini-widgets/MiniVideoRecorder.vue b/src/components/mini-widgets/MiniVideoRecorder.vue index acafe9b8e..820496e2c 100644 --- a/src/components/mini-widgets/MiniVideoRecorder.vue +++ b/src/components/mini-widgets/MiniVideoRecorder.vue @@ -248,6 +248,31 @@ watch(externalStreams, () => { updateCurrentStream(savedStream) } }) + +// Try to prevent user from closing Cockpit when a stream is being recorded +const onBeforeUnloadHandler = (): string => { + const alertMsg = ` + You have a video recording ongoing. + Remember to stop it before closing Cockpit, or the record will be lost. + ` + Swal.fire({ text: alertMsg, icon: 'warning' }) + return 'I hope the user does not clicl on the leave button.' +} + +watch(isRecording, () => { + if (isRecording.value) { + window.onbeforeunload = () => { + const alertMsg = ` + You have a video recording ongoing. + Remember to stop it before closing Cockpit, or the record will be lost. + ` + Swal.fire({ text: alertMsg, icon: 'warning' }) + return 'I hope the user does not clicl on the leave button.' + } + } else { + window.onbeforeunload = null + } +})