tauri-apps / tauri-apps/plugins-workspace

[positioner] Set the position at application startup

Open
#935 0 comments 1 reaction 0 assignees View on GitHub
plugin: positioner type: feature request
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

Description

Currently, the window positioning is done after the first click on the application icon in the system tray.
For example, if we set the hotkey to appWindow.setFocus() and press it after launching the application, the window will open in the center of the window, not under the icon.

1. Set the positioning
```rs
fn tray_event(app: &AppHandle, event: SystemTrayEvent) {
tauri_plugin_positioner::on_tray_event(app, &event);
match event {
SystemTrayEvent::LeftClick {
position: _,
size: _,
..
} => {
let win = app.get_window("main").unwrap();
let _ = win.move_window(Position::TrayCenter); // <-----------------

if win.is_visible().unwrap() {
win.hide().unwrap();
} else {
win.show().unwrap();
win.set_focus().unwrap();
}
}
...
```
2. Set the hotkey
```ts
register('CommandOrControl+L', async () => {
const focused = await appWindow.isFocused()

focused ? appWindow.hide() : appWindow.setFocus()
})
```
3. Start the application
4. Press the hotkey, the application will be displayed in the center of the screen, not in TrayCenter
5. Open the application by clicking in Tray, it will display correctly
6. Subsequent hotkey clicks will open the application correctly in TrayCenter

Link to post with video demonstration
https://discord.com/channels/616186924390023171/731495028677148753/1205606232568758312

**+ We have to track the movement of the icon in Tray and set the position for the application window.**

**UPD: That doesn't seem to be possible**
https://github.com/ahkohd/tauri-macos-menubar-app-example/issues/3#issuecomment-1943909486

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.