Fix DaemonService.startDaemon(), fix logs size

This commit is contained in:
everoddandeven 2024-10-16 00:38:57 +02:00
parent 126891dfdc
commit 4fb5627ac1
6 changed files with 34 additions and 6 deletions

View file

@ -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');

View file

@ -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);
},

View file

@ -396,8 +396,16 @@ export class DaemonService {
});
window.electronAPI.startMonerod(this.settings.toCommandOptions());
try {
await startPromise;
}
catch(error) {
console.error(error);
}
window.electronAPI.unsubscribeOnMonerodStarted();
}
public async restartDaemon(): Promise<void> {
this.restarting = true;

View file

@ -20,9 +20,12 @@
<div *ngIf="lines.length > 0" class="terminal bg-dark text-light p-3 m-4" #logTerminal>
<div class="terminal-output" id="terminalOutput">
<ng-container *ngFor="let line of lines; trackBy: trackByFn">
@for(line of lines; track line) {
<ng-container>
<div>{{ line }}</div>
</ng-container>
}
</div>
</div>
</div>

View file

@ -8,6 +8,7 @@ import { LogCategories } from '../../../common';
export class LogsService {
public readonly onLog: EventEmitter<string> = new EventEmitter<string>();
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(() => {
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));
});

View file

@ -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;