Skip to content

Commit

Permalink
I2pdProcess partial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Feb 11, 2025
1 parent 6b28ddc commit 218bb49
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 5 deletions.
9 changes: 7 additions & 2 deletions app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import axios, { AxiosRequestConfig } from 'axios';
import { AppMainProcess, MonerodProcess, PrivateTestnet } from './process';
import { AppMainProcess, I2pdProcess, MonerodProcess, PrivateTestnet } from './process';
import { BatteryUtils, FileUtils, NetworkUtils } from './utils';

app.setName('Monero Daemon');
Expand Down Expand Up @@ -772,7 +772,12 @@ try {

ipcMain.handle('check-valid-monerod-path', (event: IpcMainInvokeEvent, path: string) => {
checkValidMonerodPath(path);
})
});

ipcMain.handle('check-valid-i2pd-path', async (event: IpcMainInvokeEvent, params: { eventId: string, path: string }) => {
const { eventId, path } = params;
win?.webContents.send(eventId, await I2pdProcess.isValidPath(path));
});

ipcMain.handle('show-notification', (event: IpcMainInvokeEvent, options?: NotificationConstructorOptions) => {
showNotification(options);
Expand Down
15 changes: 15 additions & 0 deletions app/preload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
// preload.js
const { contextBridge, ipcRenderer } = require('electron');

function newId() {
return parseInt(`${Math.random()*1000}`);
}

contextBridge.exposeInMainWorld('electronAPI', {
checkValidI2pdPath: (path, callback) => {
const eventId = `on-check-valid-i2pd-path-${newId()}`;

const handler = (event, result) => {
ipcRenderer.off(eventId, handler);
callback(result);
};

ipcRenderer.on(eventId, handler);
ipcRenderer.invoke('check-valid-i2pd-path', { eventId, path });
},
httpPost: (params, callback) => {
const { id } = params;

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

export class I2pdProcess extends AppChildProcess {

public static async isValidPath(path: string): Promise<boolean> {
return false;
}
}
3 changes: 2 additions & 1 deletion app/process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { AppMainProcess } from "./AppMainProcess";
export { ProcessStats } from "./ProcessStats";
export { AppChildProcess } from "./AppChildProcess";
export { MonerodProcess } from "./MonerodProcess";
export { PrivateTestnet } from "./PrivateTestnet";
export { PrivateTestnet } from "./PrivateTestnet";
export { I2pdProcess } from "./I2pdProcess";
14 changes: 14 additions & 0 deletions src/app/core/services/daemon/daemon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ export class DaemonService {
return await checkPromise;
}


public async checkValidI2pdPath(path: string): Promise<boolean> {
if (path == null || path == undefined || path.replace(' ', '') == '') {
return false;
}

const checkPromise = new Promise<boolean>((resolve) => {
window.electronAPI.checkValidI2pdPath(path, resolve);
});

return await checkPromise;
}


public async getSettings(): Promise<DaemonSettings> {
const db = await this.openDbPromise;
const result = await db.get(this.storeName, 1);
Expand Down
36 changes: 35 additions & 1 deletion src/app/pages/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,41 @@ <h4 class="mb-3">TOR Anonymous Inbound</h4>
<div class="row g-5 p-3">
<div class="col-md-12 col-lg-12">
<form class="needs-validation" novalidate="">

<h4 class="mb-3">I2pd</h4>

<div class="col-md-12">
<label for="i2pd-path" class="form-label">I2pd path</label>
<div class="input-group mb-3">
<input id="i2pd-path" type="text" class="form-control form-control-sm" placeholder="" aria-label="I2pd path" aria-describedby="basic-addon2" [value]="currentSettings.i2pdPath" readonly>
<span class="input-group-text" id="basic-addon2"><button type="button" class="btn btn-secondary btn-sm" (click)="chooseI2pdFile()"><i class="bi bi-filetype-exe"></i> Choose executable</button></span>
<span class="input-group-text" id="basic-addon3"><button type="button" class="btn btn-secondary btn-sm" (click)="removeMonerodFile()" [disabled]="currentSettings.i2pdPath === ''"><i class="bi bi-file-x"></i> Remove</button></span>
</div>
<small class="text-body-secondary">Path to i2pd executable</small>
</div>

<hr class="my-4">
<h4 class="mb-3">Config file</h4>

<div class="row g-3">

<div class="col-md-6">
<label for="import-i2pd-config-file" class="form-label">Import config file</label>
<div class="input-group mb-3">
<button [disabled]="!canImportConfigFile" type="button" class="btn btn-secondary btn-sm" (click)="importMonerodConfigFile()"><i class="bi bi-box-arrow-in-down"></i> Import</button>
</div>
<small class="text-body-secondary">Import custom i2pd config file</small>
</div>

<div class="col-md-6">
<label for="export-i2pd-config-file" class="form-label">Export config file</label>
<div class="input-group mb-3">
<button [disabled]="!canExportConfigFile" type="button" class="btn btn-secondary btn-sm" (click)="exportMonerodConfigFile()"><i class="bi bi-box-arrow-up-right"></i> Export</button>
</div>
<small class="text-body-secondary">Export current saved i2pd settings to config file</small>
</div>

</div>

<div class="row g-3">
<h4 class="mb-3">I2P Tx Proxy</h4>

Expand Down
37 changes: 37 additions & 0 deletions src/app/pages/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ export class SettingsComponent extends BasePageComponent implements AfterViewIni
throw new Error("Could not get monerod mime type");
}

private async getI2pdFileSpec(): Promise<{ extensions?: string[]; mimeType: string; }> {
const { platform } = await this.electronService.getOsType();

if (platform == 'win32') {
return { mimeType: 'application/vnd.microsoft.portable-executable', extensions: ['exe']};
}
else if (platform == 'darwin') {
return { mimeType: 'application/octet-stream' };
}
else if (platform == 'linux') {
return { mimeType: 'application/x-executable'};
}

throw new Error("Could not get i2pd mime type");
}

public async importMonerodConfigFile(): Promise<void> {
try {
try {
Expand Down Expand Up @@ -827,6 +843,27 @@ export class SettingsComponent extends BasePageComponent implements AfterViewIni
}
}

public async chooseI2pdFile(): Promise<void> {
const spec = await this.getI2pdFileSpec();
const file = await this.electronService.selectFile(spec.extensions);

if (file == '') {
return;
}

const valid = await this.daemonService.checkValidI2pdPath(file);
if (valid) {
this.ngZone.run(() => {
const currentSettings = this.currentSettings;
if (currentSettings instanceof PrivnetDaemonSettings) return;
else currentSettings.i2pdPath = file;
});
}
else {
window.electronAPI.showErrorBox('Invalid i2pd path', `Invalid i2pd path provided: ${file}`);
}
}

public async chooseBanListFile(): Promise<void> {
const file = await this.electronService.selectFile(['txt']);

Expand Down
1 change: 1 addition & 0 deletions src/common/DaemonSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DaemonSettingsDuplicateExclusiveNodeError, DaemonSettingsDuplicatePrior

export class DaemonSettings {
public monerodPath: string = '';
public i2pdPath: string = '';

public startAtLogin: boolean = false;
public startAtLoginMinimized: boolean = false;
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ declare global {
onMoneroClose: (callback: (event: any, code: number) => void) => void;
onMoneroStdout: (callbak: (event: any, out: string) => void) => void;
unregisterOnMoneroStdout: () => void;

checkValidI2pdPath: (path: string, callback: (valid: boolean) => void) => void;
isWifiConnected: () => void;
onIsWifiConnectedResponse: (callback: (event: any, connected: boolean) => void) => void;
unregisterOnIsWifiConnectedResponse: () => void;
Expand Down

0 comments on commit 218bb49

Please sign in to comment.