fix(common): 🐛 default values for homeWindowState

This commit is contained in:
Dawn
2025-10-31 08:09:01 +08:00
parent 7bce07d4a0
commit d838709b9f
2 changed files with 38 additions and 3 deletions
+21 -2
View File
@@ -287,9 +287,28 @@ onMounted(async () => {
})
}
// 恢复大小
// 恢复大小(验证尺寸有效性)
if (globalStore.homeWindowState.width && globalStore.homeWindowState.height) {
await homeWindow.setSize(new LogicalSize(globalStore.homeWindowState.width, globalStore.homeWindowState.height))
const MIN_WIDTH = 330
const MIN_HEIGHT = 480
const DEFAULT_WIDTH = 960
const DEFAULT_HEIGHT = 720
let targetWidth = globalStore.homeWindowState.width
let targetHeight = globalStore.homeWindowState.height
// 如果窗口大小异常,使用默认值
if (targetWidth < MIN_WIDTH || targetHeight < MIN_HEIGHT) {
info(
`[layout] 检测到窗口大小异常 (${targetWidth}x${targetHeight}),使用默认值 (${DEFAULT_WIDTH}x${DEFAULT_HEIGHT})`
)
targetWidth = DEFAULT_WIDTH
targetHeight = DEFAULT_HEIGHT
// 同步更新到 store
globalStore.setHomeWindowState({ width: targetWidth, height: targetHeight })
}
await homeWindow.setSize(new LogicalSize(targetWidth, targetHeight))
}
// 居中
await homeWindow.center()
+17 -1
View File
@@ -82,7 +82,23 @@ export const useGlobalStore = defineStore(
// 设置home窗口位置、宽高信息
const setHomeWindowState = (newState: { width: number; height: number }) => {
homeWindowState.value = { ...homeWindowState.value, ...newState }
// 验证窗口大小,如果小于最小限制,则使用默认值
const MIN_WIDTH = 330
const MIN_HEIGHT = 480
const DEFAULT_WIDTH = 960
const DEFAULT_HEIGHT = 720
if (newState.width < MIN_WIDTH || newState.height < MIN_HEIGHT) {
info(
`[global] 窗口大小异常 (${newState.width}x${newState.height}),强制设置为默认值 (${DEFAULT_WIDTH}x${DEFAULT_HEIGHT})`
)
homeWindowState.value = {
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT
}
} else {
homeWindowState.value = { ...homeWindowState.value, ...newState }
}
}
// 更新全局未读消息计数