Created
October 27, 2025 13:29
-
-
Save BHznJNs/53e58ce735032226c9dbe3e888627309 to your computer and use it in GitHub Desktop.
Tauri plugin that is used to inject variables into the webview global namespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::collections::HashMap; | |
| use tauri::{ | |
| plugin::{Builder, TauriPlugin}, | |
| Runtime, | |
| }; | |
| fn create_init_script(vars: HashMap<&str, String>) -> String { | |
| let vars_str = vars | |
| .iter() | |
| .map(|(k, v)| format!("{}: '{}'", k, v)) | |
| .collect::<Vec<_>>() | |
| .join(",\n"); | |
| format!( | |
| r#" | |
| console.log("Successfully injected InputShare variables"); | |
| window.__INJECTED__ = {{ | |
| {} | |
| }}; | |
| "#, | |
| vars_str | |
| ) | |
| } | |
| pub fn init<R: Runtime>(vars: HashMap<&str, String>) -> TauriPlugin<R> { | |
| let init_script = create_init_script(vars); | |
| Builder::new("inject_vars") | |
| .js_init_script(init_script) | |
| .build() | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage in lib.rs: