Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gui/src/IPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ const ipc_listener = async (event, handled) => {
type: res.type,
is_dir: false,
is_shared: res.is_shared,
workers: res.workers.length > 0 ? res.workers : [],
suggested_apps: res.suggested_apps,
});
// sort each window
Expand Down
2 changes: 2 additions & 0 deletions src/gui/src/UI/UIDesktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ async function UIDesktop (options) {
shortcut_to: fsentry.shortcut_to,
shortcut_to_path: fsentry.shortcut_to_path,
// has_website: $(el_item).attr('data-has_website') === '1',
workers: fsentry.workers.length > 0 ? fsentry.workers : [],
metadata: JSON.stringify(fsentry.metadata) ?? '',
});

Expand Down Expand Up @@ -674,6 +675,7 @@ async function UIDesktop (options) {
is_shortcut: item.is_shortcut,
shortcut_to: item.shortcut_to,
shortcut_to_path: item.shortcut_to_path,
workers: item.workers.length > 0 ? item.workers : [],
});

//sort each window
Expand Down
62 changes: 57 additions & 5 deletions src/gui/src/UI/UIItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const sendSelectionToAIApp = async ($elements) => {
}, '*');
};

function UIItem (options) {
async function UIItem (options) {
const matching_appendto_count = $(options.appendTo).length;
if ( matching_appendto_count > 1 ) {
$(options.appendTo).each(function () {
Expand Down Expand Up @@ -138,8 +138,9 @@ function UIItem (options) {
options.shortcut_to_path = options.shortcut_to_path ?? '';
options.immutable = (options.immutable === false || options.immutable === 0 || options.immutable === undefined ? 0 : 1);
options.sort_container_after_append = (options.sort_container_after_append !== undefined ? options.sort_container_after_append : false);
const is_shared_with_me = (options.path && options.path !== `/${window.user.username}` && !options.path.startsWith(`/${window.user.username}/`));

const is_shared_with_me = (options.path !== `/${window.user.username}` && !options.path.startsWith(`/${window.user.username}/`));
const is_worker = options.workers?.length > 0;
const worker_url = is_worker ? options.workers[0].address : '';
let website_url = window.determine_website_url(options.path);

// do a quick check to see if the target parent has any file type restrictions
Expand All @@ -165,6 +166,8 @@ function UIItem (options) {
data-website_url = "${website_url ? html_encode(website_url) : ''}"
data-immutable="${options.immutable}"
data-is_shortcut = "${options.is_shortcut}"
data-is_worker = "${is_worker ? 1 : 0}"
data-worker_url = "${is_worker ? worker_url : ''}"
data-shortcut_to = "${html_encode(options.shortcut_to)}"
data-shortcut_to_path = "${html_encode(options.shortcut_to_path)}"
data-sortable = "${options.sortable ?? 'true'}"
Expand Down Expand Up @@ -206,7 +209,7 @@ function UIItem (options) {
h += '<div class="item-badges">';
// website badge
h += `<img class="item-badge item-has-website-badge long-hover"
style="${options.has_website ? 'display:block;' : ''}"
style="${options.has_website && options.workers?.length === 0 ? 'display:block;' : ''}"
src="${html_encode(window.icons['world.svg'])}"
data-item-id="${item_id}"
>`;
Expand Down Expand Up @@ -240,7 +243,12 @@ function UIItem (options) {
data-item-id="${item_id}"
title="${i18n('item_shortcut')}"
>`;

// worker badge
h += `<img class="item-badge item-is-worker long-hover"
style="background-color: #ffffff; padding: 2px; ${is_worker ? 'display:block;' : ''}"
src="${html_encode(window.icons['worker.svg'])}"
data-item-id="${item_id}"
>`;
h += '</div>';

// divider
Expand Down Expand Up @@ -1880,6 +1888,50 @@ $(document).on('click', '.website-badge-popover-link', function (e) {
$(e.target).closest('.popover').remove();
});

$(document).on('long-hover', '.item-is-worker', function (e) {
const worker_url = e.target.parentNode.parentNode.getAttribute('data-worker_url');
var box = e.target.getBoundingClientRect();

var body = document.body;
var docEl = document.documentElement;

var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;

var clientTop = docEl.clientTop || body.clientTop || 0;
var clientLeft = docEl.clientLeft || body.clientLeft || 0;

var top = box.top + scrollTop - clientTop;
var left = box.left + scrollLeft - clientLeft;

if ( worker_url ) {
let h = '<div class="allow-user-select worker-badge-popover-content">';
h += `<div class="worker-badge-popover-title">${i18n('worker')}</div>`;
h += `
<a class="worker-badge-popover-link" href="${worker_url}" style="font-size:13px;" target="_blank">${worker_url.replace('https://', '')}</a>
<br>`;
h += '</div>';

// close other worker popovers
$('.worker-badge-popover-content').closest('.popover').remove();

// show a UIPopover with the worker URL
UIPopover({
target: e.target,
content: h,
snapToElement: e.target,
parent_element: e.target,
top: top - 30,
left: left + 20,
});
}
});

$(document).on('click', '.worker-badge-popover-link', function (e) {
// remove the parent popover
$(e.target).closest('.popover').remove();
});

// removes item(s)
$.fn.removeItems = async function (options) {
options = options || {};
Expand Down
15 changes: 11 additions & 4 deletions src/gui/src/UI/UIWindowItemProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function UIWindowItemProperties (item_name, item_path, item_uid, left, top
h += `<tr><td class="item-prop-label">${i18n('modified')}</td><td class="item-prop-val item-prop-val-modified"></td></tr>`;
h += `<tr><td class="item-prop-label">${i18n('created')}</td><td class="item-prop-val item-prop-val-created"></td></tr>`;
h += `<tr><td class="item-prop-label">${i18n('versions')}</td><td class="item-prop-val item-prop-val-versions"></td></tr>`;
h += `<tr><td class="item-prop-label">${i18n('worker')}</td><td class="item-prop-val item-prop-val-worker">`;
h += `<tr><td class="item-prop-label">${i18n('associated_websites')}</td><td class="item-prop-val item-prop-val-websites">`;
h += '</td></tr>';
h += `<tr><td class="item-prop-label">${i18n('access_granted_to')}</td><td class="item-prop-val item-prop-val-permissions"></td></tr>`;
Expand Down Expand Up @@ -109,7 +110,7 @@ async function UIWindowItemProperties (item_name, item_path, item_uid, left, top
returnVersions: true,
returnSize: true,
consistency: 'eventual',
success: function (fsentry) {
success: async function (fsentry) {
// hide versions tab if item is a directory
if ( fsentry.is_dir ) {
$(el_window).find('[data-tab="versions"]').hide();
Expand All @@ -134,7 +135,6 @@ async function UIWindowItemProperties (item_name, item_path, item_uid, left, top
// Ignored
}
}

// shortcut to
if ( fsentry.shortcut_to && fsentry.shortcut_to_path ) {
$(el_window).find('.item-prop-val-shortcut-to').text(fsentry.shortcut_to_path);
Expand Down Expand Up @@ -168,7 +168,14 @@ async function UIWindowItemProperties (item_name, item_path, item_uid, left, top
else {
$(el_window).find('.item-props-version-list').append('-');
}

// worker
if ( fsentry.path.endsWith('.js') ) {
const has_worker = fsentry.workers.length > 0;
if ( has_worker ) {
const worker_url = fsentry.workers[0].address;
$(el_window).find('.item-prop-val-worker').html(`<a target="_blank" href="${html_encode(worker_url)}">${html_encode(worker_url)}</a>`);
}
}
$(el_window).find('.disassociate-website-link').on('click', function (e) {
puter.hosting.update($(e.target).attr('data-subdomain'),
null).then(() => {
Expand All @@ -178,7 +185,7 @@ async function UIWindowItemProperties (item_name, item_path, item_uid, left, top
// remove the website badge from all instances of the dir
$(`.item[data-uid="${item_uid}"]`).find('.item-has-website-badge').fadeOut(200);
}
});
});
});
},
});
Expand Down
33 changes: 33 additions & 0 deletions src/gui/src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ span.header-sort-icon img {
filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 1));
}

.item-badge.item-is-worker {
border-radius: 50%;
background: white;
cursor: pointer;
}

.item-name, .item-name-editor, .item-name-shadow {
font-size: 12px;
color: white;
Expand Down Expand Up @@ -3908,6 +3914,33 @@ fieldset[name=number-code] {
text-decoration: underline;
}

.worker-badge-popover-title {
font-size: 14px;
margin: -10px;
margin-bottom: 5px;
padding: 8px 10px;
background: #e5e5e5;
color: #4b5f6f;
}

.worker-badge-popover-content {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width: 270px;
padding: 10px;
}

.worker-badge-popover-link, .worker-badge-popover-link:visited {
color: #0073ed;
text-decoration: none;
width: 179px;
}

.worker-badge-popover-link:hover {
text-decoration: underline;
}

/*!
* animate.css - https://animate.style/
* Version - 4.1.1
Expand Down
13 changes: 11 additions & 2 deletions src/gui/src/helpers/get_html_element_from_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const get_html_element_from_options = async function (options) {
options.immutable = (options.immutable === false || options.immutable === 0 || options.immutable === undefined ? 0 : 1);
options.sort_container_after_append = (options.sort_container_after_append !== undefined ? options.sort_container_after_append : false);
const is_shared_with_me = (options.path !== `/${window.user.username}` && !options.path.startsWith(`/${window.user.username}/`));

const workers = await puter.workers.list();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't use puter.workers.list() for one file, as it fetches all workers. You should ideally just use the same fsentry for this information (.workers array) but if you don't have access to that information and must fetch a singular file's workers, use await puter.fs.stat({path: "~/Desktop/New Worker.js", returnWorkers: true})

const is_worker = workers.find(w => w.file_path === options.path);
const worker_url = is_worker?.url;
let website_url = window.determine_website_url(options.path);

// do a quick check to see if the target parent has any file type restrictions
Expand All @@ -62,6 +64,8 @@ const get_html_element_from_options = async function (options) {
data-website_url = "${website_url ? html_encode(website_url) : ''}"
data-immutable="${options.immutable}"
data-is_shortcut = "${options.is_shortcut}"
data-is_worker = "${is_worker !== undefined ? 1 : 0}"
data-worker_url = "${is_worker !== undefined ? worker_url : 0}"
data-shortcut_to = "${html_encode(options.shortcut_to)}"
data-shortcut_to_path = "${html_encode(options.shortcut_to_path)}"
data-sortable = "${options.sortable ?? 'true'}"
Expand Down Expand Up @@ -137,7 +141,12 @@ const get_html_element_from_options = async function (options) {
data-item-id="${item_id}"
title="Shortcut"
>`;

// worker badge
h += `<img class="item-badge item-is-worker long-hover"
style="background-color: #ffffff; padding: 2px; ${is_worker ? 'display:block;' : ''}"
src="${html_encode(window.icons['worker.svg'])}"
data-item-id="${item_id}"
>`;
h += '</div>';

// name
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/helpers/refresh_item_container.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const refresh_item_container = function (el_item_container, options) {
is_shortcut: fsentry.is_shortcut,
shortcut_to: fsentry.shortcut_to,
shortcut_to_path: fsentry.shortcut_to_path,
workers: fsentry.workers.length > 0 ? fsentry.workers : [],
size: fsentry.size,
type: fsentry.type,
modified: fsentry.modified,
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/icons/worker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading