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

View File

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

View File

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