Get download monero url by os

This commit is contained in:
everoddandeven 2024-10-09 23:40:32 +02:00
parent 65a22236ce
commit 6d381d6cfe
11 changed files with 141 additions and 9 deletions

View file

@ -2,11 +2,11 @@ import {app, BrowserWindow, ipcMain, screen, dialog } from 'electron';
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import * as path from 'path';
import * as fs from 'fs';
import * as https from 'https';
import { createHash } from 'crypto';
import * as tar from 'tar';
import * as os from 'os';
//import bz2 from 'unbzip2-stream';
//import * as bz2 from 'unbzip2-stream';
const bz2 = require('unbzip2-stream');
@ -68,6 +68,25 @@ function createWindow(): BrowserWindow {
return win;
}
function isWifiConnected() {
const networkInterfaces = os.networkInterfaces();
for (const interfaceName in networkInterfaces) {
const networkInterface = networkInterfaces[interfaceName];
if (networkInterface) {
for (const network of networkInterface) {
if (network.family === 'IPv4' && !network.internal && network.mac !== '00:00:00:00:00:00') {
if (interfaceName.toLowerCase().includes('wifi') || interfaceName.toLowerCase().includes('wlan')) {
return true;
}
}
}
}
}
return false;
}
function getMonerodVersion(monerodFilePath: string): void {
const monerodProcess = spawn(monerodFilePath, [ '--version' ]);
@ -332,6 +351,14 @@ try {
win?.webContents.send('selected-folder', path ? `${path}` : '');
});
ipcMain.handle('is-wifi-connected', async (event) => {
win?.webContents.send('is-wifi-connected-result', isWifiConnected());
});
ipcMain.handle('get-os-type', (event) => {
win?.webContents.send('got-os-type', { platform: os.platform(), arch: os.arch() });
})
} catch (e) {
// Catch Error
// throw e;

17
app/package-lock.json generated
View file

@ -6,7 +6,22 @@
"packages": {
"": {
"name": "angular-electron",
"version": "14.0.1"
"version": "14.0.1",
"dependencies": {
"os": "^0.1.2"
}
},
"node_modules/os": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/os/-/os-0.1.2.tgz",
"integrity": "sha512-ZoXJkvAnljwvc56MbvhtKVWmSkzV712k42Is2mA0+0KTSRakq5XXuXpjZjgAt9ctzl51ojhQWakQQpmOvXWfjQ=="
}
},
"dependencies": {
"os": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/os/-/os-0.1.2.tgz",
"integrity": "sha512-ZoXJkvAnljwvc56MbvhtKVWmSkzV712k42Is2mA0+0KTSRakq5XXuXpjZjgAt9ctzl51ojhQWakQQpmOvXWfjQ=="
}
}
}

View file

@ -9,5 +9,6 @@
"main": "main.js",
"private": true,
"dependencies": {
"os": "^0.1.2"
}
}

View file

@ -1,5 +1,6 @@
// preload.js
const { contextBridge, ipcRenderer } = require('electron');
//const os = require('os');
contextBridge.exposeInMainWorld('electronAPI', {
startMonerod: (args) => {
@ -31,5 +32,17 @@ contextBridge.exposeInMainWorld('electronAPI', {
},
onSelectedFolder: (callback) => {
ipcRenderer.on('selected-folder', callback);
},
isWifiConnected: () => {
ipcRenderer.invoke('is-wifi-connected');
},
onIsWifiConnectedResponse: (callback) => {
ipcRenderer.on('is-wifi-connected-result', callback);
},
getOsType: () => {
ipcRenderer.invoke('get-os-type');
},
gotOsType: (callback) => {
ipcRenderer.on('got-os-type', callback);
}
});

6
package-lock.json generated
View file

@ -25,6 +25,7 @@
"crypto": "1.0.1",
"idb": "8.0.0",
"jquery": "3.7.1",
"os": "0.1.2",
"rxjs": "7.8.1",
"tar": "7.4.3",
"tslib": "2.6.2",
@ -19332,6 +19333,11 @@
"node": ">=8"
}
},
"node_modules/os": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/os/-/os-0.1.2.tgz",
"integrity": "sha512-ZoXJkvAnljwvc56MbvhtKVWmSkzV712k42Is2mA0+0KTSRakq5XXuXpjZjgAt9ctzl51ojhQWakQQpmOvXWfjQ=="
},
"node_modules/os-browserify": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz",

View file

