Convert URLs to paths returned from NSSavePanel using [Url path]

This commit is contained in:
Antonio Scandurra 2021-07-06 15:48:07 +02:00
parent 39d3b21780
commit ed1eb24ee2

View File

@ -317,15 +317,10 @@ impl platform::Platform for MacPlatform {
let block = ConcreteBlock::new(move |response: NSModalResponse| {
let result = if response == NSModalResponse::NSModalResponseOk {
let url = panel.URL();
let string = url.absoluteString();
let string = std::ffi::CStr::from_ptr(string.UTF8String())
let path = std::ffi::CStr::from_ptr(url.path().UTF8String())
.to_string_lossy()
.to_string();
if let Some(path) = string.strip_prefix("file://") {
Some(PathBuf::from(path))
} else {
None
}
Some(PathBuf::from(path))
} else {
None
};