From bc189ba79fc44911a1e2b06b02692091bb562664 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 18 Aug 2026 19:02:07 +0200 Subject: [PATCH] Working server list add --- src-tauri/src/commands/server_list.rs | 6 ++-- src-tauri/src/lib.rs | 1 + src-tauri/src/protocol.rs | 46 +++++++++++++++++++++++++++ src/App.tsx | 2 +- src/app/app.ts | 2 +- src/components/view/serverList.tsx | 14 ++++---- src/lib/serverList.ts | 8 ++--- 7 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 src-tauri/src/protocol.rs diff --git a/src-tauri/src/commands/server_list.rs b/src-tauri/src/commands/server_list.rs index 12fba8f..4907159 100644 --- a/src-tauri/src/commands/server_list.rs +++ b/src-tauri/src/commands/server_list.rs @@ -2,10 +2,12 @@ use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fs}; use tauri::{AppHandle, Manager}; +use crate::protocol::ServerMeta; + #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct KnownServer { - pub name: String, - pub description: String, + pub meta: ServerMeta, pub public_key: String, pub is_secure: bool, } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7c6aa06..51cbccc 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,4 +1,5 @@ pub mod commands; +pub mod protocol; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { diff --git a/src-tauri/src/protocol.rs b/src-tauri/src/protocol.rs new file mode 100644 index 0000000..3518cf2 --- /dev/null +++ b/src-tauri/src/protocol.rs @@ -0,0 +1,46 @@ +use std::borrow::Cow; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ClientMeta {} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServerMeta { + pub name: String, + pub description: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "method")] +pub enum ClientMethod { + Initialized { + public_key: String, + signature: String, + + timestamp: u64, + hostname: String, + }, + + Error { + error: Cow<'static, str>, + }, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "method")] +pub enum ServerMethod { + Initialize { + public_key: String, + signature: String, + + timestamp: u64, + hostname: String, + }, + + Meta(ClientMeta), + + Error { + error: String, + }, +} diff --git a/src/App.tsx b/src/App.tsx index 48af353..847cc19 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import { useReducer, useRef } from "react"; import Enclave from "@/app/app"; -import ServerList from "./components/view/serverList"; +import ServerList from "./components/view/ServerList"; import { NewProfilePage } from "./components/view/NewProfileView"; export default function App() { diff --git a/src/app/app.ts b/src/app/app.ts index 17f5168..858aa6e 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -48,7 +48,7 @@ export default class Enclave { this.server.disconnect(); } - this.server = new EnclaveServer(getHostname(hostname), isSecure); + this.server = new EnclaveServer(hostname, isSecure); const clientSecretKey = this.getClientSecretKey(); diff --git a/src/components/view/serverList.tsx b/src/components/view/serverList.tsx index 05555b9..26f0212 100644 --- a/src/components/view/serverList.tsx +++ b/src/components/view/serverList.tsx @@ -40,13 +40,13 @@ export default function ServerList({ return; } - appRef.current - .connectToServer(hostname, isSecure) - .then( - () => - appRef.current?.serverList && - saveServerList(appRef.current?.serverList), - ); + appRef.current.connectToServer(hostname, isSecure).then(() => { + if (!appRef.current) return; + + appRef.current.forceRender(); + + saveServerList(appRef.current.serverList); + }); }} /> diff --git a/src/lib/serverList.ts b/src/lib/serverList.ts index 89a52e1..18e1f81 100644 --- a/src/lib/serverList.ts +++ b/src/lib/serverList.ts @@ -18,13 +18,9 @@ export async function getServerList(): Promise { } export function getHTTPUrl(hostname: string, isSecure: boolean, path: string) { - return (isSecure ? "https://" : "http://") + getHostname(hostname) + path; + return (isSecure ? "https://" : "http://") + hostname + path; } export function getWSUrl(hostname: string, isSecure: boolean) { - return (isSecure ? "wss://" : "ws://") + getHostname(hostname); -} - -export function getHostname(hostname: string) { - return hostname.includes(":") ? hostname : hostname + ":3415"; + return (isSecure ? "wss://" : "ws://") + hostname; }