@ -62,6 +62,7 @@
"crypto": "1.0.1",
"idb": "8.0.0",
"jquery": "3.7.1",
"os": "0.1.2",
"rxjs": "7.8.1",
"tar": "7.4.3",
"tslib": "2.6.2",

View file

@ -329,9 +329,12 @@ export class DaemonDataService {
this._blockCount = await this.daemonService.getBlockCount();
this._gettingBlockCount = false;
if (this._daemonInfo.synchronized) {
this._gettingLastBlockHeader = true;
this._lastBlockHeader = await this.daemonService.getLastBlockHeader(true);
this._gettingLastBlockHeader = false;
}
this._gettingIsBlockchainPruned = true;
//if (firstRefresh) this._isBlockchainPruned = (await this.daemonService.pruneBlockchain(true)).pruned;

View file

@ -4,6 +4,18 @@ import { Injectable, NgZone } from '@angular/core';
providedIn: 'root'
})
export class MoneroInstallerService {
private readonly resources = {
win32: 'https://downloads.getmonero.org/cli/win32',
win64: 'https://downloads.getmonero.org/cli/win64',
mac64: 'https://downloads.getmonero.org/cli/mac64',
macarm8: 'https://downloads.getmonero.org/cli/macarm8',
linux32: 'https://downloads.getmonero.org/cli/linux32',
linux64: 'https://downloads.getmonero.org/cli/linux64',
linuxarm7: 'https://downloads.getmonero.org/cli/linuxarm7',
linuxarm8: 'https://downloads.getmonero.org/cli/linuxarm8',
linuxriscv64: 'https://downloads.getmonero.org/cli/linuxriscv64'
};
private _upgrading: boolean = false;
private _progress: { progress: number, status: string } = { progress: 0, status: 'Starting upgrade' }
@ -17,8 +29,9 @@ export class MoneroInstallerService {
constructor(private ngZone: NgZone) {}
public async downloadMonero(downloadUrl: string, destination: string): Promise<string> {
public async downloadMonero(destination: string): Promise<string> {
this._upgrading = true;
const downloadUrl = await this.getMoneroDownloadLink();
try {
const result = await new Promise<string>((resolve, reject) => {
@ -55,5 +68,50 @@ export class MoneroInstallerService {
throw error;
}
}
private async getMoneroDownloadLink(): Promise<string> {
return new Promise<string>((resolve, reject) => {
window.electronAPI.gotOsType((event: any, osType: { platform: string, arch: string }) => {
const platform = osType.platform;
const arch = osType.arch;
let resource: string = '';
// Mappatura tra sistema operativo e architettura
if (platform === 'win32') {
resource = arch === 'x64' ? this.resources.win64 : this.resources.win32;
} else if (platform === 'darwin') {
resource = arch === 'arm64' ? this.resources.macarm8 : this.resources.mac64;
}
else if (platform === 'linux') {
if (arch === 'x64') {
resource = this.resources.linux64;
}
else if (arch === 'ia32') {
resource = this.resources.linux32;
}
else if (arch === 'arm') {
resource = this.resources.linuxarm7;
}
else if (arch === 'arm64') {
resource = this.resources.linuxarm8;
}
else if (arch === 'riscv64') {
resource = this.resources.linuxriscv64;
}
}
if (resource != '')
{
resolve(resource);
}
reject('Unsopported platform ' + platform);
});
window.electronAPI.getOsType();
});
}
}

View file

@ -109,7 +109,7 @@ export class SettingsComponent implements AfterViewInit {
}
public OnSyncEnableChange(): void {
this.currentSettings.noSync != this.currentSettings.noSync;
this.currentSettings.noSync = !this.currentSettings.noSync;
}
public OnRelayFlufflyBlocksChange(): void {

View file

@ -120,7 +120,7 @@ export class VersionComponent implements AfterViewInit {
const downloadUrl = 'https://downloads.getmonero.org/cli/linux64'; // Cambia in base al sistema
const destination = settings.downloadUpgradePath; // Aggiorna con il percorso desiderato
const moneroFolder = await this.moneroInstaller.downloadMonero(downloadUrl, destination);
const moneroFolder = await this.moneroInstaller.downloadMonero(destination);
settings.monerodPath = `${moneroFolder}/monerod`;

View file

@ -57,3 +57,11 @@ import * as $$ from 'jquery';
import * as $ from 'jquery';
import * as bootstrapTable from 'bootstrap-table';
//import 'bootstrap-table';
declare global {
interface Window {
electronAPI: {
getOsType: () => void;
gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void;
};
}
}