Skip to content

Commit

Permalink
Fix start daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Oct 15, 2024
1 parent c95017f commit 0c91f72
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions src/app/core/services/daemon/daemon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 83 in src/app/core/services/daemon/daemon.service.ts

View workflow job for this annotation

GitHub Actions / build (20)

'error' is defined but never used

Check failure on line 83 in src/app/core/services/daemon/daemon.service.ts

View workflow job for this annotation

GitHub Actions / build (20)

'error' is defined but never used

Check failure on line 83 in src/app/core/services/daemon/daemon.service.ts

View workflow job for this annotation

GitHub Actions / build (20)

'error' is defined but never used

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -337,64 +338,67 @@ export class DaemonService {
}

public async startDaemon(customSettings?: DaemonSettings): Promise<void> {
await new Promise<void>(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) {

Check failure on line 361 in src/app/core/services/daemon/daemon.service.ts

View workflow job for this annotation

GitHub Actions / build (20)

This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain

Check failure on line 361 in src/app/core/services/daemon/daemon.service.ts

View workflow job for this annotation

GitHub Actions / build (20)

This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain

Check failure on line 361 in src/app/core/services/daemon/daemon.service.ts

View workflow job for this annotation

GitHub Actions / build (20)

This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain
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<void>((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<void> {
Expand Down

0 comments on commit 0c91f72

Please sign in to comment.