Skip to content

Commit

Permalink
Add name parameter to putImageBytes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuk4ze committed Feb 4, 2024
1 parent 1dc30e3 commit d76ae5f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions windows/gal_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.System.h>

#include <thread>

namespace gal {
Expand Down Expand Up @@ -95,15 +96,16 @@ static IAsyncAction PutMedia(string path, const optional<string> album) {
}

static IAsyncAction PutMediaBytes(const vector<uint8_t>& bytes,
const optional<string> album) {
const optional<string> album,
const string name) {
auto folder = KnownFolders::PicturesLibrary();
if (album) {
folder = co_await folder.CreateFolderAsync(
winrt::to_hstring(album.value()),
CreationCollisionOption::OpenIfExists);
}
auto file = co_await folder.CreateFileAsync(
L"image." + GetExtension(bytes),
winrt::to_hstring(name) + L"." + GetExtension(bytes),
CreationCollisionOption::GenerateUniqueName);

auto stream = co_await file.OpenAsync(FileAccessMode::ReadWrite);
Expand Down Expand Up @@ -161,9 +163,10 @@ void GalPlugin::HandleMethodCall(
if (auto p = std::get_if<string>(&args->at(EncodableValue("album")))) {
album.emplace(*p);
}
std::thread([bytes, album, result = std::move(result)]() mutable {
const auto name = std::get<string>(args->at(EncodableValue("name")));
std::thread([bytes, album, name, result = std::move(result)]() mutable {
try {
PutMediaBytes(bytes, album).get();
PutMediaBytes(bytes, album, name).get();
result->Success();
} catch (const winrt::hresult_error& e) {
HandleError(e, std::move(result));
Expand Down

0 comments on commit d76ae5f

Please sign in to comment.