From 46bed7fc34d5488476fbc95dd3a605514e3a95c2 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Fri, 24 Nov 2023 15:25:45 -0300 Subject: [PATCH] Add proper alert with information about the recovered video files --- src/stores/video.ts | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/stores/video.ts b/src/stores/video.ts index 5243fd643..0d534fd93 100644 --- a/src/stores/video.ts +++ b/src/stores/video.ts @@ -2,6 +2,7 @@ import { useStorage } from '@vueuse/core' import { saveAs } from 'file-saver' import localforage from 'localforage' import { defineStore } from 'pinia' +import Swal from 'sweetalert2' import { reactive } from 'vue' export const useVideoStore = defineStore('video', () => { @@ -17,12 +18,34 @@ export const useVideoStore = defineStore('video', () => { description: 'Local backups of Cockpit video recordings to be retrieved in case of failure.', }) - cockpitVideoDB.iterate((videoFile, videoName) => { - const blob = (videoFile as Blob[]).reduce((a, b) => new Blob([a, b], { type: 'video/webm' })) - saveAs(blob, videoName) - }) - cockpitVideoDB.iterate((_, videoName) => { - cockpitVideoDB.removeItem(videoName) + cockpitVideoDB.length().then((len) => { + if (len === 0) return + + Swal.fire({ + title: 'Video recording recovery', + text: `Cockpit has pending backups for videos that you started recording but did not download. + Click 'Discard' to remove the backuped files. + Click 'Dismiss' to postpone this decision for the next boot. + Click 'Download' to download the files. If you decide to download them, they will be removed afterwards. + `, + icon: 'warning', + showDenyButton: true, + showCancelButton: true, + confirmButtonText: 'Download', + denyButtonText: 'Discard', + cancelButtonText: 'Dismiss', + }).then((decision) => { + if (decision.isDismissed) return + if (decision.isDenied) { + cockpitVideoDB.iterate((_, videoName) => cockpitVideoDB.removeItem(videoName)) + } else if (decision.isConfirmed) { + cockpitVideoDB.iterate((videoFile, videoName) => { + const blob = (videoFile as Blob[]).reduce((a, b) => new Blob([a, b], { type: 'video/webm' })) + saveAs(blob, videoName) + }) + cockpitVideoDB.iterate((_, videoName) => cockpitVideoDB.removeItem(videoName)) + } + }) }) return { availableIceIps, allowedIceIps }