Fix start daemon

This commit is contained in:
everoddandeven 2024-10-15 15:59:28 +02:00
parent c95017f4d9
commit 0c91f7222e

View file

@ -80,6 +80,7 @@ import { MethodNotFoundError } from '../../../../common/error/MethodNotFoundErro
import { openDB, IDBPDatabase } from "idb" import { openDB, IDBPDatabase } from "idb"
import { PeerInfo, TxPool } from '../../../../common'; import { PeerInfo, TxPool } from '../../../../common';
import { MoneroInstallerService } from '../monero-installer/monero-installer.service'; import { MoneroInstallerService } from '../monero-installer/monero-installer.service';
import { error } from 'console';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -337,64 +338,67 @@ export class DaemonService {
} }
public async startDaemon(customSettings?: DaemonSettings): Promise<void> { public async startDaemon(customSettings?: DaemonSettings): Promise<void> {
await new Promise<void>(async (resolve, reject) => { if (await this.isRunning()) {
if (await this.isRunning()) { console.warn("Daemon already running");
console.warn("Daemon already running"); return;
return; }
this.starting = 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;
} }
}
this.starting = true; else if (!this.settings.noSync && !this.settings.syncOnWifi) {
const wifiConnected = await this.isWifiConnected();
console.log("Starting daemon");
this.settings = customSettings ? customSettings : await this.getSettings(); if (!wifiConnected) {
console.log("Enabling sync ...");
if (!this.settings.noSync && !this.settings.syncOnWifi) {
const wifiConnected = await this.isWifiConnected();
if (wifiConnected) { this.settings.noSync = false;
console.log("Disabling sync ...");
this.settings.noSync = true;
}
}
else if (!this.settings.noSync && !this.settings.syncOnWifi) {
const wifiConnected = await this.isWifiConnected();
if (!wifiConnected) {
console.log("Enabling sync ...");
this.settings.noSync = false;
}
} }
}
const startPromise = new Promise<void>((resolve, reject) => {
window.electronAPI.onMonerodStarted((event: any, started: boolean) => { window.electronAPI.onMonerodStarted((event: any, started: boolean) => {
console.debug(event); console.debug(event);
if (started) { if (started) {
console.log("Daemon started"); console.log("Daemon started");
this.onDaemonStatusChanged.emit(true); this.isRunning(true).then((running: boolean) => {
resolve(); this.onDaemonStatusChanged.emit(running);
this.starting = false;
resolve();
}).catch((error: any) => {
console.error(error);
this.onDaemonStatusChanged.emit(false);
this.starting = false;
reject(error);
});
} }
else { else {
console.log("Daemon not started"); console.log("Daemon not started");
this.onDaemonStatusChanged.emit(false); this.onDaemonStatusChanged.emit(false);
this.starting = false;
reject('Could not start daemon'); reject('Could not start daemon');
} }
}) })
window.electronAPI.startMonerod(this.settings.toCommandOptions());
}); });
this.starting = false; window.electronAPI.startMonerod(this.settings.toCommandOptions());
await startPromise;
const isRunning: boolean = await this.isRunning(true);
if (!isRunning) {
throw new Error("Daemon started but not running");
}
} }
public async restartDaemon(): Promise<void> { public async restartDaemon(): Promise<void> {