resolve tray window position manually, remove positioner plugin

This commit is contained in:
Lucas Nogueira
2025-01-28 10:36:03 -03:00
parent 35d6bd9d72
commit 236c664867
8 changed files with 28 additions and 34 deletions
+13 -3
View File
@@ -4,13 +4,22 @@ import { MenuItem } from '@tauri-apps/api/menu'
import { resolveResource } from '@tauri-apps/api/path'
import type { TrayIconEvent } from '@tauri-apps/api/tray'
import { TrayIcon } from '@tauri-apps/api/tray'
import { getAllWindows } from '@tauri-apps/api/window'
import { getAllWindows, PhysicalPosition, PhysicalSize } from '@tauri-apps/api/window'
import { ask } from '@tauri-apps/plugin-dialog'
import { handleIconState } from '@tauri-apps/plugin-positioner'
import { exit } from '@tauri-apps/plugin-process'
import { buildMenu } from './menu'
import { resetMainWindow } from './window'
let trayPosition = new PhysicalPosition(0, 0)
let traySize = new PhysicalSize(0, 0)
export function getTrayRect() {
return {
position: trayPosition,
size: traySize,
}
}
export async function getMainTray() {
return await TrayIcon.getById('main-tray')
}
@@ -36,7 +45,8 @@ export async function rebuildTrayMenu() {
}
async function onTrayAction(event: TrayIconEvent) {
await handleIconState(event)
trayPosition = event.rect.position
traySize = event.rect.size
if (event.type === 'Click') {
console.log('Tray clicked:', event)
+15 -5
View File
@@ -1,6 +1,7 @@
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
import { LogicalSize, PhysicalSize, currentMonitor, getAllWindows } from '@tauri-apps/api/window'
import { LogicalSize, PhysicalPosition, PhysicalSize, currentMonitor, getAllWindows } from '@tauri-apps/api/window'
import { Position, moveWindow } from '@tauri-apps/plugin-positioner'
import { getTrayRect } from './tray'
export async function resetMainWindow() {
const window = await getAllWindows().then((w) => w.find((w) => w.label === 'main'))
@@ -108,10 +109,19 @@ export async function openTrayWindow({
await new Promise((resolve) => setTimeout(resolve, 1500))
await w.hide()
await w.setSize(new LogicalSize(400, 600))
// await w.center()
await w.show()
await moveWindow(Position.TrayCenter)
const windowSize = new LogicalSize(400, 600)
await w.setSize(windowSize)
const trayRect = getTrayRect()
const windowPhysicalSize = windowSize.toPhysical(await w.scaleFactor())
await w.setPosition(
new PhysicalPosition(
trayRect.position.x +
trayRect.size.width / 2 -
windowPhysicalSize.width / 2,
trayRect.position.y
)
)
await w.show()
return w
}