diff --git a/example/main.cpp b/example/main.cpp index f59c47b..1f15c6d 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -89,6 +89,13 @@ class example_application : public webframe::application router->set_default(&_archive_handler); router->add_route("/greetingIPC", &_greeting_ipc_handler); } + + void launch_desktop(webframe::desktop_context *context) + { + webframe::window *win = context->create_window(nullptr, 800, 600); + win->set_title("WebFrame Example"); + win->load_path("index.html"); + } private: archive_handler _archive_handler; greeting_ipc_handler _greeting_ipc_handler; diff --git a/include/webframe/config.hpp b/include/webframe/config.hpp index b7a4416..fa9fc81 100644 --- a/include/webframe/config.hpp +++ b/include/webframe/config.hpp @@ -19,6 +19,7 @@ #ifndef WEBFRAME_CONFIG_HPP #define WEBFRAME_CONFIG_HPP +#include #include #include @@ -38,12 +39,16 @@ namespace webframe void set_dark_mode(bool dark_mode); void set_default_window_size(int width, int height); + void set_icon(const std::string& path); + void set_icons(const std::initializer_list& paths); + bool get_dark_mode(bool &dark_mode) const; std::pair get_default_window_size() const; private: std::optional _force_dark_mode; std::pair _default_window_size = {800, 600}; + std::list _icon_paths; }; class server_config diff --git a/include/webframe/context.hpp b/include/webframe/context.hpp index 4beff23..cd31722 100644 --- a/include/webframe/context.hpp +++ b/include/webframe/context.hpp @@ -26,6 +26,8 @@ */ #include + +#include #include namespace webframe @@ -33,6 +35,7 @@ namespace webframe class window { public: + virtual void set_title(const std::string& title) = 0; virtual void load_url(const std::string& url) = 0; virtual void load_path(const std::string& path) = 0; virtual std::string get_id() const = 0; @@ -43,9 +46,11 @@ namespace webframe public: desktop_context() = default; ~desktop_context() = default; + virtual window* create_window(window *parent, int width = -1, int height = -1); virtual window* find_window(const std::string& id); virtual void destroy_window(window* handle); + virtual std::string get_exe_path() const; }; diff --git a/src/config.cpp b/src/config.cpp index 99266d3..2859c3d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,14 +17,24 @@ namespace webframe return result; } + void desktop_config::set_default_window_size(int width, int height) + { + _default_window_size = {width, height}; + } + std::pair desktop_config::get_default_window_size() const { return _default_window_size; } - void desktop_config::set_default_window_size(int width, int height) + void desktop_config::set_icon(const std::string &path) { - _default_window_size = {width, height}; + _icon_paths.push_back(path); + } + + void desktop_config::set_icons(const std::initializer_list &paths) + { + _icon_paths.insert(_icon_paths.end(), paths); } void server_config::set_host(const std::string &host) diff --git a/src/runtimes/desktop/include/desktop/window.hpp b/src/runtimes/desktop/include/desktop/window.hpp index 9cf4830..b539f83 100644 --- a/src/runtimes/desktop/include/desktop/window.hpp +++ b/src/runtimes/desktop/include/desktop/window.hpp @@ -10,12 +10,15 @@ namespace webframe::desktop public: window(wxFrame *frame, wxSharedPtr webview_handler); ~window() = default; + void load_path(const std::string &path) override; void load_url(const std::string &url) override; - std::string get_id() const override; + std::string get_id() const override; wxFrame *get_frame() const; + void set_title(const std::string &title) override; + private: std::unique_ptr _frame; wxWebView *_webview; diff --git a/src/runtimes/desktop/window.cpp b/src/runtimes/desktop/window.cpp index 4f409ab..ed33c06 100644 --- a/src/runtimes/desktop/window.cpp +++ b/src/runtimes/desktop/window.cpp @@ -50,4 +50,10 @@ namespace webframe::desktop { return _frame.get(); } + + void window::set_title(const std::string &title) + { + wxString wx_title = wxString(title.c_str()); + _frame->SetTitle(wx_title); + } }