mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-10-09 08:16:41 +00:00
chore: use new webview fork notify mechanism
This commit is contained in:
@@ -68,6 +68,7 @@ namespace
|
|||||||
[&](const std::string& req) -> std::string
|
[&](const std::string& req) -> std::string
|
||||||
{
|
{
|
||||||
const auto name = req.substr(2, req.size() - 4);
|
const auto name = req.substr(2, req.size() - 4);
|
||||||
|
w.notify("greeting", webview::json_escape(name));
|
||||||
return webview::json_escape(std::format("Hello from C++ {}!", name));
|
return webview::json_escape(std::format("Hello from C++ {}!", name));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,13 +1,22 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from "vue";
|
import { onUnmounted, ref } from "vue";
|
||||||
import { nativeMethods } from "./native";
|
import { webviewBinds, webViewAddEventListener, webViewRemoveEventListener } from "./native";
|
||||||
|
|
||||||
const greetMsg = ref("");
|
const greetMsg = ref("");
|
||||||
|
const lastPersonGreeted = ref("");
|
||||||
const name = ref("");
|
const name = ref("");
|
||||||
|
|
||||||
async function greet() {
|
async function greet() {
|
||||||
greetMsg.value = await nativeMethods.greet(name.value);
|
greetMsg.value = await webviewBinds.greet(name.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onPersonGreeted(person: string) {
|
||||||
|
lastPersonGreeted.value = person;
|
||||||
|
}
|
||||||
|
|
||||||
|
webViewAddEventListener("greeting", onPersonGreeted);
|
||||||
|
|
||||||
|
onUnmounted(() => webViewRemoveEventListener("greeting", onPersonGreeted));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -19,6 +28,7 @@ async function greet() {
|
|||||||
<button type="submit">Greet</button>
|
<button type="submit">Greet</button>
|
||||||
</form>
|
</form>
|
||||||
<p>{{ greetMsg }}</p>
|
<p>{{ greetMsg }}</p>
|
||||||
|
<p>The last person greeted is: {{ lastPersonGreeted }}</p>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@@ -2,6 +2,24 @@ export interface NativeMethods {
|
|||||||
greet: (name: string) => Promise<string>;
|
greet: (name: string) => Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowWithWebViewExtensions = window as typeof window & {webview_binds: NativeMethods};
|
interface NativeEventMap {
|
||||||
|
greeting: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const nativeMethods: NativeMethods = windowWithWebViewExtensions.webview_binds;
|
type WebViewExtensions = {
|
||||||
|
webviewBinds: NativeMethods;
|
||||||
|
webViewAddEventListener<K extends keyof NativeEventMap>(
|
||||||
|
eventKey: K,
|
||||||
|
callback: (payload: NativeEventMap[K]) => void,
|
||||||
|
): void;
|
||||||
|
webViewRemoveEventListener<K extends keyof NativeEventMap>(
|
||||||
|
eventKey: K,
|
||||||
|
callback: (payload: NativeEventMap[K]) => void,
|
||||||
|
): boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const windowWithWebViewExtensions = window as typeof window & WebViewExtensions;
|
||||||
|
|
||||||
|
export const webviewBinds = windowWithWebViewExtensions.webviewBinds;
|
||||||
|
export const webViewAddEventListener = windowWithWebViewExtensions.webViewAddEventListener;
|
||||||
|
export const webViewRemoveEventListener = windowWithWebViewExtensions.webViewRemoveEventListener;
|
||||||
|
2
thirdparty/webview
vendored
2
thirdparty/webview
vendored
Submodule thirdparty/webview updated: ef12fdb8a1...75651c83d2
Reference in New Issue
Block a user