broken code, does not suceed at calling rust code :(

This commit is contained in:
ayabusa 2024-02-14 18:02:42 +01:00
parent e3505f2d34
commit 035d72fd56
3 changed files with 16 additions and 20 deletions

View File

@ -2,14 +2,21 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
/*#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
*/
#[tauri::command]
fn slice() {
println!("I was invoked from JS!");
}
fn main() {
println!("launched");
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
//.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -5,7 +5,7 @@
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rusty slicer</title>
<script type="module" src="/main.js" defer></script>
<script src="main.js"></script>
</head>
<!-- Made by ayabusa (www.ayabusa.dev) with pain, because making html and css is awfully painfull :) -->
@ -37,7 +37,8 @@
</select>
</div>
<button class="slice-button" type="button"> Slice 🔪</button>
<button onclick="myFunction()" class="slice-button"> Slice 🔪</button>
<p id="demo">ddqdz</p>
<footer>
<br>

View File

@ -1,18 +1,6 @@
const { invoke } = window.__TAURI__.tauri;
let greetInputEl;
let greetMsgEl;
async function greet() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value });
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
invoke("slice")
}
window.addEventListener("DOMContentLoaded", () => {
greetInputEl = document.querySelector("#greet-input");
greetMsgEl = document.querySelector("#greet-msg");
document.querySelector("#greet-form").addEventListener("submit", (e) => {
e.preventDefault();
greet();
});
});