Own Web platform services and remove legacy web state
This commit is contained in:
61
src/platform_web/web_platform_services.cpp
Normal file
61
src/platform_web/web_platform_services.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "platform_web/web_platform_services.h"
|
||||
|
||||
#include "platform_api/platform_policy.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#if defined(__WEB__)
|
||||
void webgl_pick_file_save(
|
||||
const std::string& path,
|
||||
const std::string& name,
|
||||
std::function<void(bool)> callback);
|
||||
void webgl_sync();
|
||||
#endif
|
||||
|
||||
namespace pp::platform::web {
|
||||
|
||||
void WebPlatformServices::publish_exported_image(std::string_view path)
|
||||
{
|
||||
(void)path;
|
||||
}
|
||||
|
||||
void WebPlatformServices::flush_persistent_storage()
|
||||
{
|
||||
#if defined(__WEB__)
|
||||
webgl_sync();
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] int WebPlatformServices::default_canvas_resolution()
|
||||
{
|
||||
return pp::platform::platform_default_canvas_resolution(pp::platform::PlatformFamily::webgl);
|
||||
}
|
||||
|
||||
void WebPlatformServices::save_prepared_file(
|
||||
std::string_view path,
|
||||
std::string_view suggested_name,
|
||||
PreparedFileCallback callback)
|
||||
{
|
||||
const std::string value(path);
|
||||
const std::string name(suggested_name);
|
||||
#if defined(__WEB__)
|
||||
webgl_pick_file_save(
|
||||
value,
|
||||
name,
|
||||
[callback = std::move(callback), value](bool success) {
|
||||
callback(value, success);
|
||||
});
|
||||
#else
|
||||
(void)name;
|
||||
callback(value, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_web_platform_services()
|
||||
{
|
||||
return std::make_unique<WebPlatformServices>();
|
||||
}
|
||||
|
||||
}
|
||||
23
src/platform_web/web_platform_services.h
Normal file
23
src/platform_web/web_platform_services.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform_api/platform_services.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace pp::platform::web {
|
||||
|
||||
class WebPlatformServices final : public pp::platform::WebPlatformServices {
|
||||
public:
|
||||
void publish_exported_image(std::string_view path) override;
|
||||
void flush_persistent_storage() override;
|
||||
[[nodiscard]] int default_canvas_resolution() override;
|
||||
void save_prepared_file(
|
||||
std::string_view path,
|
||||
std::string_view suggested_name,
|
||||
PreparedFileCallback callback) override;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_web_platform_services();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user