diff --git a/app/main.ts b/app/main.ts index f3e38a6..1ed68ce 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1,5 +1,5 @@ import {app, BrowserWindow, ipcMain, screen, dialog } from 'electron'; -import { ChildProcess, ChildProcessWithoutNullStreams, exec, spawn } from 'child_process'; +import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; import * as path from 'path'; import * as fs from 'fs'; @@ -10,16 +10,11 @@ import * as tar from 'tar'; //import bz2 from 'unbzip2-stream'; //import * as bz2 from 'unbzip2-stream'; const bz2 = require('unbzip2-stream'); -const monerodFilePath: string = "/home/sidney/Documenti/monero-x86_64-linux-gnu-v0.18.3.4/monerod"; let win: BrowserWindow | null = null; const args = process.argv.slice(1), serve = args.some(val => val === '--serve'); -function getMonerodPath(): string { - return path.resolve(__dirname, monerodFilePath); -} - function createWindow(): BrowserWindow { const size = screen.getPrimaryDisplay().workAreaSize; @@ -74,7 +69,7 @@ function createWindow(): BrowserWindow { } function getMonerodVersion(monerodFilePath: string): void { - const monerodProcess = spawn(getMonerodPath(), [ '--version' ]); + const monerodProcess = spawn(monerodFilePath, [ '--version' ]); monerodProcess.stdout.on('data', (data) => { win?.webContents.send('monero-version', `${data}`); @@ -86,7 +81,6 @@ function getMonerodVersion(monerodFilePath: string): void { } function startMoneroDaemon(commandOptions: string[]): ChildProcessWithoutNullStreams { - //const monerodPath = getMonerodPath(); const monerodPath = commandOptions.shift(); if (!monerodPath) { @@ -228,7 +222,7 @@ const verifyFileHash = (filePath: string): Promise => { }); }; -const extractTarBz2 = (filePath: string, destination: string): Promise => { +const extractTarBz2 = (filePath: string, destination: string): Promise => { return new Promise((resolve, reject) => { // Crea il file decomprimendo il .bz2 in uno .tar temporaneo const tarPath = path.join(destination, 'temp.tar'); @@ -239,14 +233,22 @@ const extractTarBz2 = (filePath: string, destination: string): Promise => decompressedStream.pipe(writeStream); + let extractedDir: string = ''; + writeStream.on('finish', () => { // Una volta che il file .tar รจ stato creato, estrailo - tar.extract({ cwd: destination, file: tarPath }) + tar.extract({ cwd: destination, file: tarPath, onReadEntry: (entry: tar.ReadEntry) => { + if (extractedDir == '') { + const topLevelDir = entry.path.split('/')[0]; + extractedDir = topLevelDir; // Salva la prima directory + } + } }) .then(() => { // Elimina il file .tar temporaneo dopo l'estrazione fs.unlink(tarPath, (err) => { if (err) reject(err); - else resolve(); + else if (extractedDir == '') reject('Extraction failed') + else resolve(extractedDir); }); }) .catch(reject); @@ -310,10 +312,10 @@ try { // Estrai il file const fPath = `${destination}/${fileName}`; event.sender.send('download-progress', { progress: 100, status: 'Extracting' }); - await extractTarBz2(fPath, destination); + const extractedDir = await extractTarBz2(fPath, destination); event.sender.send('download-progress', { progress: 100, status: 'Download and extraction completed successfully' }); - event.sender.send('download-progress', { progress: 200, status: fPath.replace('.tar.bz2', '') }); + event.sender.send('download-progress', { progress: 200, status: `${destination}/${extractedDir}` }); } catch (error) { event.sender.send('download-progress', { progress: 0, status: `Error: ${error}` }); //throw new Error(`Error: ${error}`); diff --git a/app/preload.js b/app/preload.js index 906c446..e96a365 100644 --- a/app/preload.js +++ b/app/preload.js @@ -11,8 +11,8 @@ contextBridge.exposeInMainWorld('electronAPI', { onMoneroClose: (callback) => { ipcRenderer.on('monero-close', callback); }, - getMoneroVersion: () => { - ipcRenderer.invoke('get-monero-version'); + getMoneroVersion: (monerodPath) => { + ipcRenderer.invoke('get-monero-version', monerodPath); }, onMoneroVersion: (callback) => { ipcRenderer.on('monero-version', callback); diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index a4fd7d7..0987029 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -607,9 +607,13 @@ export class DaemonService { return DaemonVersion.parse(response.result); } else if (dontUseRpc) { - const monerodPath: string = ''; // TO DO get local monerod path + const monerodPath: string = (await this.getSettings()).monerodPath; const wdw = (window as any); + if (monerodPath == '') { + throw new Error("Daemon not configured"); + } + return new Promise((resolve, reject) => { if (this.electronService.isElectron) { this.electronService.ipcRenderer.on('on-monerod-version', (event, version: string) => { @@ -629,7 +633,7 @@ export class DaemonService { wdw.electronAPI.onMoneroVersionError((event: any, error: string) => { reject(error); }); - wdw.electronAPI.getMoneroVersion(); + wdw.electronAPI.getMoneroVersion(monerodPath); } }); } diff --git a/src/app/pages/version/version.component.ts b/src/app/pages/version/version.component.ts index 0e7811d..08f31a0 100644 --- a/src/app/pages/version/version.component.ts +++ b/src/app/pages/version/version.component.ts @@ -17,8 +17,6 @@ export class VersionComponent implements AfterViewInit { public currentVersion?: DaemonVersion; public latestVersion?: DaemonVersion; - public downloadPath: string = '/home/sidney/monerod/'; - public get buttonDisabled(): boolean { const title = this.buttonTitle; diff --git a/src/app/shared/components/daemon-not-running/daemon-not-running.component.html b/src/app/shared/components/daemon-not-running/daemon-not-running.component.html index c27dae4..7b4e975 100644 --- a/src/app/shared/components/daemon-not-running/daemon-not-running.component.html +++ b/src/app/shared/components/daemon-not-running/daemon-not-running.component.html @@ -36,5 +36,6 @@   - +   + \ No newline at end of file