test out basic matrix api
This commit is contained in:
parent
6dd9173fec
commit
f5caec924a
File diff suppressed because it is too large
Load Diff
|
@ -15,6 +15,8 @@ tauri = { version = "1.4", features = [ "window-maximize", "window-show", "windo
|
|||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
reqwest = "0.11.19"
|
||||
matrix-sdk = { version = "0.6.2", features = ["sso-login"] }
|
||||
url = "2.4.0"
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
use matrix_sdk::{
|
||||
Client, ruma::api::client::session::get_login_types::v3::{LoginType, IdentityProvider}
|
||||
};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum LoginChoice {
|
||||
Password,
|
||||
Sso(Vec<IdentityProvider>)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_login_types(srv: String) -> Result<Vec<LoginChoice>, String> {
|
||||
|
||||
let homeserver = Url::parse(srv.as_str());
|
||||
|
||||
if homeserver.is_err() {
|
||||
return Err(homeserver.unwrap_err().to_string())
|
||||
}
|
||||
|
||||
let homeserver = homeserver.unwrap();
|
||||
|
||||
let client = Client::new(homeserver).await;
|
||||
|
||||
if client.is_err() {
|
||||
return Err(client.unwrap_err().to_string());
|
||||
}
|
||||
let client: Client = client.unwrap();
|
||||
|
||||
let login_types = client.get_login_types().await;
|
||||
|
||||
if login_types.is_err() {
|
||||
return Err(login_types.unwrap_err().to_string())
|
||||
}
|
||||
|
||||
let login_types = login_types.unwrap().flows;
|
||||
|
||||
let mut choices = Vec::new();
|
||||
|
||||
for login_type in login_types {
|
||||
match login_type {
|
||||
LoginType::Password(_) => {
|
||||
choices.push(LoginChoice::Password)
|
||||
},
|
||||
LoginType::Sso(sso) => {
|
||||
choices.push(LoginChoice::Sso(sso.identity_providers.clone()))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(choices)
|
||||
}
|
|
@ -1,12 +1,23 @@
|
|||
#![forbid(unsafe_code)]
|
||||
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod servers;
|
||||
use servers::*;
|
||||
|
||||
mod client;
|
||||
use client::*;
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![list_servers])
|
||||
|
||||
// perhaps a better practice than just writing out all the functions?
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
list_servers,
|
||||
get_login_types
|
||||
])
|
||||
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ if (NODE_ENV !== 'development') {
|
|||
document.addEventListener('contextmenu', event => event.preventDefault());
|
||||
}
|
||||
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
invoke('get_login_types', { srv: 'https://matrix.org' }).then(console.log)
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById("app"),
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue