Refactor openGlance method to accept target element and send relevant data

This commit is contained in:
mr. M 2024-10-28 16:59:34 +01:00
parent a942043645
commit 416369c981
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB
3 changed files with 32 additions and 9 deletions

View file

@ -21,10 +21,15 @@
} }
observe(subject, topic, data) { observe(subject, topic, data) {
this.openGlance(data); this.openGlance(JSON.parse(data));
} }
openGlance(url) { openGlance(data) {
const initialX = data.x;
const initialY = data.y;
const initialWidth = data.width;
const initialHeight = data.height;
const url = data.url;
if (this.#currentBrowser) { if (this.#currentBrowser) {
return; return;
} }
@ -33,6 +38,11 @@
overlayWrapper.appendChild(this.overlay); overlayWrapper.appendChild(this.overlay);
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
this.browserWrapper.style.setProperty("--initial-x", `${initialX}px`);
this.browserWrapper.style.setProperty("--initial-y", `${initialY}px`);
this.browserWrapper.style.setProperty("--initial-width", initialWidth + "px");
this.browserWrapper.style.setProperty("--initial-height", initialHeight + "px");
this.overlay.removeAttribute("fade-out");
this.overlay.removeAttribute("hidden"); this.overlay.removeAttribute("hidden");
}); });
} }
@ -41,7 +51,13 @@
this.#currentBrowser?.remove(); this.#currentBrowser?.remove();
this.#currentBrowser = null; this.#currentBrowser = null;
this.overlay.setAttribute("hidden", true); window.requestAnimationFrame(() => {
this.overlay.setAttribute("fade-out", true);
setTimeout(() => {
this.overlay.setAttribute("hidden", true);
this.overlay.removeAttribute("fade-out");
}, 800);
});
} }
onLocationChange(_) { onLocationChange(_) {

View file

@ -55,8 +55,15 @@ export class ZenGlanceChild extends JSWindowActorChild {
return !(event.ctrlKey ^ event.altKey ^ event.shiftKey); return !(event.ctrlKey ^ event.altKey ^ event.shiftKey);
} }
openGlance(url) { openGlance(target) {
this.sendAsyncMessage('ZenGlance:OpenGlance', { url }); const rect = target.getBoundingClientRect();
this.sendAsyncMessage('ZenGlance:OpenGlance', {
url: target.href,
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height,
});
} }
handleMouseUp(event) { handleMouseUp(event) {
@ -71,7 +78,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
const hoverActivationDelay = await this.getHoverActivationDelay(); const hoverActivationDelay = await this.getHoverActivationDelay();
setTimeout(() => { setTimeout(() => {
if (this.mouseIsDown) { if (this.mouseIsDown) {
this.openGlance(event.target.href); this.openGlance(event.target);
} }
}, hoverActivationDelay); }, hoverActivationDelay);
} }
@ -96,7 +103,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
this.openGlance(target.href); this.openGlance(target);
} }
} }
} }

View file

@ -12,13 +12,13 @@ export class ZenGlanceParent extends JSWindowActorParent {
return Services.prefs.getIntPref('zen.glance.hold-duration', 500); return Services.prefs.getIntPref('zen.glance.hold-duration', 500);
} }
case 'ZenGlance:OpenGlance': { case 'ZenGlance:OpenGlance': {
this.openGlance(message.data.url); this.openGlance(message.data);
break; break;
} }
} }
} }
openGlance(data) { openGlance(data) {
Services.obs.notifyObservers(null, 'zen-glance-open', data); Services.obs.notifyObservers(null, 'zen-glance-open', JSON.stringify(data));
} }
} }