Skip to content

Commit

Permalink
If items are dropped on the home directory of another user, try to sh…
Browse files Browse the repository at this point in the history
…are the items rather than copy/move
  • Loading branch information
jelveh committed Jun 20, 2024
1 parent 6f0706f commit 1c2ba76
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/UI/UIWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,40 @@ async function UIWindow(options) {
}
}

// --------------------------------------------------------
// if this is the home directory of another user, show the sharing dialog
// --------------------------------------------------------
let cur_path = $(el_window).attr('data-path');
if(countSubstr(cur_path, '/') === 1 && cur_path !== '/'+window.user.username){

Check failure on line 1394 in src/UI/UIWindow.js

View workflow job for this annotation

GitHub Actions / build

'countSubstr' is not defined
let username = cur_path.split('/')[1];

const items_to_share = []

// first item
items_to_share.push({
uid: $(ui.draggable).attr('data-uid'),
path: $(ui.draggable).attr('data-path'),
icon: $(ui.draggable).find('.item-icon img').attr('src'),
name: $(ui.draggable).find('.item-name').text(),
});

// all subsequent items
const cloned_items = document.getElementsByClassName('item-selected-clone');
for(let i =0; i<cloned_items.length; i++){
const source_item = document.getElementById('item-' + $(cloned_items[i]).attr('data-id'));
if(!source_item) continue;
items_to_share.push({
uid: $(source_item).attr('data-uid'),
path: $(source_item).attr('data-path'),
icon: $(source_item).find('.item-icon img').attr('src'),
name: $(source_item).find('.item-name').text(),
})
}

UIWindowShare(items_to_share, username);
return;
}

// If ctrl key is down, copy items. Except if target is Trash
if(e.ctrlKey && $(window.mouseover_window).attr('data-path') !== window.trash_path){
// Copy items
Expand Down
8 changes: 8 additions & 0 deletions src/UI/UIWindowShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ async function UIWindowShare(items, recipient){
perm_list += `<div style="float:right;"><span class="remove-permission-link remove-permission-icon" data-recipient-username="${recipient_username}" data-permission="${perm_id}">✕</span></div>`;
perm_list += `</div>`;

// reset input
$(el_window).find('.error').hide();
$(el_window).find('.access-recipient').val('');

// disable 'Give Access' button
$(el_window).find('.give-access-btn').prop('disabled', true);

// append recipient to list
$(el_window).find('.share-recipients').append(`${perm_list}`);

Expand All @@ -246,6 +253,7 @@ async function UIWindowShare(items, recipient){
contacts.push(recipient_username);
puter.kv.set('contacts', JSON.stringify(contacts));
}

},
error: function(err) {
// at this point 'username_not_found' and 'shared_with_self' are the only
Expand Down
18 changes: 17 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2380,4 +2380,20 @@ window.set_menu_item_prop = (items, item_id, prop, val) => {
set_menu_item_prop(item.items, item_id, prop, val);
}
}
};
};

window.countSubstr = (str, substring)=>{
if (substring.length === 0) {
return 0;
}

let count = 0;
let pos = str.indexOf(substring);

while (pos !== -1) {
count++;
pos = str.indexOf(substring, pos + 1);
}

return count;
}

0 comments on commit 1c2ba76

Please sign in to comment.