From c2c87bf0bafdc8df1628a14f5aa3ef77f96c754a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 9 May 2024 15:52:38 +0100 Subject: [PATCH] refactor: Replace UIWindowDownloadDirProg with UIWindowProgress --- src/UI/UIWindowDownloadDirProg.js | 70 ------------------------------- src/helpers.js | 18 ++++---- src/i18n/translations/en.js | 2 + 3 files changed, 11 insertions(+), 79 deletions(-) delete mode 100644 src/UI/UIWindowDownloadDirProg.js diff --git a/src/UI/UIWindowDownloadDirProg.js b/src/UI/UIWindowDownloadDirProg.js deleted file mode 100644 index 9068fc88..00000000 --- a/src/UI/UIWindowDownloadDirProg.js +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (C) 2024 Puter Technologies Inc. - * - * This file is part of Puter. - * - * Puter is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import UIWindow from './UIWindow.js' - -async function UIWindowDownloadDirProg(options){ - options = options ?? {}; - - let h = ''; - // Loading spinner - h +=`circle anim`; - h += `

${options.defaultText ?? i18n('preparing')}

`; - - const el_window = await UIWindow({ - title: 'Download Directory Progress', - app: 'instant-login', - single_instance: true, - icon: null, - uid: null, - is_dir: false, - body_content: h, - has_head: false, - selectable_body: false, - allow_context_menu: false, - is_resizable: false, - is_droppable: false, - init_center: true, - allow_native_ctxmenu: false, - allow_user_select: false, - backdrop: false, - width: 460, - height: 'auto', - dominant: true, - show_in_taskbar: false, - draggable_body: true, - onAppend: function(this_window){ - }, - window_class: 'window-qr', - body_css: { - width: 'initial', - height: '100px', - 'background-color': 'rgb(245 247 249)', - 'backdrop-filter': 'blur(3px)', - 'display': 'flex', - "flex-direction": 'row', - 'justify-content': 'center', - 'align-items': 'center', - } - }) - - return el_window; -} - -export default UIWindowDownloadDirProg \ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js index 5c8ed123..77c8abe3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -27,7 +27,6 @@ import UIWindowSaveAccount from './UI/UIWindowSaveAccount.js'; import update_username_in_gui from './helpers/update_username_in_gui.js'; import update_title_based_on_uploads from './helpers/update_title_based_on_uploads.js'; import content_type_to_icon from './helpers/content_type_to_icon.js'; -import UIWindowDownloadDirProg from './UI/UIWindowDownloadDirProg.js'; import { PROCESS_RUNNING, PortalProcess, PseudoProcess } from "./definitions.js"; import UIWindowProgress from './UI/UIWindowProgress.js'; @@ -2965,14 +2964,14 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { let progwin, progwin_timeout; // only show progress window if it takes longer than 500ms to download progwin_timeout = setTimeout(async () => { - progwin = await UIWindowDownloadDirProg(); + progwin = await UIWindowProgress(); }, 500); for (const el_item of el_items) { let targetPath = $(el_item).attr('data-path'); // if directory, zip the directory if($(el_item).attr('data-is_dir') === '1'){ - $(progwin).find('.dir-dl-status').html(`Reading ${html_encode(targetPath)}`); + progwin?.set_status(i18n('reading_file', targetPath)); // Recursively read the directory let children = await readDirectoryRecursive(targetPath); @@ -2985,7 +2984,7 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { relativePath = path.basename(targetPath) + '/' + child.relativePath; // update progress window - $(progwin).find('.dir-dl-status').html(`Zipping ${html_encode(relativePath)}`); + progwin?.set_status(i18n('zipping_file', relativePath)); // read file content let content = await puter.fs.read(child.path); @@ -3034,17 +3033,18 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { // close progress window clearTimeout(progwin_timeout); setTimeout(() => { - $(progwin).close(); + progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); }) .catch(function (err) { // close progress window clearTimeout(progwin_timeout); setTimeout(() => { - $(progwin).close(); + progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); // handle errors + // TODO: Display in progress dialog console.error("Error in zipping files: ", err); }); } @@ -3087,7 +3087,7 @@ window.unzipItem = async function(itemPath) { let progwin, progwin_timeout; // only show progress window if it takes longer than 500ms to download progwin_timeout = setTimeout(async () => { - progwin = await UIWindowDownloadDirProg(); + progwin = await UIWindowProgress(); }, 500); const zip = new JSZip(); @@ -3109,7 +3109,7 @@ window.unzipItem = async function(itemPath) { // close progress window clearTimeout(progwin_timeout); setTimeout(() => { - $(progwin).close(); + progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); }).catch(function (e) { @@ -3117,7 +3117,7 @@ window.unzipItem = async function(itemPath) { // close progress window clearTimeout(progwin_timeout); setTimeout(() => { - $(progwin).close(); + progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); }) } diff --git a/src/i18n/translations/en.js b/src/i18n/translations/en.js index e31875aa..14ca930f 100644 --- a/src/i18n/translations/en.js +++ b/src/i18n/translations/en.js @@ -198,6 +198,7 @@ const en = { publish_as_website: 'Publish as website', puter_description: `Puter is a privacy-first personal cloud to keep all your files, apps, and games in one secure place, accessible from anywhere at any time.`, + reading_file: "Reading %strong%", recent: "Recent", recommended: "Recommended", recover_password: "Recover Password", @@ -281,6 +282,7 @@ const en = { yes_release_it: 'Yes, Release It', you_have_been_referred_to_puter_by_a_friend: "You have been referred to Puter by a friend!", zip: "Zip", + zipping_file: "Zipping %strong%", // === 2FA Setup === setup2fa_1_step_heading: 'Open your authenticator app',