[feat] Inject javascript from on_window_ready
or on_webview_ready
(using state data)
#9099
Labels
on_window_ready
or on_webview_ready
(using state data)
#9099
Describe the problem
I want the inline the initial values of my app user config to my window. This data is coming from managed state in Tauri. I previously was calling it async from the front-end, but it means adding some dynamic imports to prevent race conditions.
Typically, my front-end main looks like the following:
This works, but is not great, and delays to time-to-readiness of the app. In Electron, some of this work could be done in preload.
So I decided to moving some
window
global variables setup to the back-end, having discovered the [initialization_script]
(https://docs.rs/tauri/2.0.0-beta.8/tauri/webview/struct.WebviewWindowBuilder.html#method.initialization_script) feature.Unfortunately, when statically creating a window from
tauri.conf.json
, it is not possible to modify the webview attributed of it via plugin'son_window_ready
oron_webview_ready
.Describe the solution you'd like
Make it possible to append additional
initialization_script
from plugin, dynamically.Plugin::Builder::js_init_script
is not good enough, because I need to access State-managed data, and this helper only accepts static values.This is really a convenience feature request, things are working ok right now, but if you think it makes sense and it's not too complicated, it would be absolutely awesome.
Alternatives considered
My current solution is to manually create the window during
setup
I would highly prefer to be able to inject that JS via my plugin (
plugins::config::init()
) instead + static window definition intauri.conf.json
, separation of concerns, all that ;)Additional context
martpie/museeks#748 for additional context and more code :D
The text was updated successfully, but these errors were encountered: