Server selector
This commit is contained in:
@@ -8,7 +8,7 @@ pub struct KnownServer {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub hostname: String,
|
pub hostname: String,
|
||||||
pub is_wss: bool,
|
pub is_secure: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn servers_file_path(app: &AppHandle) -> Result<std::path::PathBuf, String> {
|
fn servers_file_path(app: &AppHandle) -> Result<std::path::PathBuf, String> {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import Enclave from "@/app/app";
|
import Enclave from "@/app/app";
|
||||||
|
import EnclaveServer from "@/app/server";
|
||||||
|
import { getHTTPUrl, getWSUrl } from "@/lib/serverList";
|
||||||
|
|
||||||
export default function ServerList({
|
export default function ServerList({
|
||||||
appRef,
|
appRef,
|
||||||
@@ -7,16 +9,31 @@ export default function ServerList({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<aside className="bg-card w-16 h-screen p-2 flex flex-col gap-2.5">
|
<aside className="bg-card w-16 h-screen p-2 flex flex-col gap-2.5">
|
||||||
{appRef.current?.serverList.map((server) => (
|
{appRef.current?.serverList.map((server) => {
|
||||||
|
return (
|
||||||
<img
|
<img
|
||||||
src={`http://${server.hostname}/icon`}
|
src={getHTTPUrl(server, "/icon")}
|
||||||
className={
|
className={
|
||||||
server.publicKey === appRef.current?.server?.hostname
|
server.publicKey === appRef.current?.server?.hostname
|
||||||
? "rounded-lg"
|
? "rounded-lg"
|
||||||
: "rounded-full"
|
: "rounded-full"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClick={async () => {
|
||||||
|
if (!appRef.current) {
|
||||||
|
console.error("AppRef is not initialized yet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appRef.current.server) {
|
||||||
|
appRef.current.server.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
appRef.current.server = new EnclaveServer(getWSUrl(server));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</aside>
|
</aside>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -5,7 +5,7 @@ export interface KnownServer {
|
|||||||
description: string;
|
description: string;
|
||||||
publicKey: string;
|
publicKey: string;
|
||||||
hostname: string;
|
hostname: string;
|
||||||
isWss: boolean;
|
isSecure: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveServerList(servers: KnownServer[]): Promise<void> {
|
export async function saveServerList(servers: KnownServer[]): Promise<void> {
|
||||||
@@ -15,3 +15,19 @@ export async function saveServerList(servers: KnownServer[]): Promise<void> {
|
|||||||
export async function getServerList(): Promise<KnownServer[]> {
|
export async function getServerList(): Promise<KnownServer[]> {
|
||||||
return await invoke("get_server_list");
|
return await invoke("get_server_list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getHTTPUrl(server: KnownServer, path: string) {
|
||||||
|
const hostname = server.hostname.includes(":")
|
||||||
|
? server.hostname
|
||||||
|
: server.hostname + ":3415";
|
||||||
|
|
||||||
|
return (server.isSecure ? "https://" : "http://") + hostname + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWSUrl(server: KnownServer) {
|
||||||
|
const hostname = server.hostname.includes(":")
|
||||||
|
? server.hostname
|
||||||
|
: server.hostname + ":3415";
|
||||||
|
|
||||||
|
return (server.isSecure ? "wss://" : "ws://") + hostname;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user