Skip to content

Commit ac3317a

Browse files
committed
fix: issue with popover closing when clicked
1 parent 1adfe5c commit ac3317a

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/gui/src/IPC.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const ipc_listener = async (event, handled) => {
231231
// create html
232232
h += `<div style="padding: 10px 10px 2px;">`;
233233
h += `<div style="display:flex;">`;
234-
h += `<input type="text" style="margin-bottom:10px;" class="social-url" readonly value="${html_encode(event.data.url)}"/>`;
234+
h += `<input type="text" style="margin-bottom:10px; font-size: 13px;" class="social-url" readonly value="${html_encode(event.data.url)}"/>`;
235235
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>`;
236236
h += `</div>`;
237237

@@ -247,7 +247,8 @@ const ipc_listener = async (event, handled) => {
247247
let po = await UIPopover({
248248
content: h,
249249
// snapToElement: this,
250-
// parent_element: this,
250+
parent_element: $el_parent_window,
251+
parent_id: parent_window_id,
251252
// width: 300,
252253
height: 100,
253254
left: event.data.options.left,
@@ -256,6 +257,8 @@ const ipc_listener = async (event, handled) => {
256257
});
257258

258259
$(po).find('.copy-link').on('click', function(e){
260+
e.preventDefault();
261+
e.stopPropagation();
259262
const url = $(po).find('.social-url').val();
260263
navigator.clipboard.writeText(url);
261264
// set checkmark
@@ -264,6 +267,8 @@ const ipc_listener = async (event, handled) => {
264267
setTimeout(function(){
265268
$(po).find('.copy-link').html(copy_icon)
266269
}, 1000);
270+
271+
return false;
267272
})
268273
}
269274

@@ -393,6 +398,13 @@ const ipc_listener = async (event, handled) => {
393398
});
394399
}
395400
//--------------------------------------------------------
401+
// mouseClicked
402+
//--------------------------------------------------------
403+
else if(event.data.msg === 'mouseClicked'){
404+
// close all popovers whose parent_id is parent_window_id
405+
$('.popover[data-parent_id="'+parent_window_id+'"]').remove();
406+
}
407+
//--------------------------------------------------------
396408
// showDirectoryPicker
397409
//--------------------------------------------------------
398410
else if(event.data.msg === 'showDirectoryPicker'){
@@ -488,7 +500,6 @@ const ipc_listener = async (event, handled) => {
488500
// update mouse position
489501
update_mouse_position(x + window_position.left, y + window_position.top);
490502
}
491-
492503
//--------------------------------------------------------
493504
// contextMenu
494505
//--------------------------------------------------------

src/gui/src/UI/UIPopover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function UIPopover(options){
3030
options.content = options.content ?? '';
3131

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

src/gui/src/initgui.js

+4
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,10 @@ window.initgui = async function(options){
12251225

12261226
// if mouse is clicked on a window, activate it
12271227
if(window.mouseover_window !== undefined){
1228+
// if popover clicked on, don't activate window. This is because if an app
1229+
// is using the popover API to show a popover, the popover will be closed if the window is activated
1230+
if($(e.target).hasClass('popover') || $(e.target).parents('.popover').length > 0)
1231+
return;
12281232
$(window.mouseover_window).focusWindow(e);
12291233
}
12301234
})

src/puter-js/src/modules/UI.js

+15
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,21 @@ class UI extends EventListener {
530530
y: this.mouseY,
531531
}, '*');
532532
});
533+
534+
// click
535+
document.addEventListener('click', async (event)=>{
536+
// Get the mouse position from the event object
537+
this.mouseX = event.clientX;
538+
this.mouseY = event.clientY;
539+
540+
// send the mouse position to the host environment
541+
this.messageTarget?.postMessage({
542+
msg: "mouseClicked",
543+
appInstanceID: this.appInstanceID,
544+
x: this.mouseX,
545+
y: this.mouseY,
546+
}, '*');
547+
})
533548
}
534549

535550
onWindowClose = function(callback) {

0 commit comments

Comments
 (0)