Skip to content

Commit

Permalink
fix: issue with popover closing when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
jelveh committed Nov 12, 2024
1 parent 1adfe5c commit ac3317a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/gui/src/IPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const ipc_listener = async (event, handled) => {
// create html
h += `<div style="padding: 10px 10px 2px;">`;
h += `<div style="display:flex;">`;
h += `<input type="text" style="margin-bottom:10px;" class="social-url" readonly value="${html_encode(event.data.url)}"/>`;
h += `<input type="text" style="margin-bottom:10px; font-size: 13px;" class="social-url" readonly value="${html_encode(event.data.url)}"/>`;
h += `<button class="button copy-link" style="white-space:nowrap; text-align:center; white-space: nowrap; text-align: center; padding-left: 10px; padding-right: 10px; height: 33px; box-shadow: none; margin-left: 4px;">${(copy_icon)}</button>`;
h += `</div>`;

Expand All @@ -247,7 +247,8 @@ const ipc_listener = async (event, handled) => {
let po = await UIPopover({
content: h,
// snapToElement: this,
// parent_element: this,
parent_element: $el_parent_window,
parent_id: parent_window_id,
// width: 300,
height: 100,
left: event.data.options.left,
Expand All @@ -256,6 +257,8 @@ const ipc_listener = async (event, handled) => {
});

$(po).find('.copy-link').on('click', function(e){
e.preventDefault();
e.stopPropagation();
const url = $(po).find('.social-url').val();
navigator.clipboard.writeText(url);
// set checkmark
Expand All @@ -264,6 +267,8 @@ const ipc_listener = async (event, handled) => {
setTimeout(function(){
$(po).find('.copy-link').html(copy_icon)
}, 1000);

return false;
})
}

Expand Down Expand Up @@ -393,6 +398,13 @@ const ipc_listener = async (event, handled) => {
});
}
//--------------------------------------------------------
// mouseClicked
//--------------------------------------------------------
else if(event.data.msg === 'mouseClicked'){
// close all popovers whose parent_id is parent_window_id
$('.popover[data-parent_id="'+parent_window_id+'"]').remove();
}
//--------------------------------------------------------
// showDirectoryPicker
//--------------------------------------------------------
else if(event.data.msg === 'showDirectoryPicker'){
Expand Down Expand Up @@ -488,7 +500,6 @@ const ipc_listener = async (event, handled) => {
// update mouse position
update_mouse_position(x + window_position.left, y + window_position.top);
}

//--------------------------------------------------------
// contextMenu
//--------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/UI/UIPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function UIPopover(options){
options.content = options.content ?? '';

let h = '';
h += `<div id="popover-${window.global_element_id}" class="popover">`;
h += `<div id="popover-${window.global_element_id}" class="popover" ${options.parent_id && 'data-parent_id="'+html_encode(options.parent_id)+'"'}>`;
h += options.content;
h += `</div>`;

Expand Down
4 changes: 4 additions & 0 deletions src/gui/src/initgui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,10 @@ window.initgui = async function(options){

// if mouse is clicked on a window, activate it
if(window.mouseover_window !== undefined){
// if popover clicked on, don't activate window. This is because if an app
// is using the popover API to show a popover, the popover will be closed if the window is activated
if($(e.target).hasClass('popover') || $(e.target).parents('.popover').length > 0)
return;
$(window.mouseover_window).focusWindow(e);
}
})
Expand Down
15 changes: 15 additions & 0 deletions src/puter-js/src/modules/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,21 @@ class UI extends EventListener {
y: this.mouseY,
}, '*');
});

// click
document.addEventListener('click', async (event)=>{
// Get the mouse position from the event object
this.mouseX = event.clientX;
this.mouseY = event.clientY;

// send the mouse position to the host environment
this.messageTarget?.postMessage({
msg: "mouseClicked",
appInstanceID: this.appInstanceID,
x: this.mouseX,
y: this.mouseY,
}, '*');
})
}

onWindowClose = function(callback) {
Expand Down

0 comments on commit ac3317a

Please sign in to comment.