diff --git a/src/ModMan/main.cpp b/src/ModMan/main.cpp index 01a1a5d4..bf39ad4d 100644 --- a/src/ModMan/main.cpp +++ b/src/ModMan/main.cpp @@ -68,6 +68,7 @@ namespace [&](const std::string& req) -> std::string { 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)); }); diff --git a/src/ModManUi/src/App.vue b/src/ModManUi/src/App.vue index 6bc85569..b33f0c93 100644 --- a/src/ModManUi/src/App.vue +++ b/src/ModManUi/src/App.vue @@ -1,13 +1,22 @@ diff --git a/src/ModManUi/src/native.ts b/src/ModManUi/src/native.ts index a0a0d25a..1ee88346 100644 --- a/src/ModManUi/src/native.ts +++ b/src/ModManUi/src/native.ts @@ -2,6 +2,24 @@ export interface NativeMethods { greet: (name: string) => Promise; } -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( + eventKey: K, + callback: (payload: NativeEventMap[K]) => void, + ): void; + webViewRemoveEventListener( + 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; diff --git a/thirdparty/webview b/thirdparty/webview index ef12fdb8..75651c83 160000 --- a/thirdparty/webview +++ b/thirdparty/webview @@ -1 +1 @@ -Subproject commit ef12fdb8a1ab068607cac191ff6a588f6a8e2161 +Subproject commit 75651c83d24f9484e4496d5a43fa19ed18577a31