diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 67f9c83f82..37abd6592b 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -376,6 +376,27 @@ export const handleDownloadFiles = async () => { } } +export const handleDownloadWorkspace = async () => { + try { + const zip = new JSZip() + const workspaceProvider = plugin.fileProviders.workspace + await workspaceProvider.copyFolderToJson('/', ({ path, content }) => { + zip.file(path, content) + }) + zip.generateAsync({ type: 'blob' }).then(function (blob) { + const today = new Date() + const date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate() + const 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) + } +} + export const restoreBackupZip = async () => { await plugin.appManager.activatePlugin(['restorebackupzip']) await plugin.call('mainPanel', 'showContent', 'restorebackupzip') diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 04e91602ef..44783948be 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -33,6 +33,7 @@ export const FileSystemContext = createContext<{ dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise dispatchHandleExpandPath: (paths: string[]) => Promise, dispatchHandleDownloadFiles: () => Promise, + dispatchHandleDownloadWorkspace: () => Promise, dispatchHandleRestoreBackup: () => Promise dispatchCloneRepository: (url: string) => Promise, dispatchMoveFile: (src: string, dest: string) => Promise, diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index e05e92a7d2..ae038142a7 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -7,7 +7,7 @@ import { FileSystemContext } from '../contexts' import { browserReducer, browserInitialState } from '../reducers/workspace' import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, deleteAllWorkspaces, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder, deletePath, renamePath, downloadPath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace, - fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder, + fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadWorkspace, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder, showAllBranches, switchBranch, createNewBranch, checkoutRemoteBranch, createSolidityGithubAction, createTsSolGithubAction, createSlitherGithubAction } from '../actions' import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types' @@ -135,6 +135,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await handleDownloadFiles() } + const dispatchHandleDownloadWorkspace = async () => { + await handleDownloadWorkspace() + } + const dispatchHandleRestoreBackup = async () => { await restoreBackupZip() } @@ -284,6 +288,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => { dispatchHandleClickFile, dispatchHandleExpandPath, dispatchHandleDownloadFiles, + dispatchHandleDownloadWorkspace, dispatchHandleRestoreBackup, dispatchCloneRepository, dispatchMoveFile, diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 4539b13f68..f291304b2f 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -160,7 +160,11 @@ export function Workspace () { } const onFinishDownloadWorkspace = async () => { - console.log('inside onFinishDownloadWorkspace') + try { + await global.dispatchHandleDownloadWorkspace() + } catch (e) { + console.error(e) + } } const onFinishCreateWorkspace = async () => {