diff options
-rw-r--r-- | dist/css/main.css | 9 | ||||
-rw-r--r-- | dist/index.html | 1 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 12 | ||||
-rw-r--r-- | src-ui/src/main.ts | 9 |
4 files changed, 29 insertions, 2 deletions
diff --git a/dist/css/main.css b/dist/css/main.css index 2b5cbee0..2180fafe 100644 --- a/dist/css/main.css +++ b/dist/css/main.css @@ -62,6 +62,15 @@ counter-result { padding: 1.5rem 1rem; } +panic-button { + cursor: pointer; + user-select: none; + -webkit-user-select: none; + border: solid 1px; + border-radius: 5px; + padding: .875rem 3rem; +} + backend-ping { position: absolute; top: 1rem; diff --git a/dist/index.html b/dist/index.html index c57eabc8..9c242c36 100644 --- a/dist/index.html +++ b/dist/index.html @@ -6,6 +6,7 @@ <div class="hello">Click for Hello</div> <counter-button>ADD</counter-button> <counter-result>.</counter-result> + <panic-button>Panic Button</panic-button> <backend-ping class="server"></backend-ping> </body> </html> diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 430c8111..b5cae7b9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -29,7 +29,11 @@ fn main() { Ok(()) }) .manage(Counter(Default::default())) - .invoke_handler(tauri::generate_handler![hello_world, add_count]) + .invoke_handler(tauri::generate_handler![ + hello_world, + add_count, + force_panic + ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } @@ -46,3 +50,9 @@ fn add_count(num: i32, counter: State<'_, Counter>) -> String { format!("{val}") } + +#[tauri::command] +/// This function's only use is to force a `panic!()` +fn force_panic() { + panic!("Force panicked!"); +} diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index f964a6d5..f5f3f303 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -9,6 +9,7 @@ document.addEventListener("DOMContentLoaded", async function () { let counterButtonEl = $("counter-button") as HTMLElement; let counterResultEl = $("counter-result") as HTMLElement; let pingEl = $("backend-ping")! as HTMLElement; + let panicButtonEl = $("panic-button") as HTMLElement; // listen backend-ping event (from Tauri Rust App) listen("backend-ping", function (evt: TauriEvent<any>) { @@ -32,4 +33,10 @@ document.addEventListener("DOMContentLoaded", async function () { helloEl.textContent = "Click again"; }, 1000); }) -})
\ No newline at end of file + + // panic button click + panicButtonEl.addEventListener("pointerup", async function () { + await invoke("force_panic"); + alert("Never should have been able to get here!"); + }); +}) |