Skip to content

Commit

Permalink
fix windows freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
cordx56 committed Jan 23, 2025
1 parent 2c346e0 commit af655b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/ModelView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useRef, useState, useEffect, MouseEventHandler } from "react";
import { useParams } from "react-router-dom";
import { listen } from "@tauri-apps/api/event";
import { appWindow, currentMonitor, getAll } from "@tauri-apps/api/window";
import {
appWindow,
currentMonitor,
getAll,
LogicalPosition,
} from "@tauri-apps/api/window";
import { VRM, VRMHumanBoneName } from "@pixiv/three-vrm";
import "@/ModelView.css";
import { loadModel } from "./vrm";
Expand All @@ -15,6 +20,9 @@ function App() {

const [mouseX, setMouseX] = useState(0);
const [mouseY, setMouseY] = useState(0);
const [moveOffset, setMoveOffset] = useState<{ x: number; y: number } | null>(
null,
);

const onUpdateRef = useRef((_vrm: VRM | null) => {});
useEffect(() => {
Expand Down Expand Up @@ -47,14 +55,16 @@ function App() {
}
}
};

if (moveOffset) {
appWindow.setPosition(
new LogicalPosition(mouseX - moveOffset.x, mouseY - moveOffset.y),
);
}
}, [mouseX, mouseY]);

const onClick: MouseEventHandler = async (e) => {
e.preventDefault();
setTimeout(() => {
setClickCount(0);
}, 600);
setClickCount((prev) => prev + 1);
if (clickCount === 2) {
const configWindow = getAll().find((v) => v.label === "config");
if (configWindow) {
Expand All @@ -63,6 +73,18 @@ function App() {
}
}
};
const onMouseDown: MouseEventHandler = async () => {
setTimeout(() => {
setClickCount(0);
}, 600);
setClickCount((prev) => prev + 1);
const pos = (await appWindow.outerPosition()).toLogical(
await appWindow.scaleFactor(),
);
if (clickCount == 0) {
setMoveOffset({ x: mouseX - pos.x, y: mouseY - pos.y });
}
};

useEffect(() => {
(async () => {
Expand All @@ -86,8 +108,11 @@ function App() {
<div
ref={render}
onClick={onClick}
onMouseDown={onMouseDown}
onMouseUp={() => {
setMoveOffset(null);
}}
className="render"
data-tauri-drag-region={true}
></div>
</>
);
Expand Down
1 change: 0 additions & 1 deletion src/vrm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const loadModel = <T extends Function>(
renderer.setClearAlpha(0);
renderer.shadowMap.enabled = true;
const elem = renderer.domElement;
elem.dataset.tauriDragRegion = "1";

if (render.hasChildNodes()) {
return;
Expand Down

0 comments on commit af655b0

Please sign in to comment.