diff --git a/src/composables/useSharedMenu.ts b/src/composables/useSharedMenu.ts index 3cdc4327..f7e841f6 100644 --- a/src/composables/useSharedMenu.ts +++ b/src/composables/useSharedMenu.ts @@ -3,10 +3,12 @@ import { range } from 'es-toolkit' import { useI18n } from 'vue-i18n' import { showWindow } from '@/plugins/window' +import { useAppStore } from '@/stores/app' import { useCatStore } from '@/stores/cat' import { isMac } from '@/utils/platform' export function useSharedMenu() { + const appStore = useAppStore() const catStore = useCatStore() const { t } = useI18n() @@ -58,6 +60,11 @@ export function useSharedMenu() { return Promise.all(items) } + const handleResetAll = async () => { + await catStore.resetWindowScale() + await appStore.reset() + } + const getSharedMenu = async () => { return await Promise.all([ MenuItem.new({ @@ -71,6 +78,12 @@ export function useSharedMenu() { catStore.window.visible = !catStore.window.visible }, }), + MenuItem.new({ + text: t('composables.useSharedMenu.labels.resetCat'), + action: () => { + void handleResetAll() + }, + }), PredefinedMenuItem.new({ item: 'Separator' }), CheckMenuItem.new({ text: t('composables.useSharedMenu.labels.passThrough'), diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 97b2e071..6f3b6261 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -152,7 +152,8 @@ "showCat": "Show Cat", "passThrough": "Window Penetration", "windowSize": "Window Size", - "opacity": "Opacity" + "opacity": "Opacity", + "resetCat": "Reset Cat" } }, "useTray": { diff --git a/src/locales/vi-VN.json b/src/locales/vi-VN.json index 30458d85..98b31ba5 100644 --- a/src/locales/vi-VN.json +++ b/src/locales/vi-VN.json @@ -152,7 +152,8 @@ "showCat": "Hiện Mèo", "passThrough": "Click xuyên", "windowSize": "Kích thước", - "opacity": "Độ mờ" + "opacity": "Độ mờ", + "resetCat": "Đặt lại Mèo" } }, "useTray": { diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index abfcfc7b..b842ae07 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -152,7 +152,8 @@ "showCat": "显示猫咪", "passThrough": "窗口穿透", "windowSize": "窗口尺寸", - "opacity": "不透明度" + "opacity": "不透明度", + "resetCat": "重置猫咪" } }, "useTray": { diff --git a/src/stores/app.ts b/src/stores/app.ts index 97dc8b0a..ca071ab2 100644 --- a/src/stores/app.ts +++ b/src/stores/app.ts @@ -1,6 +1,9 @@ import type { WindowState } from '@/composables/useWindowState' import { getName, getVersion } from '@tauri-apps/api/app' +import { PhysicalPosition, PhysicalSize } from '@tauri-apps/api/dpi' +import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow' +import { availableMonitors } from '@tauri-apps/api/window' import { defineStore } from 'pinia' import { reactive, ref } from 'vue' @@ -14,10 +17,43 @@ export const useAppStore = defineStore('app', () => { version.value = await getVersion() } + const reset = async () => { + const appWindow = getCurrentWebviewWindow() + const { label } = appWindow + + const size = await appWindow.size() + const monitors = await availableMonitors() + + if (!monitors.length) { + // Fallback if we somehow cannot read monitors: just clear the saved state + delete windowState[label] + return + } + + const primary = monitors[0] + + const maxX = primary.size.width - size.width + const maxY = primary.size.height - size.height + + const x = primary.position.x + Math.max(0, Math.floor(maxX / 2)) + const y = primary.position.y + Math.max(0, Math.floor(maxY / 2)) + + windowState[label] = { + x, + y, + width: size.width, + height: size.height, + } + + await appWindow.setPosition(new PhysicalPosition(x, y)) + await appWindow.setSize(new PhysicalSize(size.width, size.height)) + } + return { name, version, windowState, init, + reset, } }) diff --git a/src/stores/cat.ts b/src/stores/cat.ts index 9f25b91b..b8118cc9 100644 --- a/src/stores/cat.ts +++ b/src/stores/cat.ts @@ -77,10 +77,15 @@ export const useCatStore = defineStore('cat', () => { migrated.value = true } + const resetWindowScale = () => { + window.scale = 75 + } + return { migrated, model, window, init, + resetWindowScale, } })