mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
fix(core): properly handle async errors in addPluginListener (#14464)
* fix(core): properly handle async errors in addPluginListener The previous implementation used .then() after invoke() without await, which prevented the catch block from handling rejected promises. Now using await to properly catch errors and allow fallback to camelCase registerListener method. * Change file and generate `bundle.global.js` --------- Co-authored-by: Tony <legendmastertony@gmail.com>
This commit is contained in:
committed by
GitHub
parent
beffcd880f
commit
ad1dec2e24
5
.changes/add-plugin-listener-error-handling.md
Normal file
5
.changes/add-plugin-listener-error-handling.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tauri-apps/api": patch:bug
|
||||
---
|
||||
|
||||
Fix `addPluginListener` fallback added in https://github.com/tauri-apps/tauri/pull/14132 didn't work properly
|
||||
File diff suppressed because one or more lines are too long
@@ -186,16 +186,16 @@ async function addPluginListener<T>(
|
||||
): Promise<PluginListener> {
|
||||
const handler = new Channel<T>(cb)
|
||||
try {
|
||||
return invoke(`plugin:${plugin}|register_listener`, {
|
||||
await invoke(`plugin:${plugin}|register_listener`, {
|
||||
event,
|
||||
handler
|
||||
}).then(() => new PluginListener(plugin, event, handler.id))
|
||||
})
|
||||
return 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)
|
||||
)
|
||||
await invoke(`plugin:${plugin}|registerListener`, { event, handler })
|
||||
return new PluginListener(plugin, event, handler.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user