mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-17 18:52:06 +00:00
feat: add modman title handler for windows
This commit is contained in:
63
src/ModMan/Web/Platform/Windows/TitleHandlerWindows.cpp
Normal file
63
src/ModMan/Web/Platform/Windows/TitleHandlerWindows.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "AssetHandlerWindows.h"
|
||||||
|
|
||||||
|
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
|
||||||
|
|
||||||
|
#include "PlatformUtilsWindows.h"
|
||||||
|
#include "Web/UiAssets.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <format>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <webview/detail/backends/win32_edge.hh>
|
||||||
|
#include <wrl/event.h>
|
||||||
|
|
||||||
|
using namespace PLATFORM_NAMESPACE_WINDOWS;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
HRESULT HandleTitleChanged(ICoreWebView2* core, HWND window)
|
||||||
|
{
|
||||||
|
LPWSTR title;
|
||||||
|
|
||||||
|
if (!SUCCEEDED(core->get_DocumentTitle(&title)))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to get title\n";
|
||||||
|
return S_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetWindowTextW(window, title);
|
||||||
|
CoTaskMemFree(title);
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace PLATFORM_NAMESPACE_WINDOWS
|
||||||
|
{
|
||||||
|
void InstallTitleHandler(webview::webview& wv)
|
||||||
|
{
|
||||||
|
const auto controller = static_cast<ICoreWebView2Controller*>(wv.browser_controller().value());
|
||||||
|
auto window = static_cast<HWND>(wv.window().value());
|
||||||
|
Microsoft::WRL::ComPtr<ICoreWebView2> core;
|
||||||
|
if (!SUCCEEDED(controller->get_CoreWebView2(&core)))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to get webview\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventRegistrationToken token;
|
||||||
|
if (!SUCCEEDED(core->add_DocumentTitleChanged(Microsoft::WRL::Callback<ICoreWebView2DocumentTitleChangedEventHandler>(
|
||||||
|
[window](ICoreWebView2* sender, IUnknown* args) -> HRESULT
|
||||||
|
{
|
||||||
|
return HandleTitleChanged(sender, window);
|
||||||
|
})
|
||||||
|
.Get(),
|
||||||
|
&token)))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to add title handler\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace PLATFORM_NAMESPACE_WINDOWS
|
||||||
|
|
||||||
|
#endif
|
||||||
16
src/ModMan/Web/Platform/Windows/TitleHandlerWindows.h
Normal file
16
src/ModMan/Web/Platform/Windows/TitleHandlerWindows.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Web/Platform/Platform.h"
|
||||||
|
|
||||||
|
#include <webview/macros.h>
|
||||||
|
|
||||||
|
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
|
||||||
|
|
||||||
|
#include "Web/WebViewLib.h"
|
||||||
|
|
||||||
|
namespace PLATFORM_NAMESPACE_WINDOWS
|
||||||
|
{
|
||||||
|
void InstallTitleHandler(webview::webview& wv);
|
||||||
|
} // namespace PLATFORM_NAMESPACE_WINDOWS
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "Web/Binds/Binds.h"
|
#include "Web/Binds/Binds.h"
|
||||||
#include "Web/Platform/AssetHandler.h"
|
#include "Web/Platform/AssetHandler.h"
|
||||||
#include "Web/Platform/Windows/FaviconHandlerWindows.h"
|
#include "Web/Platform/Windows/FaviconHandlerWindows.h"
|
||||||
|
#include "Web/Platform/Windows/TitleHandlerWindows.h"
|
||||||
#include "Web/UiCommunication.h"
|
#include "Web/UiCommunication.h"
|
||||||
#include "Web/ViteAssets.h"
|
#include "Web/ViteAssets.h"
|
||||||
#include "Web/WebViewLib.h"
|
#include "Web/WebViewLib.h"
|
||||||
@@ -34,6 +35,7 @@ namespace
|
|||||||
context.m_dev_tools_webview = std::make_unique<webview::webview>(false, nullptr);
|
context.m_dev_tools_webview = std::make_unique<webview::webview>(false, nullptr);
|
||||||
auto& newWindow = *context.m_dev_tools_webview;
|
auto& newWindow = *context.m_dev_tools_webview;
|
||||||
InstallFaviconHandler(newWindow);
|
InstallFaviconHandler(newWindow);
|
||||||
|
InstallTitleHandler(newWindow);
|
||||||
|
|
||||||
newWindow.set_title("Devtools");
|
newWindow.set_title("Devtools");
|
||||||
newWindow.set_size(640, 480, WEBVIEW_HINT_NONE);
|
newWindow.set_size(640, 480, WEBVIEW_HINT_NONE);
|
||||||
@@ -69,6 +71,7 @@ namespace
|
|||||||
|
|
||||||
InstallAssetHandler(newWindow);
|
InstallAssetHandler(newWindow);
|
||||||
InstallFaviconHandler(newWindow);
|
InstallFaviconHandler(newWindow);
|
||||||
|
InstallTitleHandler(newWindow);
|
||||||
ui::RegisterAllBinds(newWindow);
|
ui::RegisterAllBinds(newWindow);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user