From 6d1df98d1328937fdc1093a3b95a680e6ecefb7a Mon Sep 17 00:00:00 2001
From: yann300
Date: Mon, 24 Jan 2022 11:09:06 +0100
Subject: [PATCH] add download backup in homepage
---
.../home-tab/src/lib/remix-ui-home-tab.tsx | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx
index 1d0f594f74..5f1b8f6f87 100644
--- a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx
+++ b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx
@@ -1,6 +1,7 @@
import React, { useState, useRef, useEffect, useReducer } from 'react' // eslint-disable-line
import './remix-ui-home-tab.css'
+import JSZip from 'jszip'
import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line
import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
import PluginButton from './components/pluginButton' // eslint-disable-line
@@ -175,6 +176,43 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => {
const startPluginManager = async () => {
plugin.verticalIcons.select('pluginManager')
}
+ const saveAs = (blob, name) => {
+ const node = document.createElement('a')
+ node.download = name
+ node.rel = 'noopener'
+ node.href = URL.createObjectURL(blob)
+ setTimeout(function () { URL.revokeObjectURL(node.href) }, 4E4) // 40s
+ setTimeout(function () {
+ try {
+ node.dispatchEvent(new MouseEvent('click'))
+ } catch (e) {
+ var evt = document.createEvent('MouseEvents')
+ evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80,
+ 20, false, false, false, false, 0, null)
+ node.dispatchEvent(evt)
+ }
+ }, 0) // 40s
+ }
+ const downloadFiles = async () => {
+ try {
+ plugin.call('notification', 'toast', 'preparing files for download, please wait..')
+ const zip = new JSZip()
+ const browserProvider = fileManager.getProvider('browser')
+ await browserProvider.copyFolderToJson('/', ({ path, content }) => {
+ zip.file(path, content)
+ })
+ zip.generateAsync({ type: 'blob' }).then(function (blob) {
+ var today = new Date()
+ var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
+ var time = today.getHours() + 'h' + today.getMinutes() + 'min'
+ saveAs(blob, `remix-backup-at-${time}-${date}.zip`)
+ }).catch((e) => {
+ plugin.call('notification', 'toast', e.message)
+ })
+ } catch (e) {
+ plugin.call('notification', 'toast', e.message)
+ }
+ }
const showFullMessage = (title: string, loadItem: string, examples: Array) => {
setState(prevState => {
@@ -279,6 +317,10 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => {
+
+
+
+