Customize Bootstrap Relays (#205)

* feat: add bootstrap relays file

* feat: add save bootstrap relays command

* feat: add customize bootstrap relays screen
This commit is contained in:
雨宮蓮
2024-06-10 10:48:39 +07:00
committed by GitHub
parent b396c8a695
commit 90342c552f
9 changed files with 902 additions and 448 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
import { LumeColumn, Metadata, NostrEvent, Settings } from "@lume/types";
import { LumeColumn, Metadata, NostrEvent, Relay, Settings } from "@lume/types";
import { commands } from "./commands";
import { resolveResource } from "@tauri-apps/api/path";
import { readFile, readTextFile } from "@tauri-apps/plugin-fs";
@@ -6,6 +6,7 @@ import { isPermissionGranted } from "@tauri-apps/plugin-notification";
import { open } from "@tauri-apps/plugin-dialog";
import { dedupEvents } from "./dedup";
import { invoke } from "@tauri-apps/api/core";
import { relaunch } from "@tauri-apps/plugin-process";
enum NSTORE_KEYS {
settings = "lume_user_settings",
@@ -305,4 +306,38 @@ export class NostrQuery {
}
}
}
static async getBootstrapRelays() {
const query = await commands.getBootstrapRelays();
if (query.status === "ok") {
let relays: Relay[] = [];
console.log(query.data);
for (const item of query.data) {
const line = item.split(",");
const url = line[0];
const purpose = line[1] ?? "";
relays.push({ url, purpose });
}
return relays;
} else {
return [];
}
}
static async saveBootstrapRelays(relays: Relay[]) {
const text = relays
.map((relay) => Object.values(relay).join(","))
.join("\n");
const query = await commands.saveBootstrapRelays(text);
if (query.status === "ok") {
return await relaunch();
} else {
throw new Error(query.error);
}
}
}

View File

@@ -179,3 +179,8 @@ export interface Relays {
write: string[];
both: string[];
}
export interface Relay {
url: string;
purpose: "read" | "write" | string;
}