From 3ce86df1d69b9f0db34a441b23edbb4b87edfa22 Mon Sep 17 00:00:00 2001 From: Fleeym <61891787+Fleeym@users.noreply.github.com> Date: Thu, 13 Jun 2024 04:09:53 +0300 Subject: [PATCH] maybe mac fix 3 --- loader/src/platform/mac/util.mm | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/loader/src/platform/mac/util.mm b/loader/src/platform/mac/util.mm index 077c0690..ccf76e33 100644 --- a/loader/src/platform/mac/util.mm +++ b/loader/src/platform/mac/util.mm @@ -162,22 +162,33 @@ namespace { GEODE_DLL Task> file::pick(file::PickMode mode, file::FilePickOptions const& options) { using RetTask = Task>; - [FileDialog dispatchFilePickerWithMode:mode options:options multiple:false onCompletion: ^(FileResult result) { - if (result.isOk()) { - std::filesystem::path path = result.unwrap()[0]; - return RetTask::immediate(Ok(path)); - } else { - return RetTask::immediate(Err(result.err().unwrap())); - } - }]; + return RetTask::runWithCallback([mode, options](auto resultCallback, auto progress, auto cancelled) { + [FileDialog dispatchFilePickerWithMode:mode options:options multiple:false onCompletion: ^(FileResult result) { + if (cancelled()) { + resultCallback(RetTask::Cancel()); + } else { + if (result.isOk()) { + std::filesystem::path path = result.unwrap()[0]; + resultCallback(Ok(path)); + } else { + resultCallback(Err(result.err().value())); + } + } + }]; + }); } GEODE_DLL Task>> file::pickMany(file::FilePickOptions const& options) { using RetTask = Task>>; - [FileDialog dispatchFilePickerWithMode:mode options:options multiple:true onCompletion: ^(FileResult result) { - return RetTask::immediate(result); - }]; - + return RetTask::runWithCallback([options](auto resultCallback, auto progress, auto cancelled) { + [FileDialog dispatchFilePickerWithMode:mode options:options multiple:true onCompletion: ^(FileResult result) { + if (cancelled()) { + resultCallback(RetTask::Cancel()); + } else { + resultCallback(result); + } + }]; + }) } CCPoint cocos::getMousePos() {