yeah, sorry, but there is an alternative that works with a few limitations:
example of a titlebar in react-ts which sends the mouse movement once dragging starts:
function Header({ leading, navigation, following }: HeaderProps) {
const navigate = useNavigate();
const [, startTransition] = useTransition();
const [dragging, setDragging] = useState(false);
return (
<div
className="titleBar"
onMouseDown={() => {
setDragging(true);
}}
onMouseUp={() => {
setDragging(false);
}}
onMouseLeave={() => {
setDragging(false);
}}
onMouseMove={(e) => {
if (dragging) {
window.electron.ipcRenderer.sendMessage(
'window',
'move',
e.movementX,
e.movementY
);
}
}}
>
<div className="flexrow_start">
{leading}
<div>
{navigation.map((info, index) => (
<button
type="button"
onClick={(e) => {
e.preventDefault();
startTransition(() => {
navigate(info.destination ?? '/');
});
}}
key={index}
>
{info.content}
</button>
))}
</div>
</div>
{following !== undefined && (
<div className="flexrow_end"> {following}</div>
)}
</div>
);
}
in main.ts:
ipcMain.on('window', (e, arg, arg2, arg3) => {
switch (arg as string) {
// comes from element added to header as element following routes
case 'min':
mainWindow?.minimize();
break;
// comes from element added to header as element following routes
case 'max':
if (mainWindow?.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow?.maximize();
}
break;
// comes from element added to header as element following routes
case 'close':
app.quit();
break;
//header element dragging handler
case 'move':
console.log(arg2, arg3);
mainWindow?.setPosition(
mainWindow.getPosition()[0] + arg2,
mainWindow.getPosition()[1] + arg3
);
break;
default:
break;
}
});
.titleBar{
height: 50px;
display: flex;
justify-content: space-between;
}
.titleBar:hover{
cursor: grab;
}
EDIT: it doesn't work well when you move the electron app between displays. If anyone has a solution for that, I would be very gratreful for a comment