mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-10-19 21:15: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 "Context/ModManContext.h"
|
||||||
#include "Web/Binds/DialogBinds.h"
|
#include "GitVersion.h"
|
||||||
|
#include "Web/Binds/Binds.h"
|
||||||
#include "Web/Platform/AssetHandler.h"
|
#include "Web/Platform/AssetHandler.h"
|
||||||
#include "Web/UiCommunication.h"
|
#include "Web/UiCommunication.h"
|
||||||
#include "Web/ViteAssets.h"
|
#include "Web/ViteAssets.h"
|
||||||
@@ -7,7 +8,6 @@
|
|||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@@ -21,15 +21,17 @@ using namespace PLATFORM_NAMESPACE;
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
std::optional<webview::webview> devToolWindow;
|
void SpawnDevToolsWindow()
|
||||||
|
|
||||||
void RunDevToolsWindow()
|
|
||||||
{
|
{
|
||||||
con::debug("Creating dev tools window");
|
con::debug("Creating dev tools window");
|
||||||
|
|
||||||
|
auto& context = ModManContext::Get();
|
||||||
|
|
||||||
try
|
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_title("Devtools");
|
||||||
newWindow.set_size(640, 480, WEBVIEW_HINT_NONE);
|
newWindow.set_size(640, 480, WEBVIEW_HINT_NONE);
|
||||||
newWindow.set_size(480, 320, WEBVIEW_HINT_MIN);
|
newWindow.set_size(480, 320, WEBVIEW_HINT_MIN);
|
||||||
@@ -42,59 +44,44 @@ namespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int RunMainWindow()
|
int SpawnMainWindow()
|
||||||
{
|
{
|
||||||
con::debug("Creating main window");
|
con::debug("Creating main window");
|
||||||
|
|
||||||
|
auto& context = ModManContext::Get();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
webview::webview w(
|
context.m_main_webview = std::make_unique<webview::webview>(
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
true,
|
true,
|
||||||
#else
|
#else
|
||||||
false,
|
false,
|
||||||
#endif
|
#endif
|
||||||
nullptr);
|
nullptr);
|
||||||
w.set_title("OpenAssetTools ModMan");
|
auto& newWindow = *context.m_main_webview;
|
||||||
w.set_size(1280, 640, WEBVIEW_HINT_NONE);
|
|
||||||
w.set_size(480, 320, WEBVIEW_HINT_MIN);
|
|
||||||
|
|
||||||
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.
|
InstallAssetHandler(newWindow);
|
||||||
ui::Bind<std::string, std::string>(w,
|
ui::RegisterAllBinds(newWindow);
|
||||||
"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
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#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)
|
if (VITE_DEV_SERVER)
|
||||||
{
|
{
|
||||||
w.dispatch(
|
newWindow.dispatch(
|
||||||
[]
|
[]
|
||||||
{
|
{
|
||||||
RunDevToolsWindow();
|
SpawnDevToolsWindow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
w.navigate(std::format("{}index.html", urlPrefix));
|
newWindow.navigate(std::format("{}index.html", URL_PREFIX));
|
||||||
#endif
|
#endif
|
||||||
w.run();
|
newWindow.run();
|
||||||
}
|
}
|
||||||
catch (const webview::exception& e)
|
catch (const webview::exception& e)
|
||||||
{
|
{
|
||||||
@@ -129,7 +116,7 @@ int main()
|
|||||||
|
|
||||||
con::info("Starting ModMan " GIT_VERSION);
|
con::info("Starting ModMan " GIT_VERSION);
|
||||||
|
|
||||||
const auto result = RunMainWindow();
|
const auto result = SpawnMainWindow();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onUnmounted, ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { webviewBinds, webviewAddEventListener, webviewRemoveEventListener } from "./native";
|
import { webviewBinds } from "./native";
|
||||||
|
|
||||||
const greetMsg = ref("");
|
|
||||||
const lastPersonGreeted = ref("");
|
|
||||||
const lastPath = 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() {
|
async function onOpenFastfileClick() {
|
||||||
lastPath.value =
|
lastPath.value =
|
||||||
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
webviewAddEventListener("greeting", onPersonGreeted);
|
|
||||||
|
|
||||||
onUnmounted(() => webviewRemoveEventListener("greeting", onPersonGreeted));
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -30,12 +15,6 @@ onUnmounted(() => webviewRemoveEventListener("greeting", onPersonGreeted));
|
|||||||
<h1>Welcome to ModMan</h1>
|
<h1>Welcome to ModMan</h1>
|
||||||
<small>Nothing to see here yet, this is mainly for testing</small>
|
<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>
|
<p>
|
||||||
<button @click="onOpenFastfileClick">Open fastfile</button>
|
<button @click="onOpenFastfileClick">Open fastfile</button>
|
||||||
<span>The last path: {{ lastPath }}</span>
|
<span>The last path: {{ lastPath }}</span>
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
import type { DialogBinds } from "./DialogBinds";
|
import type { DialogBinds } from "./DialogBinds";
|
||||||
|
|
||||||
|
|
||||||
export type NativeMethods = {
|
export type NativeMethods = DialogBinds;
|
||||||
greet(name: string): Promise<string>;
|
|
||||||
} & DialogBinds;
|
|
||||||
|
|
||||||
interface NativeEventMap {
|
interface NativeEventMap {
|
||||||
greeting: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebViewExtensions = {
|
type WebViewExtensions = {
|
||||||
|
Reference in New Issue
Block a user