Skip to content

Commit 08bda64

Browse files
authored
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
1 parent 28a2f9b commit 08bda64

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": patch:bug
3+
---
4+
5+
Fix `core > addPluginListener` failing on command permission check.

crates/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/src/core.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,18 @@ async function addPluginListener<T>(
185185
cb: (payload: T) => void
186186
): Promise<PluginListener> {
187187
const handler = new Channel<T>(cb)
188-
return invoke(`plugin:${plugin}|registerListener`, { event, handler }).then(
189-
() => new PluginListener(plugin, event, handler.id)
190-
)
188+
try {
189+
return invoke(`plugin:${plugin}|register_listener`, {
190+
event,
191+
handler
192+
}).then(() => new PluginListener(plugin, event, handler.id))
193+
} catch {
194+
// TODO(v3): remove this fallback
195+
// note: we must try with camelCase here for backwards compatibility
196+
return invoke(`plugin:${plugin}|registerListener`, { event, handler }).then(
197+
() => new PluginListener(plugin, event, handler.id)
198+
)
199+
}
191200
}
192201

193202
type PermissionState = 'granted' | 'denied' | 'prompt' | 'prompt-with-rationale'

0 commit comments

Comments
 (0)