Fix upgrade

This commit is contained in:
everoddandeven 2024-10-09 21:44:37 +02:00
parent f9d878906f
commit 65a22236ce
5 changed files with 25 additions and 20 deletions

View file

@ -1,5 +1,5 @@
import {app, BrowserWindow, ipcMain, screen, dialog } from 'electron'; 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 path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
@ -10,16 +10,11 @@ import * as tar from 'tar';
//import bz2 from 'unbzip2-stream'; //import bz2 from 'unbzip2-stream';
//import * as bz2 from 'unbzip2-stream'; //import * as bz2 from 'unbzip2-stream';
const bz2 = require('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; let win: BrowserWindow | null = null;
const args = process.argv.slice(1), const args = process.argv.slice(1),
serve = args.some(val => val === '--serve'); serve = args.some(val => val === '--serve');
function getMonerodPath(): string {
return path.resolve(__dirname, monerodFilePath);
}
function createWindow(): BrowserWindow { function createWindow(): BrowserWindow {
const size = screen.getPrimaryDisplay().workAreaSize; const size = screen.getPrimaryDisplay().workAreaSize;
@ -74,7 +69,7 @@ function createWindow(): BrowserWindow {
} }
function getMonerodVersion(monerodFilePath: string): void { function getMonerodVersion(monerodFilePath: string): void {
const monerodProcess = spawn(getMonerodPath(), [ '--version' ]); const monerodProcess = spawn(monerodFilePath, [ '--version' ]);
monerodProcess.stdout.on('data', (data) => { monerodProcess.stdout.on('data', (data) => {
win?.webContents.send('monero-version', `${data}`); win?.webContents.send('monero-version', `${data}`);
@ -86,7 +81,6 @@ function getMonerodVersion(monerodFilePath: string): void {
} }
function startMoneroDaemon(commandOptions: string[]): ChildProcessWithoutNullStreams { function startMoneroDaemon(commandOptions: string[]): ChildProcessWithoutNullStreams {
//const monerodPath = getMonerodPath();
const monerodPath = commandOptions.shift(); const monerodPath = commandOptions.shift();
if (!monerodPath) { if (!monerodPath) {
@ -228,7 +222,7 @@ const verifyFileHash = (filePath: string): Promise<string> => {
}); });
}; };
const extractTarBz2 = (filePath: string, destination: string): Promise<void> => { const extractTarBz2 = (filePath: string, destination: string): Promise<string> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Crea il file decomprimendo il .bz2 in uno .tar temporaneo // Crea il file decomprimendo il .bz2 in uno .tar temporaneo
const tarPath = path.join(destination, 'temp.tar'); const tarPath = path.join(destination, 'temp.tar');
@ -239,14 +233,22 @@ const extractTarBz2 = (filePath: string, destination: string): Promise<void> =>
decompressedStream.pipe(writeStream); decompressedStream.pipe(writeStream);
let extractedDir: string = '';
writeStream.on('finish', () => { writeStream.on('finish', () => {
// Una volta che il file .tar è stato creato, estrailo // 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(() => { .then(() => {
// Elimina il file .tar temporaneo dopo l'estrazione // Elimina il file .tar temporaneo dopo l'estrazione
fs.unlink(tarPath, (err) => { fs.unlink(tarPath, (err) => {
if (err) reject(err); if (err) reject(err);
else resolve(); else if (extractedDir == '') reject('Extraction failed')
else resolve(extractedDir);
}); });
}) })
.catch(reject); .catch(reject);
@ -310,10 +312,10 @@ try {
// Estrai il file // Estrai il file
const fPath = `${destination}/${fileName}`; const fPath = `${destination}/${fileName}`;
event.sender.send('download-progress', { progress: 100, status: 'Extracting' }); 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: 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) { } catch (error) {
event.sender.send('download-progress', { progress: 0, status: `Error: ${error}` }); event.sender.send('download-progress', { progress: 0, status: `Error: ${error}` });
//throw new Error(`Error: ${error}`); //throw new Error(`Error: ${error}`);

View file

@ -11,8 +11,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
onMoneroClose: (callback) => { onMoneroClose: (callback) => {
ipcRenderer.on('monero-close', callback); ipcRenderer.on('monero-close', callback);
}, },
getMoneroVersion: () => { getMoneroVersion: (monerodPath) => {
ipcRenderer.invoke('get-monero-version'); ipcRenderer.invoke('get-monero-version', monerodPath);
}, },
onMoneroVersion: (callback) => { onMoneroVersion: (callback) => {
ipcRenderer.on('monero-version', callback); ipcRenderer.on('monero-version', callback);

View file

@ -607,9 +607,13 @@ export class DaemonService {
return DaemonVersion.parse(response.result); return DaemonVersion.parse(response.result);
} }
else if (dontUseRpc) { else if (dontUseRpc) {
const monerodPath: string = ''; // TO DO get local monerod path const monerodPath: string = (await this.getSettings()).monerodPath;
const wdw = (window as any); const wdw = (window as any);
if (monerodPath == '') {
throw new Error("Daemon not configured");
}
return new Promise<DaemonVersion>((resolve, reject) => { return new Promise<DaemonVersion>((resolve, reject) => {
if (this.electronService.isElectron) { if (this.electronService.isElectron) {
this.electronService.ipcRenderer.on('on-monerod-version', (event, version: string) => { this.electronService.ipcRenderer.on('on-monerod-version', (event, version: string) => {
@ -629,7 +633,7 @@ export class DaemonService {
wdw.electronAPI.onMoneroVersionError((event: any, error: string) => { wdw.electronAPI.onMoneroVersionError((event: any, error: string) => {
reject(error); reject(error);
}); });
wdw.electronAPI.getMoneroVersion(); wdw.electronAPI.getMoneroVersion(monerodPath);
} }
}); });
} }

View file

@ -17,8 +17,6 @@ export class VersionComponent implements AfterViewInit {
public currentVersion?: DaemonVersion; public currentVersion?: DaemonVersion;
public latestVersion?: DaemonVersion; public latestVersion?: DaemonVersion;
public downloadPath: string = '/home/sidney/monerod/';
public get buttonDisabled(): boolean { public get buttonDisabled(): boolean {
const title = this.buttonTitle; const title = this.buttonTitle;

View file

@ -36,5 +36,6 @@
&nbsp; &nbsp;
<button *ngIf="!startingDaemon && !stoppingDaemon && !restartingDaemon && !upgrading" routerLink="/settings" class="btn btn-outline-light" type="button"><i class="bi bi-gear"></i> Configure</button> <button *ngIf="!startingDaemon && !stoppingDaemon && !restartingDaemon && !upgrading" routerLink="/settings" class="btn btn-outline-light" type="button"><i class="bi bi-gear"></i> Configure</button>
<button *ngIf="!startingDaemon && !stoppingDaemon && !restartingDaemon && !upgrading" routerLink="/version" class="btn btn-outline-light" type="button"><i class="bi bi-arrow-down-circle"></i> Install</button> &nbsp;
<button *ngIf="!startingDaemon && !stoppingDaemon && !restartingDaemon && !upgrading && !daemonConfigured" routerLink="/version" class="btn btn-outline-light" type="button"><i class="bi bi-arrow-down-circle"></i> Install</button>
</div> </div>