🚀 Improve relay initialization and UX enhancements
✅ **Replace** static 5-second sleep with active relay status checking that fails gracefully after timeout ➕ **Add new features**: - 🏠 Home button navigation to dashboard - 🧪 Dev mode detection for existing relay on localhost:6942 🧹 Perform minor cleanup (remove unimplemented method in electron) #ux #devEx
This commit is contained in:
parent
cee44c69ed
commit
2a1447cd77
6 changed files with 47 additions and 11 deletions
|
@ -108,6 +108,14 @@ export class Header extends LitElement {
|
|||
>
|
||||
<iconify-icon icon="material-symbols:arrow-forward"></iconify-icon>
|
||||
</button>
|
||||
<button
|
||||
@click=${() => {
|
||||
window.location.hash = '#';
|
||||
}}
|
||||
aria-label="Home"
|
||||
>
|
||||
<iconify-icon icon="material-symbols:home"></iconify-icon>
|
||||
</button>
|
||||
</div>
|
||||
<div class="search-container" @click=${this.focusSearch}>
|
||||
<input
|
||||
|
|
|
@ -40,10 +40,6 @@ ipcMain.handle('relay:status', () => {
|
|||
};
|
||||
});
|
||||
|
||||
ipcMain.handle('relay:getLogs', () => {
|
||||
return relay.getLogs();
|
||||
});
|
||||
|
||||
function createWindow(): void {
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 1024,
|
||||
|
|
|
@ -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: {
|
||||
|
|
29
src/main.ts
29
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
export function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
Loading…
Add table
Reference in a new issue