Desktop support (#4484)
* Remove home link on desktop app * Spellcheck, installation toasts, background styling, … * Add email,slack, auth support * More desktop style tweaks * Move redirect to client * cleanup * Record desktop usage * docs * fix: Selection state in search input when double clicking header
This commit is contained in:
46
app/hooks/useDesktopTitlebar.ts
Normal file
46
app/hooks/useDesktopTitlebar.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from "react";
|
||||
import Desktop from "~/utils/Desktop";
|
||||
|
||||
export const useDesktopTitlebar = () => {
|
||||
React.useEffect(() => {
|
||||
if (!Desktop.isElectron()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleDoubleClick = (event: MouseEvent) => {
|
||||
// Ignore double clicks on interactive elements such as inputs and buttons
|
||||
if (event.composedPath().some(elementIsInteractive)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if the mouse position is further down than the header height
|
||||
if (event.clientY > 64) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
Desktop.bridge.onTitlebarDoubleClick();
|
||||
};
|
||||
|
||||
window.addEventListener("dblclick", handleDoubleClick);
|
||||
return () => window.removeEventListener("dblclick", handleDoubleClick);
|
||||
}, []);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if an element is user interactive.
|
||||
*
|
||||
* @param target HTML element
|
||||
* @returns boolean
|
||||
*/
|
||||
function elementIsInteractive(target: EventTarget) {
|
||||
return (
|
||||
target &&
|
||||
target instanceof HTMLElement &&
|
||||
(target instanceof HTMLSelectElement ||
|
||||
target instanceof HTMLInputElement ||
|
||||
target instanceof HTMLButtonElement ||
|
||||
target.getAttribute("role") === "button" ||
|
||||
target.getAttribute("role") === "textarea")
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user