mirror of
https://github.com/tauri-apps/tao.git
synced 2026-01-31 00:35:16 +01:00
On macOS, fix wry window can crash if unfocused (#714)
This commit is contained in:
committed by
GitHub
parent
407a9feaed
commit
6a03847f6d
6
.changes/views.md
Normal file
6
.changes/views.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"tao": patch
|
||||
---
|
||||
|
||||
On macOS, fix wry window will crash if unfocused.
|
||||
|
||||
@@ -34,6 +34,9 @@ use crate::{
|
||||
|
||||
pub struct WindowDelegateState {
|
||||
ns_window: IdRef, // never changes
|
||||
// We keep this ns_view because we still need its view state for some extern function
|
||||
// like didResignKey
|
||||
ns_view: IdRef, // never changes
|
||||
|
||||
window: Weak<UnownedWindow>,
|
||||
|
||||
@@ -60,6 +63,7 @@ impl WindowDelegateState {
|
||||
let scale_factor = window.scale_factor();
|
||||
let mut delegate_state = WindowDelegateState {
|
||||
ns_window: window.ns_window.clone(),
|
||||
ns_view: window.ns_view.clone(),
|
||||
window: Arc::downgrade(window),
|
||||
initial_fullscreen,
|
||||
previous_position: None,
|
||||
@@ -398,7 +402,7 @@ extern "C" fn window_did_resign_key(this: &Object, _: Sel, _: id) {
|
||||
// Object referenced by state.ns_view (an IdRef, which is dereferenced
|
||||
// to an id)
|
||||
let view_state: &mut ViewState = unsafe {
|
||||
let ns_view: &Object = state.ns_view().as_ref().expect("failed to deref");
|
||||
let ns_view: &Object = (*state.ns_view).as_ref().expect("failed to deref");
|
||||
let state_ptr: *mut c_void = *ns_view.get_ivar("taoState");
|
||||
&mut *(state_ptr as *mut ViewState)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user