From 0c91f7222ecacfd780e68cd304ab9be01bb8a6bc Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 15 Oct 2024 15:59:28 +0200 Subject: [PATCH] Fix start daemon --- .../core/services/daemon/daemon.service.ts | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index 3070da2..10468be 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -80,6 +80,7 @@ import { MethodNotFoundError } from '../../../../common/error/MethodNotFoundErro import { openDB, IDBPDatabase } from "idb" import { PeerInfo, TxPool } from '../../../../common'; import { MoneroInstallerService } from '../monero-installer/monero-installer.service'; +import { error } from 'console'; @Injectable({ providedIn: 'root' @@ -337,64 +338,67 @@ export class DaemonService { } public async startDaemon(customSettings?: DaemonSettings): Promise { - await new Promise(async (resolve, reject) => { - if (await this.isRunning()) { - console.warn("Daemon already running"); - return; - } - - this.starting = true; - - console.log("Starting daemon"); + if (await this.isRunning()) { + console.warn("Daemon already running"); + return; + } - this.settings = customSettings ? customSettings : await this.getSettings(); - - if (!this.settings.noSync && !this.settings.syncOnWifi) { - const wifiConnected = await this.isWifiConnected(); + this.starting = true; - if (wifiConnected) { - console.log("Disabling sync ..."); - - this.settings.noSync = true; - } + console.log("Starting daemon"); + + this.settings = customSettings ? customSettings : await this.getSettings(); + + if (!this.settings.noSync && !this.settings.syncOnWifi) { + const wifiConnected = await this.isWifiConnected(); + + if (wifiConnected) { + console.log("Disabling sync ..."); + + this.settings.noSync = true; } - else if (!this.settings.noSync && !this.settings.syncOnWifi) { - const wifiConnected = await this.isWifiConnected(); + } + else if (!this.settings.noSync && !this.settings.syncOnWifi) { + const wifiConnected = await this.isWifiConnected(); - if (!wifiConnected) { - console.log("Enabling sync ..."); - - this.settings.noSync = false; - } + if (!wifiConnected) { + console.log("Enabling sync ..."); + + this.settings.noSync = false; } + } + const startPromise = new Promise((resolve, reject) => { window.electronAPI.onMonerodStarted((event: any, started: boolean) => { console.debug(event); if (started) { console.log("Daemon started"); - this.onDaemonStatusChanged.emit(true); - resolve(); + this.isRunning(true).then((running: boolean) => { + this.onDaemonStatusChanged.emit(running); + this.starting = false; + resolve(); + }).catch((error: any) => { + console.error(error); + this.onDaemonStatusChanged.emit(false); + this.starting = false; + reject(error); + }); + + } else { console.log("Daemon not started"); this.onDaemonStatusChanged.emit(false); + this.starting = false; reject('Could not start daemon'); } }) - - window.electronAPI.startMonerod(this.settings.toCommandOptions()); - }); - this.starting = false; - - const isRunning: boolean = await this.isRunning(true); - - if (!isRunning) { - throw new Error("Daemon started but not running"); - } + window.electronAPI.startMonerod(this.settings.toCommandOptions()); + await startPromise; } public async restartDaemon(): Promise {