2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-18 03:02:07 +00:00

chore: save shared modman info in context

This commit is contained in:
Jan Laupetin
2025-10-10 10:57:07 +01:00
parent 9845b0a889
commit 219f0c1c85
7 changed files with 68 additions and 64 deletions

View File

@@ -1,5 +1,6 @@
#include "GitVersion.h"
#include "Web/Binds/DialogBinds.h"
#include "Context/ModManContext.h"
#include "GitVersion.h"
#include "Web/Binds/Binds.h"
#include "Web/Platform/AssetHandler.h"
#include "Web/UiCommunication.h"
#include "Web/ViteAssets.h"
@@ -7,7 +8,6 @@
#include <format>
#include <iostream>
#include <optional>
#include <string>
#include <thread>
@@ -21,15 +21,17 @@ using namespace PLATFORM_NAMESPACE;
namespace
{
#ifdef _DEBUG
std::optional<webview::webview> devToolWindow;
void RunDevToolsWindow()
void SpawnDevToolsWindow()
{
con::debug("Creating dev tools window");
auto& context = ModManContext::Get();
try
{
auto& newWindow = devToolWindow.emplace(false, nullptr);
context.m_dev_tools_webview = std::make_unique<webview::webview>(false, nullptr);
auto& newWindow = *context.m_dev_tools_webview;
newWindow.set_title("Devtools");
newWindow.set_size(640, 480, WEBVIEW_HINT_NONE);
newWindow.set_size(480, 320, WEBVIEW_HINT_MIN);
@@ -42,59 +44,44 @@ namespace
}
#endif
int RunMainWindow()
int SpawnMainWindow()
{
con::debug("Creating main window");
auto& context = ModManContext::Get();
try
{
webview::webview w(
context.m_main_webview = std::make_unique<webview::webview>(
#ifdef _DEBUG
true,
#else
false,
#endif
nullptr);
w.set_title("OpenAssetTools ModMan");
w.set_size(1280, 640, WEBVIEW_HINT_NONE);
w.set_size(480, 320, WEBVIEW_HINT_MIN);
auto& newWindow = *context.m_main_webview;
ui::RegisterDialogHandlerBinds(w);
newWindow.set_title("OpenAssetTools ModMan");
newWindow.set_size(1280, 640, WEBVIEW_HINT_NONE);
newWindow.set_size(480, 320, WEBVIEW_HINT_MIN);
// A binding that counts up or down and immediately returns the new value.
ui::Bind<std::string, std::string>(w,
"greet",
[&w](std::string name) -> std::string
{
ui::Notify(w, "greeting", name);
return std::format("Hello from C++ {}!", name);
});
#if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
InstallAssetHandler(w);
constexpr auto urlPrefix = URL_PREFIX;
#elif defined(WEBVIEW_PLATFORM_LINUX) && defined(WEBVIEW_GTK)
InstallAssetHandler(w);
constexpr auto urlPrefix = URL_PREFIX;
#else
#error Unsupported platform
#endif
InstallAssetHandler(newWindow);
ui::RegisterAllBinds(newWindow);
#ifdef _DEBUG
w.navigate(VITE_DEV_SERVER ? std::format("http://localhost:{}", VITE_DEV_SERVER_PORT) : std::format("{}index.html", urlPrefix));
newWindow.navigate(VITE_DEV_SERVER ? std::format("http://localhost:{}", VITE_DEV_SERVER_PORT) : std::format("{}index.html", URL_PREFIX));
if (VITE_DEV_SERVER)
{
w.dispatch(
newWindow.dispatch(
[]
{
RunDevToolsWindow();
SpawnDevToolsWindow();
});
}
#else
w.navigate(std::format("{}index.html", urlPrefix));
newWindow.navigate(std::format("{}index.html", URL_PREFIX));
#endif
w.run();
newWindow.run();
}
catch (const webview::exception& e)
{
@@ -129,7 +116,7 @@ int main()
con::info("Starting ModMan " GIT_VERSION);
const auto result = RunMainWindow();
const auto result = SpawnMainWindow();
return result;
}