mirror of
				https://github.com/Laupetin/OpenAssetTools.git
				synced 2025-10-31 02:26:59 +00:00 
			
		
		
		
	chore: update example for webview
This commit is contained in:
		| @@ -6,6 +6,7 @@ | ||||
| #include "webview/gtk/CustomProtocolHandlerGtk.h" | ||||
|  | ||||
| #include <chrono> | ||||
| #include <format> | ||||
| #include <iostream> | ||||
| #include <thread> | ||||
|  | ||||
| @@ -22,15 +23,15 @@ int main() | ||||
|         long count = 0; | ||||
|         webview::webview w(true, nullptr); | ||||
|         w.set_title("OpenAssetTools ModMan"); | ||||
|         w.set_size(480, 320, WEBVIEW_HINT_NONE); | ||||
|         w.set_size(480, 320, WEBVIEW_HINT_MIN); | ||||
|  | ||||
|         // A binding that counts up or down and immediately returns the new value. | ||||
|         w.bind("count", | ||||
|         w.bind("greet", | ||||
|                [&](const std::string& req) -> std::string | ||||
|                { | ||||
|                    // Imagine that req is properly parsed or use your own JSON parser. | ||||
|                    auto direction = std::stol(req.substr(1, req.size() - 1)); | ||||
|                    return std::to_string(count += direction); | ||||
|                    const auto name = req.substr(2, req.size() - 4); | ||||
|                    return std::format("\"Hello from C++ {}!\"", name); | ||||
|                }); | ||||
|  | ||||
|         // A binding that creates a new thread and returns the result at a later time. | ||||
|   | ||||
| @@ -1,18 +1,18 @@ | ||||
| <script setup lang="ts"> | ||||
| import { ref } from "vue"; | ||||
| import { nativeMethods } from "./native"; | ||||
|  | ||||
| const greetMsg = ref(""); | ||||
| const name = ref(""); | ||||
|  | ||||
| async function greet() { | ||||
|   // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ | ||||
|   // greetMsg.value = await invoke("greet", { name: name.value }); | ||||
|   greetMsg.value = await nativeMethods.greet(name.value); | ||||
| } | ||||
| </script> | ||||
|  | ||||
| <template> | ||||
|   <main class="container"> | ||||
|     <h1>Welcome to Tauri + Vue</h1> | ||||
|     <h1>Welcome to Webview + Vue</h1> | ||||
|  | ||||
|     <form class="row" @submit.prevent="greet"> | ||||
|       <input id="greet-input" v-model="name" placeholder="Enter a name..." autocomplete="off" /> | ||||
|   | ||||
							
								
								
									
										7
									
								
								src/ModManUi/src/native.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/ModManUi/src/native.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| export interface NativeMethods{ | ||||
|  | ||||
|     greet: (name: string) => Promise<string>; | ||||
| } | ||||
|  | ||||
| // @ts-expect-error | ||||
| export const nativeMethods: NativeMethods = window as NativeMethods; | ||||
		Reference in New Issue
	
	Block a user