fix: clipboard.readImage()
should be synchronous (#39069)
* feat: clipboard.readImage returns a Promise * chore: update breaking changes doc * fix: make function synchronous * Update docs/api/native-image.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> --------- Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
34e7c3696a
commit
f61425efdb
1 changed files with 9 additions and 2 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <map>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "shell/common/gin_converters/image_converter.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
|
@ -221,17 +222,23 @@ void Clipboard::WriteBookmark(const std::u16string& title,
|
|||
gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) {
|
||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||
absl::optional<gfx::Image> image;
|
||||
|
||||
base::RunLoop run_loop;
|
||||
base::RepeatingClosure callback = run_loop.QuitClosure();
|
||||
clipboard->ReadPng(
|
||||
GetClipboardBuffer(args),
|
||||
/* data_dst = */ nullptr,
|
||||
base::BindOnce(
|
||||
[](absl::optional<gfx::Image>* image,
|
||||
[](absl::optional<gfx::Image>* image, base::RepeatingClosure cb,
|
||||
const std::vector<uint8_t>& result) {
|
||||
SkBitmap bitmap;
|
||||
gfx::PNGCodec::Decode(result.data(), result.size(), &bitmap);
|
||||
image->emplace(gfx::Image::CreateFrom1xBitmap(bitmap));
|
||||
std::move(cb).Run();
|
||||
},
|
||||
&image));
|
||||
&image, std::move(callback)));
|
||||
run_loop.Run();
|
||||
|
||||
DCHECK(image.has_value());
|
||||
return image.value();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue