diff --git a/.changes/fix-handleIconState.md b/.changes/fix-handleIconState.md new file mode 100644 index 0000000000..0b5eec3d67 --- /dev/null +++ b/.changes/fix-handleIconState.md @@ -0,0 +1,6 @@ +--- +"positioner": patch +"positioner-js": patch +--- + +Added missing permission for `handleIconState` and fixed its event processing logic. diff --git a/plugins/positioner/api-iife.js b/plugins/positioner/api-iife.js index bce8ee32f3..0b78572d3a 100644 --- a/plugins/positioner/api-iife.js +++ b/plugins/positioner/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_POSITIONER__=function(t){"use strict";async function e(t,e={},o){return window.__TAURI_INTERNALS__.invoke(t,e,o)}var o;return"function"==typeof SuppressedError&&SuppressedError,t.Position=void 0,(o=t.Position||(t.Position={}))[o.TopLeft=0]="TopLeft",o[o.TopRight=1]="TopRight",o[o.BottomLeft=2]="BottomLeft",o[o.BottomRight=3]="BottomRight",o[o.TopCenter=4]="TopCenter",o[o.BottomCenter=5]="BottomCenter",o[o.LeftCenter=6]="LeftCenter",o[o.RightCenter=7]="RightCenter",o[o.Center=8]="Center",o[o.TrayLeft=9]="TrayLeft",o[o.TrayBottomLeft=10]="TrayBottomLeft",o[o.TrayRight=11]="TrayRight",o[o.TrayBottomRight=12]="TrayBottomRight",o[o.TrayCenter=13]="TrayCenter",o[o.TrayBottomCenter=14]="TrayBottomCenter",t.handleIconState=async function(t){const o={};o[`${t.rect.size.type}`]={width:t.rect.size.width,height:t.rect.size.height};const i={};i[`${t.rect.position.type}`]={x:t.rect.position.x,y:t.rect.position.y},await e("plugin:positioner|set_tray_icon_state",{position:i,size:o})},t.moveWindow=async function(t){await e("plugin:positioner|move_window",{position:t})},t}({});Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_PLUGIN_POSITIONER__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_POSITIONER__=function(t){"use strict";async function o(t,o={},e){return window.__TAURI_INTERNALS__.invoke(t,o,e)}var e;return"function"==typeof SuppressedError&&SuppressedError,t.Position=void 0,(e=t.Position||(t.Position={}))[e.TopLeft=0]="TopLeft",e[e.TopRight=1]="TopRight",e[e.BottomLeft=2]="BottomLeft",e[e.BottomRight=3]="BottomRight",e[e.TopCenter=4]="TopCenter",e[e.BottomCenter=5]="BottomCenter",e[e.LeftCenter=6]="LeftCenter",e[e.RightCenter=7]="RightCenter",e[e.Center=8]="Center",e[e.TrayLeft=9]="TrayLeft",e[e.TrayBottomLeft=10]="TrayBottomLeft",e[e.TrayRight=11]="TrayRight",e[e.TrayBottomRight=12]="TrayBottomRight",e[e.TrayCenter=13]="TrayCenter",e[e.TrayBottomCenter=14]="TrayBottomCenter",t.handleIconState=async function(t){await o("plugin:positioner|set_tray_icon_state",{position:t.rect.position,size:t.rect.size})},t.moveWindow=async function(t){await o("plugin:positioner|move_window",{position:t})},t}({});Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_PLUGIN_POSITIONER__})} diff --git a/plugins/positioner/build.rs b/plugins/positioner/build.rs index 52d333761c..896c81aadd 100644 --- a/plugins/positioner/build.rs +++ b/plugins/positioner/build.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -const COMMANDS: &[&str] = &["move_window"]; +const COMMANDS: &[&str] = &["move_window", "set_tray_icon_state"]; fn main() { tauri_plugin::Builder::new(COMMANDS) diff --git a/plugins/positioner/guest-js/index.ts b/plugins/positioner/guest-js/index.ts index 8ba1d609f7..d8f6204fa0 100644 --- a/plugins/positioner/guest-js/index.ts +++ b/plugins/positioner/guest-js/index.ts @@ -40,20 +40,8 @@ export async function moveWindow(to: Position): Promise { } export async function handleIconState(event: TrayIconEvent): Promise { - const size = {} as Record - size[`${event.rect.size.type}`] = { - width: event.rect.size.width, - height: event.rect.size.height - } - - const position = {} as Record - 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 + position: event.rect.position, + size: event.rect.size }) } diff --git a/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml b/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml index dcc8fa56ee..6b85f63508 100644 --- a/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml +++ b/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml @@ -4,5 +4,10 @@ [[permission]] identifier = "allow-set-tray-icon-state" -description = "Enables the set_tray_icon_state to handle events and set the TrayIcon state." +description = "Enables the set_tray_icon_state command without any pre-configured scope." commands.allow = ["set_tray_icon_state"] + +[[permission]] +identifier = "deny-set-tray-icon-state" +description = "Denies the set_tray_icon_state command without any pre-configured scope." +commands.deny = ["set_tray_icon_state"] diff --git a/plugins/positioner/permissions/autogenerated/reference.md b/plugins/positioner/permissions/autogenerated/reference.md index 324e4e56f1..8dfe0466ea 100644 --- a/plugins/positioner/permissions/autogenerated/reference.md +++ b/plugins/positioner/permissions/autogenerated/reference.md @@ -1,6 +1,6 @@ ## Default Permission -Allows the move_window command +Allows the moveWindow and handleIconState APIs - `allow-move-window` - `set-tray-icon-state` @@ -48,7 +48,20 @@ Denies the move_window command without any pre-configured scope. -Enables the set_tray_icon_state to handle events and set the TrayIcon state. +Enables the set_tray_icon_state command without any pre-configured scope. + + + + + + + +`positioner:deny-set-tray-icon-state` + + + + +Denies the set_tray_icon_state command without any pre-configured scope. diff --git a/plugins/positioner/permissions/default.toml b/plugins/positioner/permissions/default.toml index 8492711c55..bd8dc25e52 100644 --- a/plugins/positioner/permissions/default.toml +++ b/plugins/positioner/permissions/default.toml @@ -1,4 +1,4 @@ "$schema" = "schemas/schema.json" [default] -description = "Allows the move_window command" +description = "Allows the moveWindow and handleIconState APIs" permissions = ["allow-move-window", "set-tray-icon-state"] diff --git a/plugins/positioner/permissions/schemas/schema.json b/plugins/positioner/permissions/schemas/schema.json index 5bddddde37..c4d1696682 100644 --- a/plugins/positioner/permissions/schemas/schema.json +++ b/plugins/positioner/permissions/schemas/schema.json @@ -305,12 +305,17 @@ "const": "deny-move-window" }, { - "description": "Enables the set_tray_icon_state to handle events and set the TrayIcon state.", + "description": "Enables the set_tray_icon_state command without any pre-configured scope.", "type": "string", "const": "allow-set-tray-icon-state" }, { - "description": "Allows the move_window command", + "description": "Denies the set_tray_icon_state command without any pre-configured scope.", + "type": "string", + "const": "deny-set-tray-icon-state" + }, + { + "description": "Allows the moveWindow and handleIconState APIs", "type": "string", "const": "default" }