Skip to content

Commit

Permalink
Detect linux monerod installation
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Feb 14, 2025
1 parent fde4167 commit 8040975
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ async function detectInstallation(program: string): Promise<any> {
if (program === 'i2pd') {
return await I2pdProcess.detectInstalled();
}
else if (program === 'monerod') {
return await MonerodProcess.detectInstalled();
}
else return undefined;
}

Expand Down
3 changes: 3 additions & 0 deletions app/process/I2pdInstallationInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { InstallationInfo } from "./InstallationInfo";

export interface I2pdInstallationInfo extends InstallationInfo { configFile?: string; tunnelConfig?: string; tunnelsConfigDir?: string; pidFile?: string; isRunning?: boolean; };
4 changes: 1 addition & 3 deletions app/process/I2pdProcess.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions app/process/InstallationInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface InstallationInfo { path: string };
7 changes: 7 additions & 0 deletions app/process/MonerodInstallationInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { InstallationInfo } from "./InstallationInfo";

export interface MonerodInstallationInfo extends InstallationInfo {
configFile?: string;
pidFile?: string;
isRunning?: boolean;
};
51 changes: 51 additions & 0 deletions app/process/MonerodProcess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AppChildProcess } from "./AppChildProcess";
import { MonerodInstallationInfo } from "./MonerodInstallationInfo";
import * as fs from 'fs';

export class MonerodProcess extends AppChildProcess {

Expand Down Expand Up @@ -232,4 +234,53 @@ export class MonerodProcess extends AppChildProcess {
return await promise;
}

public static async detectInstalled(): Promise<MonerodInstallationInfo | undefined> {
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<MonerodInstallationInfo | undefined> {
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<MonerodInstallationInfo | undefined> {
return undefined;
}

private static async detectInstalledMacos(): Promise<MonerodInstallationInfo | undefined> {
return undefined;
}

}
3 changes: 3 additions & 0 deletions app/process/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/electron/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
public async downloadFile(url: string, destination: string, progressFunction: (info: { progress: number, status: string }) => void): Promise<string> {
const promise = new Promise<string>((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;
Expand Down

0 comments on commit 8040975

Please sign in to comment.