From 4fb5627ac1f8fda0f746c95a33b5b23b43f38de8 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Wed, 16 Oct 2024 00:38:57 +0200 Subject: [PATCH] Fix DaemonService.startDaemon(), fix logs size --- app/main.ts | 4 +++- app/preload.js | 7 +++++++ src/app/core/services/daemon/daemon.service.ts | 10 +++++++++- src/app/pages/logs/logs.component.html | 9 ++++++--- src/app/pages/logs/logs.service.ts | 9 ++++++++- src/polyfills.ts | 1 + 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/main.ts b/app/main.ts index 4dbfa30..4c99c91 100644 --- a/app/main.ts +++ b/app/main.ts @@ -68,12 +68,14 @@ function createWindow(): BrowserWindow { preload: path.join(__dirname, 'preload.js'), nodeIntegration: false, allowRunningInsecureContent: (serve), - contextIsolation: true + contextIsolation: true, + devTools: true }, autoHideMenuBar: true, icon: wdwIcon }); + win.webContents.openDevTools(); if (serve) { const debug = require('electron-debug'); diff --git a/app/preload.js b/app/preload.js index c32e728..9e7ed8a 100644 --- a/app/preload.js +++ b/app/preload.js @@ -9,6 +9,13 @@ contextBridge.exposeInMainWorld('electronAPI', { onMonerodStarted: (callback) => { ipcRenderer.on('monerod-started', callback); }, + unsubscribeOnMonerodStarted: () => { + const listeners = ipcRenderer.listeners('monerod-started'); + + listeners.forEach((listener) => { + ipcRenderer.removeListener('monerod-started', listener); + }); + }, onMoneroStdout: (callback) => { ipcRenderer.on('monero-stdout', callback); }, diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index 16b6ae9..93b3ae0 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -396,7 +396,15 @@ export class DaemonService { }); window.electronAPI.startMonerod(this.settings.toCommandOptions()); - await startPromise; + + try { + await startPromise; + } + catch(error) { + console.error(error); + } + + window.electronAPI.unsubscribeOnMonerodStarted(); } public async restartDaemon(): Promise { diff --git a/src/app/pages/logs/logs.component.html b/src/app/pages/logs/logs.component.html index c0f35ba..a6ac5b4 100644 --- a/src/app/pages/logs/logs.component.html +++ b/src/app/pages/logs/logs.component.html @@ -20,9 +20,12 @@
- -
{{ line }}
-
+ @for(line of lines; track line) { + +
{{ line }}
+
+ } +
diff --git a/src/app/pages/logs/logs.service.ts b/src/app/pages/logs/logs.service.ts index fd0a406..ab9ffe2 100644 --- a/src/app/pages/logs/logs.service.ts +++ b/src/app/pages/logs/logs.service.ts @@ -8,6 +8,7 @@ import { LogCategories } from '../../../common'; export class LogsService { public readonly onLog: EventEmitter = new EventEmitter(); public readonly lines: string[] = []; + public readonly maxLines: number = 250; public readonly categories: LogCategories = new LogCategories(); constructor(private electronService: ElectronService, private ngZone: NgZone) { @@ -31,7 +32,13 @@ export class LogsService { public log(message: string): void { this.ngZone.run(() => { - this.lines.push(this.cleanLog(message)); + if (this.lines.length <= this.maxLines) { + this.lines.push(this.cleanLog(message)); + } + else { + this.lines.shift(); + this.lines.push(this.cleanLog(message)); + } this.onLog.emit(this.cleanLog(message)); }); diff --git a/src/polyfills.ts b/src/polyfills.ts index f641105..90f3350 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -60,6 +60,7 @@ declare global { electronAPI: { startMonerod: (options: string[]) => void; onMonerodStarted: (callback: (event: any, started: boolean) => void) => void; + unsubscribeOnMonerodStarted: () => void; onMoneroClose: (callback: (event: any, code: number) => void) => void; isWifiConnected: () => void; onIsWifiConnectedResponse: (callback: (event: any, connected: boolean) => void) => void;