Merge pull request #176 from rubickCenter/feature/drag

Feature/drag
This commit is contained in:
璃白 2023-04-01 23:10:50 +08:00 committed by GitHub
commit 6f02359727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "rubick",
"version": "2.1.8",
"version": "2.1.9",
"author": "muwoo <2424880409@qq.com>",
"private": true,
"scripts": {

View File

@ -4,12 +4,20 @@ const useDrag = () => {
let animationId: number;
let mouseX: number;
let mouseY: number;
let clientWidth = 0;
let clientHeight = 0;
let draggable = true;
const onMouseDown = (e) => {
draggable = true;
mouseX = e.clientX;
mouseY = e.clientY;
if (Math.abs(document.body.clientWidth - clientWidth) > 5) {
clientWidth = document.body.clientWidth;
}
if (Math.abs(document.body.clientHeight - clientHeight) > 5) {
clientHeight = document.body.clientHeight;
}
document.addEventListener('mouseup', onMouseUp);
animationId = requestAnimationFrame(moveWindow);
};
@ -23,7 +31,7 @@ const useDrag = () => {
const moveWindow = () => {
ipcRenderer.send('msg-trigger', {
type: 'windowMoving',
data: { mouseX, mouseY },
data: { mouseX, mouseY, width: clientWidth, height: clientHeight },
});
if (draggable) animationId = requestAnimationFrame(moveWindow);
};

View File

@ -60,7 +60,7 @@ class API {
const { x, y } = screen.getCursorScreenPoint();
const originWindow = this.getCurrentWindow(window, e);
if (!originWindow) return;
originWindow.setBounds({ x: x - mouseX, y: y - mouseY });
originWindow.setBounds({ x: x - mouseX, y: y - mouseY, width, height });
}
public loadPlugin({ data: plugin }, window) {