Handle custom httpd port

We only supported fetching the default httpd port (8080).
This commit removes navigation to `radicle.local` which represents
`0.0.0.0:8080`, and prepares the app for defining custom port.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-06-14 16:17:21 +02:00
parent 4fcb7373a3
commit 52cece4680
11 changed files with 186 additions and 36 deletions
+14 -3
View File
@@ -17,11 +17,12 @@ export type HttpdState =
};
const HTTPD_STATE_STORAGE_KEY = "httpdState";
const HTTPD_CUSTOM_PORT_KEY = "httpdCustomPort";
const store = writable<HttpdState>({ state: "stopped" });
export const httpdStore = derived(store, s => s);
const api = new HttpdClient({
export const api = new HttpdClient({
hostname: "127.0.0.1",
port: 8080,
scheme: "http",
@@ -29,6 +30,11 @@ const api = new HttpdClient({
let pollHttpdStateHandle: number | undefined = undefined;
export function changeHttpdPort(port: number) {
window.localStorage.setItem(HTTPD_CUSTOM_PORT_KEY, String(port));
void checkState();
}
function update(state: HttpdState) {
window.localStorage.setItem(HTTPD_STATE_STORAGE_KEY, JSON.stringify(state));
store.set(state);
@@ -89,6 +95,10 @@ export async function disconnect() {
async function checkState() {
let httpdState: HttpdState | null = null;
const rawHttpdState = window.localStorage.getItem(HTTPD_STATE_STORAGE_KEY);
const customHttpdPort = window.localStorage.getItem(HTTPD_CUSTOM_PORT_KEY);
if (customHttpdPort) {
api.changePort(Number(customHttpdPort));
}
if (rawHttpdState) {
try {
httpdState = JSON.parse(rawHttpdState);
@@ -140,8 +150,9 @@ export function initialize() {
// Sync session state changes with other open tabs and windows.
addEventListener("storage", event => {
if (
event.key === HTTPD_STATE_STORAGE_KEY &&
event.oldValue !== event.newValue
(event.key === HTTPD_STATE_STORAGE_KEY &&
event.oldValue !== event.newValue) ||
(event.key === HTTPD_CUSTOM_PORT_KEY && event.oldValue !== event.newValue)
) {
void checkState();
}
+4 -3
View File
@@ -255,10 +255,11 @@ export function extractBaseUrl(hostnamePort: string): BaseUrl {
) {
return { hostname: "127.0.0.1", port: 8080, scheme: "http" };
} else if (hostnamePort.includes(":")) {
const [hostname, port] = hostnamePort.split(":");
return {
hostname: hostnamePort.split(":")[0],
port: Number(hostnamePort.split(":")[1]),
scheme: config.seeds.defaultHttpdScheme,
hostname,
port: Number(port),
scheme: isLocal(hostname) ? "http" : config.seeds.defaultHttpdScheme,
};
} else {
return {