diff --git a/src/app/depot/index.tsx b/src/app/depot/index.tsx
index 42301fb8..a9ac8094 100644
--- a/src/app/depot/index.tsx
+++ b/src/app/depot/index.tsx
@@ -1,29 +1,148 @@
-import { configDir, resolveResource } from '@tauri-apps/api/path';
-import { Command } from '@tauri-apps/plugin-shell';
+import { useEffect, useState } from 'react';
+import { toast } from 'sonner';
+import { useArk } from '@libs/ark';
+import { LoaderIcon } from '@shared/icons';
+import { delay } from '@utils/delay';
export function DepotScreen() {
+ const ark = useArk();
+
+ const [status, setStatus] = useState(false);
+ const [loading, setLoading] = useState(false);
+
const launch = async () => {
- const configPath = await resolveResource('resources/config.toml');
- const dataPath = await configDir();
+ try {
+ setLoading(true);
- const command = Command.sidecar('bin/depot', ['-c', configPath, '-d', dataPath]);
- const process = await command.spawn();
+ await ark.launchDepot();
+ await delay(5000); // delay 5s to make sure depot is running
- process.pid;
+ // default depot url: ws://localhost:6090
+ // #TODO: user can custom depot url
+ const connect = await ark.connectDepot();
+
+ if (connect) {
+ setStatus(true);
+ setLoading(false);
+ }
+ } catch (e) {
+ toast.error(e);
+ }
};
+ useEffect(() => {
+ const depotStatus = ark.checkDepot();
+ setStatus(depotStatus);
+ }, []);
+
return (
-
-
-
Depot
-
-
+
+ {!status ? (
+
+
+ Deploy Nostr Relay inside Lume{' '}
+ with Depot.
+
+
+
+ ) : (
+
+
+
+
+ Your Depot is running
+
+
+
+
+
+
+
ws://localhost:6090
+
+
+
+
+
+
Backup
+
+ Sync all your data to Depot.
+
+
+
+
+
+
+
Expose
+
+ Help other users can see your depot on Internet. You also can do it by
+ yourself by using other service like ngrok or localtunnel.
+
+
+
+
+
+
+
Relay Hint
+
+ Instruct other Nostr client find your events in this depot.
+
+
+
+
+
+
+
Invite
+
+ By default, only you can write event to Depot, but you can invite
+ other user to your Depot.
+
+
+
+
+
+
+
Customize
+
+ Depot also provide plenty config to customize your experiences.
+
+
+
+
+
+
+
+ )}
);
}
diff --git a/src/libs/ark/ark.ts b/src/libs/ark/ark.ts
index 4d372143..96d909c5 100644
--- a/src/libs/ark/ark.ts
+++ b/src/libs/ark/ark.ts
@@ -4,17 +4,20 @@ import NDK, {
NDKKind,
NDKNip46Signer,
NDKPrivateKeySigner,
+ NDKRelay,
NDKSubscriptionCacheUsage,
NDKTag,
NDKUser,
NostrEvent,
} from '@nostr-dev-kit/ndk';
import { ndkAdapter } from '@nostr-fetch/adapter-ndk';
+import { configDir, resolveResource } from '@tauri-apps/api/path';
import { invoke } from '@tauri-apps/api/primitives';
import { open } from '@tauri-apps/plugin-dialog';
import { readBinaryFile } from '@tauri-apps/plugin-fs';
import { fetch } from '@tauri-apps/plugin-http';
import { Platform } from '@tauri-apps/plugin-os';
+import { Child, Command } from '@tauri-apps/plugin-shell';
import Database from '@tauri-apps/plugin-sql';
import {
NostrEventExt,
@@ -35,6 +38,7 @@ import {
export class Ark {
#storage: Database;
+ #depot: Child;
public ndk: NDK;
public fetcher: NostrFetcher;
public account: Account | null;
@@ -61,6 +65,28 @@ export class Ark {
};
}
+ public async launchDepot() {
+ const configPath = await resolveResource('resources/config.toml');
+ const dataPath = await configDir();
+
+ const command = Command.sidecar('bin/depot', ['-c', configPath, '-d', dataPath]);
+ this.#depot = await command.spawn();
+ }
+
+ public async connectDepot() {
+ if (!this.#depot) return;
+ return this.ndk.addExplicitRelay(
+ new NDKRelay('ws://localhost:6090'),
+ undefined,
+ true
+ );
+ }
+
+ public checkDepot() {
+ if (this.#depot) return true;
+ return false;
+ }
+
async #keyring_save(key: string, value: string) {
return await invoke('secure_save', { key, value });
}
diff --git a/src/utils/delay.ts b/src/utils/delay.ts
new file mode 100644
index 00000000..29a28bd1
--- /dev/null
+++ b/src/utils/delay.ts
@@ -0,0 +1 @@
+export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));