fix(api): "command not found" error when running addPluginListener (#14132)

* fix(api): "command not found" error when running addPluginListener

the backend expects the command name to be in snake case

we've made this change already for check_permissions and request_permissions, but missed register_listener

* fix check instead

* update bundle.global.js

* code review suggestion

* add note

* adjust change file

* remove unused var

* fmt

* build
This commit is contained in:
Lucas Fernandes Nogueira
2025-10-06 14:55:20 -03:00
committed by GitHub
parent 28a2f9bc55
commit 08bda64c25
3 changed files with 18 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@tauri-apps/api": patch:bug
---
Fix `core > addPluginListener` failing on command permission check.

File diff suppressed because one or more lines are too long

View File

@@ -185,9 +185,18 @@ async function addPluginListener<T>(
cb: (payload: T) => void
): Promise<PluginListener> {
const handler = new Channel<T>(cb)
return invoke(`plugin:${plugin}|registerListener`, { event, handler }).then(
() => new PluginListener(plugin, event, handler.id)
)
try {
return invoke(`plugin:${plugin}|register_listener`, {
event,
handler
}).then(() => new PluginListener(plugin, event, handler.id))
} catch {
// TODO(v3): remove this fallback
// note: we must try with camelCase here for backwards compatibility
return invoke(`plugin:${plugin}|registerListener`, { event, handler }).then(
() => new PluginListener(plugin, event, handler.id)
)
}
}
type PermissionState = 'granted' | 'denied' | 'prompt' | 'prompt-with-rationale'