From 1c2ba76db28404a0c5a1cd67607c1becb1c59b59 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Thu, 20 Jun 2024 14:06:43 -0700 Subject: [PATCH] If items are dropped on the home directory of another user, try to share the items rather than copy/move --- src/UI/UIWindow.js | 34 ++++++++++++++++++++++++++++++++++ src/UI/UIWindowShare.js | 8 ++++++++ src/helpers.js | 18 +++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/UI/UIWindow.js b/src/UI/UIWindow.js index a4bc5fccd7..16ad79f3ba 100644 --- a/src/UI/UIWindow.js +++ b/src/UI/UIWindow.js @@ -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){ + 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`; perm_list += ``; + // 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}`); @@ -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 diff --git a/src/helpers.js b/src/helpers.js index 773e8281ef..e8f6fdb2c7 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -2380,4 +2380,20 @@ window.set_menu_item_prop = (items, item_id, prop, val) => { set_menu_item_prop(item.items, item_id, prop, val); } } -}; \ No newline at end of file +}; + +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; +}