test out basic matrix api

This commit is contained in:
b1ek 2023-08-27 10:27:38 +10:00
parent 6dd9173fec
commit f5caec924a
Signed by: blek
GPG Key ID: 14546221E3595D0C
5 changed files with 1328 additions and 18 deletions

1273
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,8 @@ tauri = { version = "1.4", features = [ "window-maximize", "window-show", "windo
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
reqwest = "0.11.19" reqwest = "0.11.19"
matrix-sdk = { version = "0.6.2", features = ["sso-login"] }
url = "2.4.0"
[features] [features]
# this feature is used for production builds or when `devPath` points to the filesystem # this feature is used for production builds or when `devPath` points to the filesystem

55
src-tauri/src/client.rs Normal file
View File

@ -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)
}

View File

@ -1,12 +1,23 @@
#![forbid(unsafe_code)]
// Prevents additional console window on Windows in release, DO NOT REMOVE!! // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod servers; mod servers;
use servers::*; use servers::*;
mod client;
use client::*;
fn main() { fn main() {
tauri::Builder::default() 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!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View File

@ -11,6 +11,9 @@ if (NODE_ENV !== 'development') {
document.addEventListener('contextmenu', event => event.preventDefault()); 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({ const app = new App({
target: document.getElementById("app"), target: document.getElementById("app"),
}); });