mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-29 13:31:27 +02:00
654a7299c3
* fix(positioner): pass correct values through IPC followup to https://github.com/tauri-apps/plugins-workspace/pull/1822 * build api & remove packageManager field
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
// Copyright 2021 Jonas Kruckenberg
|
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import { invoke } from '@tauri-apps/api/core'
|
|
import type { TrayIconEvent } from '@tauri-apps/api/tray'
|
|
|
|
/**
|
|
* Well known window positions.
|
|
*/
|
|
export enum Position {
|
|
TopLeft = 0,
|
|
TopRight,
|
|
BottomLeft,
|
|
BottomRight,
|
|
TopCenter,
|
|
BottomCenter,
|
|
LeftCenter,
|
|
RightCenter,
|
|
Center,
|
|
TrayLeft,
|
|
TrayBottomLeft,
|
|
TrayRight,
|
|
TrayBottomRight,
|
|
TrayCenter,
|
|
TrayBottomCenter
|
|
}
|
|
|
|
/**
|
|
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window()`
|
|
* All positions are relative to the **current** screen.
|
|
*
|
|
* @param to The {@link Position} to move to.
|
|
*/
|
|
export async function moveWindow(to: Position): Promise<void> {
|
|
await invoke('plugin:positioner|move_window', {
|
|
position: to
|
|
})
|
|
}
|
|
|
|
export async function handleIconState(event: TrayIconEvent): Promise<void> {
|
|
const size = {} as Record<string, unknown>
|
|
size[`${event.rect.size.type}`] = {
|
|
width: event.rect.size.width,
|
|
height: event.rect.size.height
|
|
}
|
|
|
|
const position = {} as Record<string, unknown>
|
|
position[`${event.rect.position.type}`] = {
|
|
x: event.rect.position.x,
|
|
y: event.rect.position.y
|
|
}
|
|
|
|
await invoke('plugin:positioner|set_tray_icon_state', {
|
|
position,
|
|
size
|
|
})
|
|
}
|