diff --git a/src/components/Header.ts b/src/components/Header.ts
index bdde566..4825408 100644
--- a/src/components/Header.ts
+++ b/src/components/Header.ts
@@ -108,6 +108,14 @@ export class Header extends LitElement {
>
+
{
};
});
-ipcMain.handle('relay:getLogs', () => {
- return relay.getLogs();
-});
-
function createWindow(): void {
const mainWindow = new BrowserWindow({
width: 1024,
diff --git a/src/electron/relayManager.ts b/src/electron/relayManager.ts
index ab5b2db..72b8adc 100644
--- a/src/electron/relayManager.ts
+++ b/src/electron/relayManager.ts
@@ -122,6 +122,15 @@ export class RelayManager {
this.encryptionKey = encryptionKey;
+ if (is.dev) {
+ this.process = spawn('nc', ['localhost', '6942']);
+ this.process.on('exit', () => {
+ this.process = null;
+ this.start(encryptionKey);
+ });
+ return;
+ }
+
try {
this.process = spawn(this.relayPath, [], {
env: {
diff --git a/src/main.ts b/src/main.ts
index c21bf27..c2324f2 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -9,14 +9,39 @@ import '@components/Header';
import '@routes/router';
import '@components/LoadingView';
import type EveRouter from '@routes/router';
-import { sleep } from './utils/sleep';
+
+function checkRelayUp() {
+ return new Promise((resolve, reject) => {
+ const timeoutId = setTimeout(() => {
+ ws.close();
+ reject(new Error('Connection timeout'));
+ }, 5000);
+
+ const ws = new WebSocket('ws://localhost:6942');
+
+ ws.onopen = () => {
+ clearTimeout(timeoutId);
+ ws.close();
+ resolve(true);
+ };
+
+ ws.onerror = (error) => {
+ clearTimeout(timeoutId);
+ reject(error);
+ };
+ });
+}
async function startRelay() {
if (localStorage.getItem('ncryptsec')) {
const loadingIndicator = document.createElement('arx-loading-view');
document.body.appendChild(loadingIndicator);
await window.relay.start(localStorage.getItem('encryption_key')!);
- await sleep(5000);
+ try {
+ await checkRelayUp();
+ } catch (err) {
+ alert('Could not connect to relay. This might be because the relay is not running. Try restarting Eve');
+ }
loadingIndicator.remove();
}
}
diff --git a/src/ndk.ts b/src/ndk.ts
index 8277a90..ef844aa 100644
--- a/src/ndk.ts
+++ b/src/ndk.ts
@@ -29,9 +29,10 @@ export function setSigner(signer: NDKPrivateKeySigner) {
ndk.signer = signer;
}
-export async function getUserProfile(npub: string) {
+export async function getUserProfile(npub: string | undefined = undefined) {
await ndk.connect();
- const query = npub.startsWith('npub') ? { npub } : { pubkey: npub };
+ const npubToCheck = npub ? npub : await getNpub();
+ const query = npubToCheck.startsWith('npub') ? { npub: npubToCheck } : { pubkey: npubToCheck };
const user = ndk.getUser(query);
await user.fetchProfile();
return user.profile;
diff --git a/src/utils/sleep.ts b/src/utils/sleep.ts
deleted file mode 100644
index 0d7f188..0000000
--- a/src/utils/sleep.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export function sleep(ms: number) {
- return new Promise((resolve) => setTimeout(resolve, ms));
-}