Improve a bit frontend
This commit is contained in:
parent
ad3988ed29
commit
dec3172af3
@ -15,18 +15,18 @@ fn greet(name: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn second_window(app: tauri::AppHandle, _window: tauri::Window) -> Result<String, ()> {
|
async fn login(app: tauri::AppHandle, _window: tauri::Window) -> Result<String, String> {
|
||||||
let result = Authentification::login(Prompt::SelectAccount, app).await;
|
let result = Authentification::login(Prompt::SelectAccount, app).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(val) => Ok(format!("Hello {}", val.1)),
|
Ok(val) => Ok(format!("Hello {}", val.1)),
|
||||||
Err(err) => Ok(err.to_string())
|
Err(err) => Err(err.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![greet, second_window])
|
.invoke_handler(tauri::generate_handler![greet, login])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
@ -17,28 +17,10 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Welcome to Tauri!</h1>
|
<h1>Welcome to Tauri!</h1>
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<a href="https://tauri.app" target="_blank">
|
|
||||||
<img src="/assets/tauri.svg" class="logo tauri" alt="Tauri logo" />
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="/assets/javascript.svg"
|
|
||||||
class="logo vanilla"
|
|
||||||
alt="JavaScript logo"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>Click on the Tauri logo to learn more about the framework</p>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div>
|
<div>
|
||||||
<input id="greet-input" placeholder="Enter a name..." />
|
<button id="greet-button" type="button">Login to Minecraft</button>
|
||||||
<button id="greet-button" type="button">Greet</button>
|
<button id="greet-button" type="button" hidden>Launch the game</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
15
src/main.js
15
src/main.js
@ -1,17 +1,20 @@
|
|||||||
const { invoke } = window.__TAURI__.tauri;
|
const { invoke } = window.__TAURI__.tauri;
|
||||||
|
|
||||||
let greetInputEl;
|
|
||||||
let greetMsgEl;
|
let greetMsgEl;
|
||||||
|
let greetButton;
|
||||||
|
|
||||||
async function greet() {
|
async function greet() {
|
||||||
// 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
|
||||||
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", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
greetInputEl = document.querySelector("#greet-input");
|
|
||||||
greetMsgEl = document.querySelector("#greet-msg");
|
greetMsgEl = document.querySelector("#greet-msg");
|
||||||
document
|
greetButton = document.querySelector("#greet-button")
|
||||||
.querySelector("#greet-button")
|
greetButton.addEventListener("click", () => greet());
|
||||||
.addEventListener("click", () => greet());
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user