Skip to content

Commit

Permalink
delaying progress window for quick move/copy operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vineeth-vk11 committed Mar 10, 2024
1 parent 440e832 commit 2afb1a2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ window.default_taskbar_height = 50;
window.taskbar_height = window.default_taskbar_height;
window.upload_progress_hide_delay = 500;
window.active_uploads = {};
window.copy_progress_hide_delay = 1000;
window.copy_progress_hide_delay = 2000;
window.busy_indicator_hide_delay = 600;
window.global_element_id = 0;
window.operation_id = 0;
Expand Down
45 changes: 34 additions & 11 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,13 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){
let overwrite_all = false;
(async()=>{
let copy_progress_window_init_ts = Date.now();
let progwin = await UIWindowCopyProgress({operation_id: copy_op_id});

// only show progress window if it takes longer than 2s to copy
let progwin;
let progwin_timeout = setTimeout(async () => {
progwin = await UIWindowCopyProgress({operation_id: copy_op_id});
}, 2000);

for(let i=0; i<clipboard.length; i++){
let copy_path = clipboard[i].path;
let item_with_same_name_already_exists = true;
Expand Down Expand Up @@ -1531,10 +1537,12 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){
}

// done
clearTimeout(progwin_timeout);

let copy_duration = (Date.now() - copy_progress_window_init_ts);
if( copy_duration >= copy_progress_hide_delay){
if(progwin && copy_duration >= copy_progress_hide_delay){
$(progwin).close();
}else{
}else if(progwin){
setTimeout(() => {
setTimeout(() => {
$(progwin).close();
Expand All @@ -1555,7 +1563,13 @@ window.copy_items = function(el_items, dest_path){
let overwrite_all = false;
(async()=>{
let copy_progress_window_init_ts = Date.now();
let progwin = await UIWindowCopyProgress({operation_id: copy_op_id});

// only show progress window if it takes longer than 2s to copy
let progwin;
let progwin_timeout = setTimeout(async () => {
progwin = await UIWindowCopyProgress({operation_id: copy_op_id});
}, 2000);

for(let i=0; i < el_items.length; i++){
let copy_path = $(el_items[i]).attr('data-path');
let item_with_same_name_already_exists = true;
Expand Down Expand Up @@ -1612,10 +1626,12 @@ window.copy_items = function(el_items, dest_path){
}

// done
clearTimeout(progwin_timeout);

let copy_duration = (Date.now() - copy_progress_window_init_ts);
if( copy_duration >= copy_progress_hide_delay){
if(progwin && copy_duration >= copy_progress_hide_delay){
$(progwin).close();
}else{
}else if(progwin){
setTimeout(() => {
setTimeout(() => {
$(progwin).close();
Expand Down Expand Up @@ -2250,8 +2266,11 @@ window.move_items = async function(el_items, dest_path){
// when did this operation start
let move_init_ts = Date.now();

// create progress window
let progwin = await UIWindowMoveProgress({operation_id: move_op_id});
// only show progress window if it takes longer than 2s to move
let progwin;
let progwin_timeout = setTimeout(async () => {
progwin = await UIWindowMoveProgress({operation_id: move_op_id});
}, 2000);

// Go through each item and try to move it
for(let i=0; i<el_items.length; i++){
Expand Down Expand Up @@ -2597,16 +2616,20 @@ window.move_items = async function(el_items, dest_path){
}
}

clearTimeout(progwin_timeout);

// log stats to console
let move_duration = (Date.now() - move_init_ts);
console.log(`moved ${el_items.length} item${el_items.length > 1 ? 's':''} in ${move_duration}ms`);

// -----------------------------------------------------------------------
// DONE! close progress window with delay to allow user to see 100% progress
// -----------------------------------------------------------------------
setTimeout(() => {
$(progwin).close();
}, copy_progress_hide_delay);
if(progwin){
setTimeout(() => {
$(progwin).close();
}, copy_progress_hide_delay);
}
}

/**
Expand Down

0 comments on commit 2afb1a2

Please sign in to comment.