2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-10-12 17:49:03 +00:00

chore: update example for webview

This commit is contained in:
Jan Laupetin
2025-10-03 12:06:34 +01:00
parent 804e6cf1cd
commit 026d5e3dfa
3 changed files with 15 additions and 7 deletions

View File

@@ -6,6 +6,7 @@
#include "webview/gtk/CustomProtocolHandlerGtk.h" #include "webview/gtk/CustomProtocolHandlerGtk.h"
#include <chrono> #include <chrono>
#include <format>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
@@ -22,15 +23,15 @@ int main()
long count = 0; long count = 0;
webview::webview w(true, nullptr); webview::webview w(true, nullptr);
w.set_title("OpenAssetTools ModMan"); w.set_title("OpenAssetTools ModMan");
w.set_size(480, 320, WEBVIEW_HINT_NONE);
w.set_size(480, 320, WEBVIEW_HINT_MIN); w.set_size(480, 320, WEBVIEW_HINT_MIN);
// A binding that counts up or down and immediately returns the new value. // 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 [&](const std::string& req) -> std::string
{ {
// Imagine that req is properly parsed or use your own JSON parser. const auto name = req.substr(2, req.size() - 4);
auto direction = std::stol(req.substr(1, req.size() - 1)); return std::format("\"Hello from C++ {}!\"", name);
return std::to_string(count += direction);
}); });
// A binding that creates a new thread and returns the result at a later time. // A binding that creates a new thread and returns the result at a later time.

View File

@@ -1,18 +1,18 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref } from "vue";
import { nativeMethods } from "./native";
const greetMsg = ref(""); const greetMsg = ref("");
const name = ref(""); const name = ref("");
async function greet() { async function greet() {
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ greetMsg.value = await nativeMethods.greet(name.value);
// greetMsg.value = await invoke("greet", { name: name.value });
} }
</script> </script>
<template> <template>
<main class="container"> <main class="container">
<h1>Welcome to Tauri + Vue</h1> <h1>Welcome to Webview + Vue</h1>
<form class="row" @submit.prevent="greet"> <form class="row" @submit.prevent="greet">
<input id="greet-input" v-model="name" placeholder="Enter a name..." autocomplete="off" /> <input id="greet-input" v-model="name" placeholder="Enter a name..." autocomplete="off" />

View File

@@ -0,0 +1,7 @@
export interface NativeMethods{
greet: (name: string) => Promise<string>;
}
// @ts-expect-error
export const nativeMethods: NativeMethods = window as NativeMethods;