mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 20:48:52 +03:00
parent
fc2e4083b0
commit
076e1a81a5
6
.changes/core-js-listenrid-u32.md
Normal file
6
.changes/core-js-listenrid-u32.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
'tauri-runtime': 'patch'
|
||||
'tauri-runtime-wry': 'patch'
|
||||
---
|
||||
|
||||
Use `u32` instead of `u64` for js event listener ids
|
5
.changes/core-js-listners-unlisten.md
Normal file
5
.changes/core-js-listners-unlisten.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'patch:bug'
|
||||
---
|
||||
|
||||
Fix unlistening to window events failing sometimes.
|
@ -3308,7 +3308,7 @@ fn create_ipc_handler<T: UserEvent>(
|
||||
context: Context<T>,
|
||||
label: String,
|
||||
menu_ids: Arc<Mutex<HashMap<MenuHash, MenuId>>>,
|
||||
js_event_listeners: Arc<Mutex<HashMap<JsEventListenerKey, HashSet<u64>>>>,
|
||||
js_event_listeners: Arc<Mutex<HashMap<JsEventListenerKey, HashSet<u32>>>>,
|
||||
handler: WebviewIpcHandler<T, Wry<T>>,
|
||||
) -> Box<IpcHandler> {
|
||||
Box::new(move |window, request| {
|
||||
|
@ -231,7 +231,7 @@ pub struct PendingWindow<T: UserEvent, R: Runtime<T>> {
|
||||
pub menu_ids: Arc<Mutex<HashMap<MenuHash, MenuId>>>,
|
||||
|
||||
/// A HashMap mapping JS event names with associated listener ids.
|
||||
pub js_event_listeners: Arc<Mutex<HashMap<JsEventListenerKey, HashSet<u64>>>>,
|
||||
pub js_event_listeners: Arc<Mutex<HashMap<JsEventListenerKey, HashSet<u32>>>>,
|
||||
|
||||
/// A handler to decide if incoming url is allowed to navigate.
|
||||
pub navigation_handler: Option<Box<dyn Fn(Url) -> bool + Send>>,
|
||||
@ -362,7 +362,7 @@ pub struct DetachedWindow<T: UserEvent, R: Runtime<T>> {
|
||||
pub menu_ids: Arc<Mutex<HashMap<MenuHash, MenuId>>>,
|
||||
|
||||
/// A HashMap mapping JS event names with associated listener ids.
|
||||
pub js_event_listeners: Arc<Mutex<HashMap<JsEventListenerKey, HashSet<u64>>>>,
|
||||
pub js_event_listeners: Arc<Mutex<HashMap<JsEventListenerKey, HashSet<u32>>>>,
|
||||
}
|
||||
|
||||
impl<T: UserEvent, R: Runtime<T>> Clone for DetachedWindow<T, R> {
|
||||
|
@ -67,7 +67,7 @@ pub enum Cmd {
|
||||
},
|
||||
/// Unlisten to an event.
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Unlisten { event: EventId, event_id: u64 },
|
||||
Unlisten { event: EventId, event_id: u32 },
|
||||
/// Emit an event to the webview associated with the given window.
|
||||
/// If the window_label is omitted, the event will be triggered on all listeners.
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -84,7 +84,7 @@ impl Cmd {
|
||||
event: EventId,
|
||||
window_label: Option<WindowLabel>,
|
||||
handler: CallbackFn,
|
||||
) -> super::Result<u64> {
|
||||
) -> super::Result<u32> {
|
||||
let event_id = rand::random();
|
||||
|
||||
let window_label = window_label.map(|l| l.0);
|
||||
@ -110,7 +110,7 @@ impl Cmd {
|
||||
fn unlisten<R: Runtime>(
|
||||
context: InvokeContext<R>,
|
||||
event: EventId,
|
||||
event_id: u64,
|
||||
event_id: u32,
|
||||
) -> super::Result<()> {
|
||||
context
|
||||
.window
|
||||
|
@ -299,7 +299,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlisten_js(listeners_object_name: String, event_name: String, event_id: u64) -> String {
|
||||
pub fn unlisten_js(listeners_object_name: String, event_name: String, event_id: u32) -> String {
|
||||
format!(
|
||||
"
|
||||
(function () {{
|
||||
@ -318,7 +318,7 @@ pub fn unlisten_js(listeners_object_name: String, event_name: String, event_id:
|
||||
pub fn listen_js(
|
||||
listeners_object_name: String,
|
||||
event: String,
|
||||
event_id: u64,
|
||||
event_id: u32,
|
||||
window_label: Option<String>,
|
||||
handler: String,
|
||||
) -> String {
|
||||
|
@ -1594,7 +1594,7 @@ impl<R: Runtime> Window<R> {
|
||||
self.window.dispatcher.eval_script(js).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub(crate) fn register_js_listener(&self, window_label: Option<String>, event: String, id: u64) {
|
||||
pub(crate) fn register_js_listener(&self, window_label: Option<String>, event: String, id: u32) {
|
||||
self
|
||||
.window
|
||||
.js_event_listeners
|
||||
@ -1608,7 +1608,7 @@ impl<R: Runtime> Window<R> {
|
||||
.insert(id);
|
||||
}
|
||||
|
||||
pub(crate) fn unregister_js_listener(&self, id: u64) {
|
||||
pub(crate) fn unregister_js_listener(&self, id: u32) {
|
||||
let mut empty = None;
|
||||
let mut js_listeners = self.window.js_event_listeners.lock().unwrap();
|
||||
let iter = js_listeners.iter_mut();
|
||||
|
Loading…
Reference in New Issue
Block a user