Working server list add
This commit is contained in:
@@ -2,10 +2,12 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{collections::HashMap, fs};
|
use std::{collections::HashMap, fs};
|
||||||
use tauri::{AppHandle, Manager};
|
use tauri::{AppHandle, Manager};
|
||||||
|
|
||||||
|
use crate::protocol::ServerMeta;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct KnownServer {
|
pub struct KnownServer {
|
||||||
pub name: String,
|
pub meta: ServerMeta,
|
||||||
pub description: String,
|
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub is_secure: bool,
|
pub is_secure: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
|
pub mod protocol;
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
},
|
||||||
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { useReducer, useRef } from "react";
|
import { useReducer, useRef } from "react";
|
||||||
import Enclave from "@/app/app";
|
import Enclave from "@/app/app";
|
||||||
import ServerList from "./components/view/serverList";
|
import ServerList from "./components/view/ServerList";
|
||||||
import { NewProfilePage } from "./components/view/NewProfileView";
|
import { NewProfilePage } from "./components/view/NewProfileView";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ export default class Enclave {
|
|||||||
this.server.disconnect();
|
this.server.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server = new EnclaveServer(getHostname(hostname), isSecure);
|
this.server = new EnclaveServer(hostname, isSecure);
|
||||||
|
|
||||||
const clientSecretKey = this.getClientSecretKey();
|
const clientSecretKey = this.getClientSecretKey();
|
||||||
|
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ export default function ServerList({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appRef.current
|
appRef.current.connectToServer(hostname, isSecure).then(() => {
|
||||||
.connectToServer(hostname, isSecure)
|
if (!appRef.current) return;
|
||||||
.then(
|
|
||||||
() =>
|
appRef.current.forceRender();
|
||||||
appRef.current?.serverList &&
|
|
||||||
saveServerList(appRef.current?.serverList),
|
saveServerList(appRef.current.serverList);
|
||||||
);
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -18,13 +18,9 @@ export async function getServerList(): Promise<ServerList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getHTTPUrl(hostname: string, isSecure: boolean, path: string) {
|
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) {
|
export function getWSUrl(hostname: string, isSecure: boolean) {
|
||||||
return (isSecure ? "wss://" : "ws://") + getHostname(hostname);
|
return (isSecure ? "wss://" : "ws://") + hostname;
|
||||||
}
|
|
||||||
|
|
||||||
export function getHostname(hostname: string) {
|
|
||||||
return hostname.includes(":") ? hostname : hostname + ":3415";
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user