From 804097547385d71317ffdf328b2d3c313fc933bd Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Fri, 14 Feb 2025 23:46:36 +0100 Subject: [PATCH] Detect linux monerod installation --- app/main.ts | 3 ++ app/process/I2pdInstallationInfo.ts | 3 ++ app/process/I2pdProcess.ts | 4 +- app/process/InstallationInfo.ts | 1 + app/process/MonerodInstallationInfo.ts | 7 +++ app/process/MonerodProcess.ts | 51 +++++++++++++++++++ app/process/index.ts | 3 ++ .../services/electron/electron.service.ts | 4 +- 8 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 app/process/I2pdInstallationInfo.ts create mode 100644 app/process/InstallationInfo.ts create mode 100644 app/process/MonerodInstallationInfo.ts diff --git a/app/main.ts b/app/main.ts index d3d7c0a..dc0b217 100644 --- a/app/main.ts +++ b/app/main.ts @@ -404,6 +404,9 @@ async function detectInstallation(program: string): Promise { if (program === 'i2pd') { return await I2pdProcess.detectInstalled(); } + else if (program === 'monerod') { + return await MonerodProcess.detectInstalled(); + } else return undefined; } diff --git a/app/process/I2pdInstallationInfo.ts b/app/process/I2pdInstallationInfo.ts new file mode 100644 index 0000000..2cc39c9 --- /dev/null +++ b/app/process/I2pdInstallationInfo.ts @@ -0,0 +1,3 @@ +import { InstallationInfo } from "./InstallationInfo"; + +export interface I2pdInstallationInfo extends InstallationInfo { configFile?: string; tunnelConfig?: string; tunnelsConfigDir?: string; pidFile?: string; isRunning?: boolean; }; diff --git a/app/process/I2pdProcess.ts b/app/process/I2pdProcess.ts index 7d16cad..2279edd 100644 --- a/app/process/I2pdProcess.ts +++ b/app/process/I2pdProcess.ts @@ -1,9 +1,7 @@ import { execSync } from "child_process"; import { AppChildProcess } from "./AppChildProcess"; import * as fs from 'fs'; - -export interface InstallationInfo { path: string }; -export interface I2pdInstallationInfo extends InstallationInfo { configFile?: string; tunnelConfig?: string; tunnelsConfigDir?: string; pidFile?: string; isRunning?: boolean; }; +import { I2pdInstallationInfo } from "./I2pdInstallationInfo"; export interface I2pTunnelConfig { name: string; diff --git a/app/process/InstallationInfo.ts b/app/process/InstallationInfo.ts new file mode 100644 index 0000000..ab77e0f --- /dev/null +++ b/app/process/InstallationInfo.ts @@ -0,0 +1 @@ +export interface InstallationInfo { path: string }; diff --git a/app/process/MonerodInstallationInfo.ts b/app/process/MonerodInstallationInfo.ts new file mode 100644 index 0000000..40a207d --- /dev/null +++ b/app/process/MonerodInstallationInfo.ts @@ -0,0 +1,7 @@ +import { InstallationInfo } from "./InstallationInfo"; + +export interface MonerodInstallationInfo extends InstallationInfo { + configFile?: string; + pidFile?: string; + isRunning?: boolean; +}; diff --git a/app/process/MonerodProcess.ts b/app/process/MonerodProcess.ts index ed1a757..06ad2ba 100644 --- a/app/process/MonerodProcess.ts +++ b/app/process/MonerodProcess.ts @@ -1,4 +1,6 @@ import { AppChildProcess } from "./AppChildProcess"; +import { MonerodInstallationInfo } from "./MonerodInstallationInfo"; +import * as fs from 'fs'; export class MonerodProcess extends AppChildProcess { @@ -232,4 +234,53 @@ export class MonerodProcess extends AppChildProcess { return await promise; } + public static async detectInstalled(): Promise { + if (this.isLinux) { + return await this.detectInstalledLinux(); + } + else if (this.isWindows) { + return await this.detectInstalledWindows(); + } + else if (this.isMacos) { + return await this.detectInstalledMacos(); + } + + return undefined; + } + + private static async detectInstalledLinux(): Promise { + let path: string | undefined = undefined; + let configFile: string | undefined = undefined; + let pidFile: string | undefined = undefined; + let isRunning: boolean = false; + + if (await this.isValidPath('/usr/bin/monerod')) { + path = '/usr/bin/monerod'; + } + else if (await this.isValidPath('/opt/monero/monerod')) { + path = '/opt/monero/monerod'; + } + if (fs.existsSync('/etc/monerod.conf')) { + configFile = '/etc/monerod.conf'; + } + if (fs.existsSync('/run/monero/monerod.pid')) { + pidFile = '/run/monero/monerod.pid'; + isRunning = true; + } + + if (path) { + return { path, configFile, pidFile, isRunning }; + } + + return undefined; + } + + private static async detectInstalledWindows(): Promise { + return undefined; + } + + private static async detectInstalledMacos(): Promise { + return undefined; + } + } \ No newline at end of file diff --git a/app/process/index.ts b/app/process/index.ts index fde3fe7..0e5d96b 100644 --- a/app/process/index.ts +++ b/app/process/index.ts @@ -1,3 +1,6 @@ +export { InstallationInfo } from "./InstallationInfo"; +export { I2pdInstallationInfo } from "./I2pdInstallationInfo"; +export { MonerodInstallationInfo } from "./MonerodInstallationInfo"; export { AppMainProcess } from "./AppMainProcess"; export { ProcessStats } from "./ProcessStats"; export { AppChildProcess } from "./AppChildProcess"; diff --git a/src/app/core/services/electron/electron.service.ts b/src/app/core/services/electron/electron.service.ts index ac04742..6237df3 100644 --- a/src/app/core/services/electron/electron.service.ts +++ b/src/app/core/services/electron/electron.service.ts @@ -267,9 +267,9 @@ export class ElectronService { return this._osType; } - public async downloadFile(url: string, destination: string, progressFunction?: (info: { progress: number, status: string }) => void): Promise { + public async downloadFile(url: string, destination: string, progressFunction: (info: { progress: number, status: string }) => void): Promise { const promise = new Promise((resolve, reject) => { - window.electronAPI.downloadFile(url, destination, progressFunction ? progressFunction : (info: any) => {}, (fileName: string) => resolve(fileName), (error: string) => reject(new Error(error))); + window.electronAPI.downloadFile(url, destination, progressFunction, (fileName: string) => resolve(fileName), (error: string) => reject(new Error(error))); }); return await promise;