diff --git a/src-tauri/src/commands/server_list.rs b/src-tauri/src/commands/server_list.rs index b084088..176ae7f 100644 --- a/src-tauri/src/commands/server_list.rs +++ b/src-tauri/src/commands/server_list.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, fs}; +use std::fs; use tauri::{AppHandle, Manager}; use crate::types::ServerMeta; @@ -7,12 +7,13 @@ use crate::types::ServerMeta; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct KnownServer { - pub meta: ServerMeta, + pub hostname: String, pub public_key: String, pub is_secure: bool, + pub meta: ServerMeta, } -type ServerList = HashMap; +type ServerList = Vec; fn servers_file_path(app: &AppHandle) -> Result { let dir = app diff --git a/src/app/app.ts b/src/app/app.ts index a5abb25..7fb3f50 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -37,7 +37,7 @@ export default class Enclave

{ public config?: Config; public constructor() { - this.serverList = {}; + this.serverList = []; this.forceRender = () => {}; this.isSettingsOpen = false; } @@ -113,13 +113,17 @@ export default class Enclave

{ return; } + const serveridx = this.serverList.findIndex((server) => { + server.hostname === hostname; + }); + if ( - this.serverList[hostname] && - this.serverList[hostname].publicKey !== + this.serverList[serveridx] && + this.serverList[serveridx].publicKey !== base58.encode(this.server.serverPublicKey) ) { console.error("Server's new public key doesn't match old one", { - old: this.serverList[hostname].publicKey, + old: this.serverList[serveridx].publicKey, new: base58.encode(this.server.serverPublicKey), }); return; @@ -156,12 +160,19 @@ export default class Enclave

{ this.server.meta = metaResponse.data as any; - this.serverList[hostname] = { - meta: metaResponse.data as any, - isSecure, + const serverItem = { + hostname, publicKey: base58.encode(this.server.serverPublicKey), + isSecure, + meta: metaResponse.data as any, }; + if (this.serverList[serveridx]) { + this.serverList[serveridx] = serverItem; + } else { + this.serverList.push(serverItem); + } + this.forceRender(); } diff --git a/src/components/view/ServerList.tsx b/src/components/view/ServerList.tsx index 2e1da81..f23fd30 100644 --- a/src/components/view/ServerList.tsx +++ b/src/components/view/ServerList.tsx @@ -12,14 +12,14 @@ export default function ServerList({ return (