diff --git a/example/frontend/cat.jpg b/example/frontend/cat.jpg new file mode 100644 index 0000000..3bdff96 Binary files /dev/null and b/example/frontend/cat.jpg differ diff --git a/example/frontend/index.html b/example/frontend/index.html index 2785b06..269b34d 100644 --- a/example/frontend/index.html +++ b/example/frontend/index.html @@ -1,24 +1,21 @@ - - - - WebFrame - - - -
-

WebFrame

-
- -
- - - -
- - - + + + + + WebFrame Example + + + + + +
+
+ + + +
+
+ \ No newline at end of file diff --git a/example/frontend/style.css b/example/frontend/style.css new file mode 100644 index 0000000..c987eb0 --- /dev/null +++ b/example/frontend/style.css @@ -0,0 +1,44 @@ +html, +body { + height: 100%; + margin: 0; + font-family: Arial, sans-serif; +} + +body { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: linear-gradient(to bottom, darkcyan, darkgray); + /* Gradient background */ +} + +.logo { + margin-bottom: 24px; +} + +.divClass { + text-align: center; + color: #ffffff; + /* White text color */ + font-size: 2.5rem; + /* Adjusted font size */ + font-weight: 700; + /* Bold text */ + background: rgba(0, 0, 0, 0.6); + /* Semi-transparent background */ + padding: 20px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); +} + +.divClass div { + margin-bottom: 10px; +} + +.divClass div:last-child { + margin-bottom: 0; + font-size: 1.5rem; + /* Smaller font size for the second line */ +} \ No newline at end of file diff --git a/example/main.cpp b/example/main.cpp index 27516c2..f59c47b 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -40,7 +40,7 @@ class archive_handler : public webframe::handler else { res->set_status(404); res->set_header("Content-Type", "text/plain"); - const std::string not_found_msg = "404 Not Found"; + const std::string not_found_msg = "Not Found"; res->set_body(reinterpret_cast(not_found_msg.data()), not_found_msg.size()); } } diff --git a/src/runtimes/desktop/desktop.hpp b/src/runtimes/desktop/desktop.hpp index 0a17523..d5edc36 100644 --- a/src/runtimes/desktop/desktop.hpp +++ b/src/runtimes/desktop/desktop.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include diff --git a/src/runtimes/desktop/response.cpp b/src/runtimes/desktop/response.cpp index a6ac3e9..c836b70 100644 --- a/src/runtimes/desktop/response.cpp +++ b/src/runtimes/desktop/response.cpp @@ -1,5 +1,31 @@ #include +class response_body_writer : public wxWebViewHandlerResponseData +{ +public: + response_body_writer() = default; + ~response_body_writer() = default; + + wxInputStream *GetStream() override + { + if (!_stream) + { + _stream = std::make_unique(_buffer.data(), _buffer.size()); + } + return _stream.get(); + } + + void write(const uint8_t *data, size_t size) + { + _buffer.insert(_buffer.end(), data, data + size); + } + +private: + std::vector _buffer; + std::unique_ptr _stream; +}; + + namespace webframe { namespace desktop @@ -20,27 +46,27 @@ namespace webframe void response::set_body(const uint8_t *data, size_t size) { - _response->Finish(std::string(reinterpret_cast(data), size)); + std::unique_ptr body_writer = std::make_unique(); + body_writer->write(data, size); + _response->Finish(wxSharedPtr(body_writer.release())); _sent = true; } void response::write_body(const std::function &)> &callback) { - std::vector buffer; - bool has_more_data = true; - while (has_more_data) + std::unique_ptr body_writer = std::make_unique(); + bool has_more(true); + while(has_more) { std::pair data; - if (callback(data)) - { - buffer.insert(buffer.end(), data.first, data.first + data.second); - } - else + has_more = callback(data); + if (data.first && data.second) { - has_more_data = false; + body_writer->write(data.first, data.second); } } - set_body(buffer.data(), buffer.size()); + _response->Finish(wxSharedPtr(body_writer.release())); + _sent = true; } } } \ No newline at end of file