2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-10-28 17:16:56 +00:00

chore: update modman vite setup to support dev server

This commit is contained in:
Jan Laupetin
2025-10-06 21:19:02 +02:00
parent 047fabb546
commit 4f24b9ce86
7 changed files with 164 additions and 96 deletions

View File

@@ -18,6 +18,8 @@
namespace
{
constexpr auto LOCALHOST_PREFIX = "http://localhost:";
std::unordered_map<std::string, UiFile> assetLookup;
std::string WideStringToString(const std::wstring& wideString)
@@ -95,6 +97,13 @@ namespace
const auto uri = WideStringToString(wUri);
bool fileFound = false;
#ifdef _DEBUG
// Allow dev server access
if (uri.starts_with(LOCALHOST_PREFIX))
return S_OK;
#endif
if (uri.starts_with(edge::URL_PREFIX))
{
const auto asset = uri.substr(std::char_traits<char>::length(edge::URL_PREFIX) - 1);

View File

@@ -1,6 +1,6 @@
#pragma once
#include "ui/modmanui.h"
#include "Web/ViteAssets.h"
#include <string>
#include <unordered_map>

View File

@@ -2,6 +2,7 @@
#include "webview/webview.h"
#pragma warning(pop)
#include "Web/ViteAssets.h"
#include "Web/Edge/AssetHandlerEdge.h"
#include "Web/Gtk/AssetHandlerGtk.h"
@@ -58,12 +59,19 @@ int main()
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
edge::InstallCustomProtocolHandler(w);
w.navigate(edge::URL_PREFIX + "index.html"s);
constexpr auto urlPrefix = edge::URL_PREFIX;
#elif defined(WEBVIEW_PLATFORM_LINUX) && defined(WEBVIEW_GTK)
gtk::InstallCustomProtocolHandler(w);
w.navigate(gtk::URL_PREFIX + "index.html"s);
constexpr auto urlPrefix = gtk::URL_PREFIX;
#else
#error Unsupported platform
#endif
#ifdef _DEBUG
w.navigate(VITE_DEV_SERVER ? std::format("http://localhost:{}", VITE_DEV_SERVER_PORT) : std::format("{}index.html", urlPrefix));
#else
w.navigate(std::format("{}index.html", urlPrefix));
#endif
w.run();
}
catch (const webview::exception& e)