Skip to content

Commit

Permalink
Merge pull request #12 from crabnebula-dev/fix/check-files-exist
Browse files Browse the repository at this point in the history
fix(macos): check if image file exists to prevent crash
  • Loading branch information
lucasfernog-crabnebula authored Dec 7, 2023
2 parents 4f588b5 + 592cd30 commit 935b34f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/drag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ pub enum Error {
UnsupportedWindowHandle,
#[error("failed to start drag")]
FailedToStartDrag,
#[error("drag image not found")]
ImageNotFound,
#[cfg(target_os = "linux")]
#[error("empty drag target list")]
EmptyTargetList,
Expand Down
3 changes: 3 additions & 0 deletions crates/drag/src/platform_impl/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub fn start_drag<W: HasRawWindowHandle>(
let img: id = msg_send![class!(NSImage), alloc];
let img: id = match image {
Image::File(path) => {
if !path.exists() {
return Err(crate::Error::ImageNotFound);
}
NSImage::initByReferencingFile_(img, new_nsstring(&path.to_string_lossy()))
}
Image::Raw(bytes) => {
Expand Down

0 comments on commit 935b34f

Please sign in to comment.