Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/composables/useWindowState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Event } from '@tauri-apps/api/event'
import type { ScaleFactorChanged } from '@tauri-apps/api/window'

import { PhysicalPosition, PhysicalSize } from '@tauri-apps/api/dpi'
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
Expand All @@ -12,7 +13,7 @@ import { useAppStore } from '@/stores/app'
import { useCatStore } from '@/stores/cat'
import { getCursorMonitor } from '@/utils/monitor'

export type WindowState = Record<string, Partial<PhysicalPosition & PhysicalSize> | undefined>
export type WindowState = Record<string, Partial<PhysicalPosition & PhysicalSize & Pick<ScaleFactorChanged, 'scaleFactor'>> | undefined>

const appWindow = getCurrentWebviewWindow()
const { label } = appWindow
Expand All @@ -28,6 +29,7 @@ export function useWindowState() {
appWindow.onResized(onChange)

appWindow.onScaleChanged(clampToMonitor)
appWindow.onScaleChanged(onScaleChanged)
})

const clampToMonitor = useDebounceFn(async () => {
Expand All @@ -54,6 +56,11 @@ export function useWindowState() {
return appWindow.setPosition(new PhysicalPosition(clampedX, clampedY))
}, 500)

const onScaleChanged = (event: Event<ScaleFactorChanged>) => {
appStore.windowState[label] ??= {}
appStore.windowState[label].scaleFactor = event.payload.scaleFactor
}

watch(() => catStore.window.keepInScreen, clampToMonitor)

const onChange = async (event: Event<PhysicalPosition | PhysicalSize>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ import { open } from '@tauri-apps/plugin-dialog'
import { readDir } from '@tauri-apps/plugin-fs'
import { message } from 'antdv-next'
import { nanoid } from 'nanoid'
import { onMounted, ref, useTemplateRef, watch } from 'vue'
import { computed, onMounted, ref, useTemplateRef, watch } from 'vue'
import { useI18n } from 'vue-i18n'

import type { ModelMode } from '@/stores/model'

import { INVOKE_KEY } from '@/constants'
import { useAppStore } from '@/stores/app'
import { useModelStore } from '@/stores/model'
import { join } from '@/utils/path'

const dropRef = useTemplateRef('drop')
const dragenter = ref(false)
const selectPaths = ref<string[]>([])
const modelStore = useModelStore()
const appStore = useAppStore()
const { t } = useI18n()
const appWindow = getCurrentWebviewWindow()
const scaleFactor = computed(() => appStore.windowState[appWindow.label]?.scaleFactor ?? devicePixelRatio)

onMounted(() => {
const appWindow = getCurrentWebviewWindow()

appWindow.onDragDropEvent(({ payload }) => {
const { type } = payload

if (type === 'over') {
const { x, y } = payload.position
const { x, y } = payload.position.toLogical(scaleFactor.value)

if (dropRef.value) {
const { left, right, top, bottom } = dropRef.value.getBoundingClientRect()
Expand Down