Skip to content
Closed
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
13 changes: 13 additions & 0 deletions src/composables/useSharedMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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({
Expand All @@ -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'),
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
"showCat": "Show Cat",
"passThrough": "Window Penetration",
"windowSize": "Window Size",
"opacity": "Opacity"
"opacity": "Opacity",
"resetCat": "Reset Cat"
}
},
"useTray": {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/vi-VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
"showCat": "显示猫咪",
"passThrough": "窗口穿透",
"windowSize": "窗口尺寸",
"opacity": "不透明度"
"opacity": "不透明度",
"resetCat": "重置猫咪"
}
},
"useTray": {
Expand Down
36 changes: 36 additions & 0 deletions src/stores/app.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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,
}
})
5 changes: 5 additions & 0 deletions src/stores/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ export const useCatStore = defineStore('cat', () => {
migrated.value = true
}

const resetWindowScale = () => {
window.scale = 75
}

return {
migrated,
model,
window,
init,
resetWindowScale,
}
})