Refactor HWND management and modularize initialization

Centralized HWND handling into a dedicated `hwnd_module` for improved clarity and modularity. Updated `toolboxWindow` and `optionWindow` to use the new module abstraction. Adjusted related initialization code for better structure and maintainability.
This commit is contained in:
2025-01-19 19:17:35 +01:00
parent c93758f732
commit 9e3c9f4d0e
9 changed files with 52 additions and 26 deletions

View File

@@ -6,25 +6,34 @@
#define HWND_MODULE_H
#include <saucer/modules/native/webview2.hpp> // Für Windows mit WebView2
#include <execution>
#include <saucer/smartview.hpp>
#include <saucer/modules/stable/webview2.hpp> // Für Windows mit WebView2
class hwnd_module {
saucer::natives m_natives;
saucer::smartview_core *m_smartview;
saucer::webview *m_parent;
public:
explicit hwnd_module(saucer::webview *parent)
: m_parent(parent) {}
HWND get_hwnd() const
{
if (auto [window, webview] = m_parent->native<>(); !webview) {
throw std::runtime_error("WebView instance is null.");
}
HWND parent = nullptr;
if (FAILED(m_parent->native<>().controller->get_ParentWindow(&parent))) {
throw std::runtime_error("Failed to retrieve HWND from WebView.");
}
return parent;
}
public:
hwnd_module(saucer::smartview_core *smartview, saucer::natives natives)
: m_natives(natives), m_smartview(smartview) {}
HWND get_hwnd() {
auto [window, webview] = m_natives;
return window->hwnd.get();
}
};
static_assert(saucer::Module<hwnd_module>);
static_assert(saucer::Module<hwnd_module, saucer::webview>);
#endif //HWND_MODULE_H

View File

@@ -17,10 +17,12 @@ public:
// Für die Fensterinitialisierung
void initialize();
void setHWND(HWND hwnd);
private:
std::shared_ptr<saucer::application> m_app;
saucer::smartview<saucer::default_serializer, hwnd_module> m_webview;
saucer::smartview<saucer::default_serializer> m_webview;
HWND m_hwnd;
void configureWindow();
void loadResources();

View File

@@ -40,9 +40,11 @@ public:
std::vector<ToolboxItem> m_toolboxItems;
saucer::smartview<saucer::default_serializer, hwnd_module> m_webview;
saucer::smartview<saucer::default_serializer> m_webview;
private:
hwnd_module* m_hwnd_module;
HWND m_hwnd;
std::shared_ptr<saucer::application> m_app;
std::thread m_threadMonitor;
std::atomic<bool> m_runningMonitor = true;