From dec3172af31b6b3dfc795b5033673bb4acef39d9 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Mon, 9 Jan 2023 01:31:12 +0100 Subject: [PATCH] Improve a bit frontend --- src-tauri/src/main.rs | 6 +++--- src/index.html | 22 ++-------------------- src/main.js | 15 +++++++++------ 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3806ee9..c9db333 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -15,18 +15,18 @@ fn greet(name: &str) -> String { } #[tauri::command] -async fn second_window(app: tauri::AppHandle, _window: tauri::Window) -> Result { +async fn login(app: tauri::AppHandle, _window: tauri::Window) -> Result { let result = Authentification::login(Prompt::SelectAccount, app).await; match result { Ok(val) => Ok(format!("Hello {}", val.1)), - Err(err) => Ok(err.to_string()) + Err(err) => Err(err.to_string()) } } #[tokio::main] async fn main() { tauri::Builder::default() - .invoke_handler(tauri::generate_handler![greet, second_window]) + .invoke_handler(tauri::generate_handler![greet, login]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src/index.html b/src/index.html index b2fc8e7..f276387 100644 --- a/src/index.html +++ b/src/index.html @@ -17,28 +17,10 @@

Welcome to Tauri!

- - -

Click on the Tauri logo to learn more about the framework

-
- - + +
diff --git a/src/main.js b/src/main.js index f109d08..78dc021 100644 --- a/src/main.js +++ b/src/main.js @@ -1,17 +1,20 @@ const { invoke } = window.__TAURI__.tauri; -let greetInputEl; let greetMsgEl; +let greetButton; async function greet() { // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command - greetMsgEl.textContent = await invoke("second_window", { name: greetInputEl.value }); + // greetMsgEl.textContent = await invoke("login", {}); + invoke("login", {}).then(value => { + greetMsgEl.textContent = value + }).catch(err => { + greetMsgEl.textContent = "Error: " + err + }) } window.addEventListener("DOMContentLoaded", () => { - greetInputEl = document.querySelector("#greet-input"); greetMsgEl = document.querySelector("#greet-msg"); - document - .querySelector("#greet-button") - .addEventListener("click", () => greet()); + greetButton = document.querySelector("#greet-button") + greetButton.addEventListener("click", () => greet()); });