Skip to content

Commit c1494b3

Browse files
committed
refactor: return Weak<Window> on create_tao_window
1 parent dbe0d21 commit c1494b3

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-runtime-wry": patch
3+
"tauri": patch
4+
---
5+
6+
Refactor `create_tao_window` API to return `Weak<Window>` instead of `Arc<Window>`.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ use std::{
9393
sync::{
9494
atomic::{AtomicBool, Ordering},
9595
mpsc::{channel, Sender},
96-
Arc, Mutex, MutexGuard,
96+
Arc, Mutex, MutexGuard, Weak,
9797
},
9898
thread::{current as current_thread, ThreadId},
9999
};
@@ -976,7 +976,7 @@ pub enum Message {
976976
),
977977
CreateWindow(
978978
Box<dyn FnOnce() -> (String, WryWindowBuilder) + Send>,
979-
Sender<Result<Arc<Window>>>,
979+
Sender<Result<Weak<Window>>>,
980980
),
981981
GlobalShortcut(GlobalShortcutMessage),
982982
Clipboard(ClipboardMessage),
@@ -1485,7 +1485,7 @@ impl WryHandle {
14851485
pub fn create_tao_window<F: FnOnce() -> (String, WryWindowBuilder) + Send + 'static>(
14861486
&self,
14871487
f: F,
1488-
) -> Result<Arc<Window>> {
1488+
) -> Result<Weak<Window>> {
14891489
let (tx, rx) = channel();
14901490
self
14911491
.dispatcher_context
@@ -2181,7 +2181,7 @@ fn handle_event_loop(
21812181
menu_items: Default::default(),
21822182
},
21832183
);
2184-
sender.send(Ok(w)).unwrap();
2184+
sender.send(Ok(Arc::downgrade(&w))).unwrap();
21852185
} else {
21862186
sender.send(Err(Error::CreateWindow)).unwrap();
21872187
}

core/tauri/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use tauri_utils::PackageInfo;
2828
use std::{
2929
collections::HashMap,
3030
path::PathBuf,
31-
sync::{mpsc::Sender, Arc},
31+
sync::{mpsc::Sender, Arc, Weak},
3232
};
3333

3434
use crate::runtime::menu::{Menu, MenuId, MenuIdRef};
@@ -187,7 +187,7 @@ impl AppHandle<crate::Wry> {
187187
>(
188188
&self,
189189
f: F,
190-
) -> crate::Result<Arc<tauri_runtime_wry::Window>> {
190+
) -> crate::Result<Weak<tauri_runtime_wry::Window>> {
191191
self.runtime_handle.create_tao_window(f).map_err(Into::into)
192192
}
193193

0 commit comments

Comments
 (0)