Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ import { initializeTheme, toggleThemeQuickly, useThemeState } from './utils/them
type ViewType = 'welcome' | 'main' | 'settings';
const NORMAL_MIN_WIDTH = 320;
const NORMAL_MIN_HEIGHT = 300;
const MINI_DRAG_THRESHOLD_PX = 3;
const MINI_CLICK_MAX_DURATION_MS = 260;

interface WindowStatePayload {
mini_mode: boolean;
Expand Down Expand Up @@ -281,7 +283,8 @@ const searchInputRef = ref<HTMLInputElement | null>(null);
let miniStartPoint: { x: number; y: number } | null = null;
let miniPressStartedAt = 0;
let miniMouseMoveHandler: ((event: MouseEvent) => void) | null = null;
let miniMouseUpHandler: (() => void) | null = null;
let miniMouseUpHandler: ((event: MouseEvent) => void) | null = null;
let miniDragIntent = false;
let miniSuppressClick = false;

const toast = ref('');
Expand Down Expand Up @@ -664,6 +667,7 @@ function cancelMiniInteraction() {
clearMiniDragListeners();
miniStartPoint = null;
miniPressStartedAt = 0;
miniDragIntent = false;
miniPressed.value = false;
miniDragging.value = false;
}
Expand All @@ -679,6 +683,7 @@ function onMiniMouseDown(event: MouseEvent) {
if (event.button !== 0) return;
miniPressed.value = true;
miniDragging.value = false;
miniDragIntent = false;
miniStartPoint = { x: event.clientX, y: event.clientY };
miniPressStartedAt = Date.now();

Expand All @@ -687,7 +692,8 @@ function onMiniMouseDown(event: MouseEvent) {
if (!miniStartPoint || miniDragging.value) return;
const dx = moveEvent.clientX - miniStartPoint.x;
const dy = moveEvent.clientY - miniStartPoint.y;
if (Math.hypot(dx, dy) < 3) return;
if (Math.hypot(dx, dy) < MINI_DRAG_THRESHOLD_PX) return;
miniDragIntent = true;
miniDragging.value = true;
suppressMiniClick(500);
clearMiniDragListeners();
Expand All @@ -700,19 +706,24 @@ function onMiniMouseDown(event: MouseEvent) {
window.setTimeout(() => {
miniStartPoint = null;
miniPressStartedAt = 0;
miniDragIntent = false;
miniPressed.value = false;
miniDragging.value = false;
void persistPetPosition();
}, 120);
});
};

miniMouseUpHandler = () => {
miniMouseUpHandler = (upEvent: MouseEvent) => {
const pressDuration = Date.now() - miniPressStartedAt;
const shouldRestore = !miniDragging.value && pressDuration < 260;
const dx = miniStartPoint ? upEvent.clientX - miniStartPoint.x : 0;
const dy = miniStartPoint ? upEvent.clientY - miniStartPoint.y : 0;
const moved = Math.hypot(dx, dy) >= MINI_DRAG_THRESHOLD_PX;
const shouldRestore = !miniDragging.value && !miniDragIntent && !moved && pressDuration < MINI_CLICK_MAX_DURATION_MS;
clearMiniDragListeners();
miniStartPoint = null;
miniPressStartedAt = 0;
miniDragIntent = false;
if (shouldRestore) {
suppressMiniClick();
void restoreNormalMode();
Expand Down