Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 5 additions & 0 deletions .changes/api-tray-doubleClick-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": "patch:bug"
---

Add missing `TrayIconDoubleClickEvent` type and `doubleClick` variant in `TrayIconEvent` type.
6 changes: 6 additions & 0 deletions .changes/api-tray-icon-event-value-mismatch-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/api": "patch:bug"
---

Fix inavlid value passed to the callback `action` function that doesn't match the `TrayIconEvent` type.

2 changes: 1 addition & 1 deletion crates/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
"devDependencies": {
"prettier": "^3.3.3"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"rollup@>=4.0.0 <4.22.4": ">=4.22.4"
}
}
}
60 changes: 59 additions & 1 deletion packages/api/src/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ export interface TrayIconClickEvent {
button_state: MouseButtonState
}

/** A double click happened on the tray icon. **Windows Only** */
export interface TrayIconDoubleClickEvent {
/** Id of the tray icon which triggered this event. */
id: string
/** Physical X Position of the click the triggered this event. */
x: number
/** Physical Y Position of the click the triggered this event. */
y: number
/** Position and size of the tray icon. */
rect: {
position: PhysicalPosition
size: PhysicalSize
}
/** Mouse button that triggered this event. */
button: MouseButton
}

/** The mouse entered the tray icon region. */
export interface TrayIconEnterEvent {
/** Id of the tray icon which triggered this event. */
Expand Down Expand Up @@ -84,6 +101,7 @@ export interface TrayIconLeaveEvent {
*/
export type TrayIconEvent =
| { click: TrayIconClickEvent }
| { doubleClick: TrayIconDoubleClickEvent }
| { enter: TrayIconEnterEvent }
| { move: TrayIconMoveEvent }
| { leave: TrayIconLeaveEvent }
Expand Down Expand Up @@ -207,7 +225,36 @@ export class TrayIcon extends Resource {

const handler = new Channel<TrayIconEvent>()
if (options?.action) {
handler.onmessage = options.action
const action = options.action
handler.onmessage = (e) => {
if ('click' in e) {
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.click.rect.position = mapPosition(e.click.rect.position)
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.click.rect.size = mapSize(e.click.rect.size)
} else if ('doubleClick' in e) {
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.doubleClick.rect.position = mapPosition(e.doubleClick.rect.position)
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.doubleClick.rect.size = mapSize(e.doubleClick.rect.size)
} else if ('enter' in e) {
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.enter.rect.position = mapPosition(e.enter.rect.position)
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.enter.rect.size = mapSize(e.enter.rect.size)
} else if ('move' in e) {
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.move.rect.position = mapPosition(e.move.rect.position)
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.move.rect.size = mapSize(e.move.rect.size)
} else if ('leave' in e) {
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.leave.rect.position = mapPosition(e.leave.rect.position)
// @ts-expect-error `TrayIconEvent` doesn't quite match the value yet so we reconstruct the incorrect fields
e.leave.rect.size = mapSize(e.leave.rect.size)
}
action(e)
}
delete options.action
}

Expand Down Expand Up @@ -310,3 +357,14 @@ export class TrayIcon extends Resource {
})
}
}

function mapPosition(pos: {
Physical: { x: number; y: number }
}): PhysicalPosition {
return new PhysicalPosition(pos.Physical.x, pos.Physical.y)
}
function mapSize(pos: {
Physical: { width: number; height: number }
}): PhysicalSize {
return new PhysicalSize(pos.Physical.width, pos.Physical.height)
}
Loading
Loading