mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-10-19 13:05:20 +00:00
chore: save shared modman info in context
This commit is contained in:
7
src/ModMan/Context/ModManContext.cpp
Normal file
7
src/ModMan/Context/ModManContext.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "ModManContext.h"
|
||||
|
||||
ModManContext& ModManContext::Get()
|
||||
{
|
||||
static ModManContext context;
|
||||
return context;
|
||||
}
|
14
src/ModMan/Context/ModManContext.h
Normal file
14
src/ModMan/Context/ModManContext.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Web/WebViewLib.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ModManContext
|
||||
{
|
||||
public:
|
||||
static ModManContext& Get();
|
||||
|
||||
std::unique_ptr<webview::webview> m_main_webview;
|
||||
std::unique_ptr<webview::webview> m_dev_tools_webview;
|
||||
};
|
11
src/ModMan/Web/Binds/Binds.cpp
Normal file
11
src/ModMan/Web/Binds/Binds.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "Binds.h"
|
||||
|
||||
#include "Web/Binds/DialogBinds.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
void RegisterAllBinds(webview::webview& wv)
|
||||
{
|
||||
RegisterDialogHandlerBinds(wv);
|
||||
}
|
||||
} // namespace ui
|
8
src/ModMan/Web/Binds/Binds.h
Normal file
8
src/ModMan/Web/Binds/Binds.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Web/WebViewLib.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
void RegisterAllBinds(webview::webview& wv);
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -1,28 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { onUnmounted, ref } from "vue";
|
||||
import { webviewBinds, webviewAddEventListener, webviewRemoveEventListener } from "./native";
|
||||
import { ref } from "vue";
|
||||
import { webviewBinds } from "./native";
|
||||
|
||||
const greetMsg = ref("");
|
||||
const lastPersonGreeted = ref("");
|
||||
const lastPath = ref("");
|
||||
const name = ref("");
|
||||
|
||||
async function greet() {
|
||||
greetMsg.value = await webviewBinds.greet(name.value);
|
||||
}
|
||||
|
||||
function onPersonGreeted(person: string) {
|
||||
lastPersonGreeted.value = person;
|
||||
}
|
||||
|
||||
async function onOpenFastfileClick() {
|
||||
lastPath.value =
|
||||
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
||||
}
|
||||
|
||||
webviewAddEventListener("greeting", onPersonGreeted);
|
||||
|
||||
onUnmounted(() => webviewRemoveEventListener("greeting", onPersonGreeted));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -30,12 +15,6 @@ onUnmounted(() => webviewRemoveEventListener("greeting", onPersonGreeted));
|
||||
<h1>Welcome to ModMan</h1>
|
||||
<small>Nothing to see here yet, this is mainly for testing</small>
|
||||
|
||||
<form class="row" @submit.prevent="greet">
|
||||
<input id="greet-input" v-model="name" placeholder="Enter a name..." autocomplete="off" />
|
||||
<button type="submit">Greet</button>
|
||||
</form>
|
||||
<p>{{ greetMsg }}</p>
|
||||
<p>The last person greeted is: {{ lastPersonGreeted }}</p>
|
||||
<p>
|
||||
<button @click="onOpenFastfileClick">Open fastfile</button>
|
||||
<span>The last path: {{ lastPath }}</span>
|
||||
|
@@ -1,12 +1,10 @@
|
||||
import type { DialogBinds } from "./DialogBinds";
|
||||
|
||||
|
||||
export type NativeMethods = {
|
||||
greet(name: string): Promise<string>;
|
||||
} & DialogBinds;
|
||||
export type NativeMethods = DialogBinds;
|
||||
|
||||
interface NativeEventMap {
|
||||
greeting: string;
|
||||
|
||||
}
|
||||
|
||||
type WebViewExtensions = {
|
||||
|
Reference in New Issue
Block a user