macOS: fix a crash when dragging non-file content onto window

Winit only supports text, thus we should ignore the rest
instead of crashing.
This commit is contained in:
Dan Harris 2025-11-04 20:20:01 -08:00 committed by GitHub
parent a9c189a423
commit 82eab465e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View file

@ -353,13 +353,16 @@ define_class!(
use std::path::PathBuf;
let pb = sender.draggingPasteboard();
#[allow(deprecated)]
let filenames = pb
.propertyListForType(unsafe { NSFilenamesPboardType })
.unwrap()
let property_list = match pb.propertyListForType(unsafe { NSFilenamesPboardType }) {
Some(property_list) => property_list,
None => return false.into(),
};
let paths = property_list
.downcast::<NSArray>()
.unwrap();
let paths = filenames
.unwrap()
.into_iter()
.map(|file| PathBuf::from(file.downcast::<NSString>().unwrap().to_string()))
.collect();
@ -411,13 +414,16 @@ define_class!(
use std::path::PathBuf;
let pb = sender.draggingPasteboard();
#[allow(deprecated)]
let filenames = pb
.propertyListForType(unsafe { NSFilenamesPboardType })
.unwrap()
let property_list = match pb.propertyListForType(unsafe { NSFilenamesPboardType }) {
Some(property_list) => property_list,
None => return false.into(),
};
let paths = property_list
.downcast::<NSArray>()
.unwrap();
let paths = filenames
.unwrap()
.into_iter()
.map(|file| PathBuf::from(file.downcast::<NSString>().unwrap().to_string()))
.collect();

View file

@ -272,3 +272,4 @@ changelog entry.
- On Web, device events are emitted regardless of cursor type.
- On Wayland, `axis_value120` scroll events now generate `MouseScrollDelta::LineDelta`
- On X11, mouse scroll button events no longer cause duplicated `WindowEvent::MouseWheel` events.
- On macOS, fixed crash when dragging non-file content onto window.