mirror of https://github.com/tauri-apps/tauri
fix(tauri) salt race condition
This commit is contained in:
parent
4db6171c37
commit
d04b15fc90
|
@ -11,41 +11,35 @@ pub(crate) fn handle<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> boo
|
|||
match command {
|
||||
Init {} => {
|
||||
webview
|
||||
.handle()
|
||||
.dispatch(move |_webview| {
|
||||
_webview
|
||||
.eval(&format!(
|
||||
"window['{queue}'] = [];
|
||||
window['{fn}'] = function (payload, salt, ignoreQueue) {{
|
||||
window.tauri.promisified({{
|
||||
cmd: 'validateSalt',
|
||||
salt: salt
|
||||
}}).then(function () {{
|
||||
const listeners = (window['{listeners}'] && window['{listeners}'][payload.type]) || []
|
||||
if (!ignoreQueue && listeners.length === 0) {{
|
||||
window['{queue}'].push({{
|
||||
payload: payload,
|
||||
salt: salt
|
||||
}})
|
||||
}}
|
||||
.eval(&format!(
|
||||
"window['{queue}'] = [];
|
||||
window['{fn}'] = function (payload, salt, ignoreQueue) {{
|
||||
const listeners = (window['{listeners}'] && window['{listeners}'][payload.type]) || []
|
||||
if (!ignoreQueue && listeners.length === 0) {{
|
||||
window['{queue}'].push({{
|
||||
payload: payload,
|
||||
salt: salt
|
||||
}})
|
||||
}}
|
||||
|
||||
for (let i = listeners.length - 1; i >= 0; i--) {{
|
||||
const listener = listeners[i]
|
||||
if (listener.once)
|
||||
listeners.splice(i, 1)
|
||||
listener.handler(payload)
|
||||
}}
|
||||
}})
|
||||
}}",
|
||||
fn = crate::event::emit_function_name(),
|
||||
listeners = crate::event::event_listeners_object_name(),
|
||||
queue = crate::event::event_queue_object_name()
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
if (listeners.length > 0) {{
|
||||
window.tauri.promisified({{
|
||||
cmd: 'validateSalt',
|
||||
salt: salt
|
||||
}}).then(function () {{
|
||||
for (let i = listeners.length - 1; i >= 0; i--) {{
|
||||
const listener = listeners[i]
|
||||
if (listener.once)
|
||||
listeners.splice(i, 1)
|
||||
listener.handler(payload)
|
||||
}}
|
||||
}})
|
||||
}}
|
||||
}}",
|
||||
fn = crate::event::emit_function_name(),
|
||||
listeners = crate::event::event_listeners_object_name(),
|
||||
queue = crate::event::event_queue_object_name()
|
||||
)).unwrap();
|
||||
}
|
||||
#[cfg(any(feature = "all-api", feature = "readTextFile"))]
|
||||
ReadTextFile {
|
||||
|
|
|
@ -48,16 +48,11 @@ pub fn validate<T: 'static>(
|
|||
callback: String,
|
||||
error: String,
|
||||
) {
|
||||
crate::execute_promise(
|
||||
webview,
|
||||
move || {
|
||||
if is_valid(salt) {
|
||||
Ok("'VALID'".to_string())
|
||||
} else {
|
||||
Err("'INVALID SALT'".to_string())
|
||||
}
|
||||
},
|
||||
callback,
|
||||
error,
|
||||
);
|
||||
let response = if is_valid(salt) {
|
||||
Ok("'VALID'".to_string())
|
||||
} else {
|
||||
Err("'INVALID SALT'".to_string())
|
||||
};
|
||||
let callback_string = crate::api::rpc::format_callback_result(response, callback, error);
|
||||
webview.eval(callback_string.as_str()).unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue