mirror of
https://github.com/everoddandeven/monerod-gui.git
synced 2024-12-22 19:49:27 +00:00
Get download monero url by os
This commit is contained in:
parent
65a22236ce
commit
6d381d6cfe
11 changed files with 141 additions and 9 deletions
31
app/main.ts
31
app/main.ts
|
@ -2,11 +2,11 @@ import {app, BrowserWindow, ipcMain, screen, dialog } from 'electron';
|
||||||
import { ChildProcessWithoutNullStreams, 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';
|
||||||
|
|
||||||
|
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
import * as tar from 'tar';
|
import * as tar from 'tar';
|
||||||
|
import * as os from 'os';
|
||||||
|
|
||||||
//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');
|
||||||
|
@ -68,6 +68,25 @@ function createWindow(): BrowserWindow {
|
||||||
return win;
|
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 {
|
function getMonerodVersion(monerodFilePath: string): void {
|
||||||
const monerodProcess = spawn(monerodFilePath, [ '--version' ]);
|
const monerodProcess = spawn(monerodFilePath, [ '--version' ]);
|
||||||
|
|
||||||
|
@ -332,6 +351,14 @@ try {
|
||||||
win?.webContents.send('selected-folder', path ? `${path}` : '');
|
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 (e) {
|
||||||
// Catch Error
|
// Catch Error
|
||||||
// throw e;
|
// throw e;
|
||||||
|
|
17
app/package-lock.json
generated
17
app/package-lock.json
generated
|
@ -6,7 +6,22 @@
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "angular-electron",
|
"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=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"os": "^0.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// preload.js
|
// preload.js
|
||||||
const { contextBridge, ipcRenderer } = require('electron');
|
const { contextBridge, ipcRenderer } = require('electron');
|
||||||
|
//const os = require('os');
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('electronAPI', {
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
startMonerod: (args) => {
|
startMonerod: (args) => {
|
||||||
|
@ -31,5 +32,17 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
},
|
},
|
||||||
onSelectedFolder: (callback) => {
|
onSelectedFolder: (callback) => {
|
||||||
ipcRenderer.on('selected-folder', 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
6
package-lock.json
generated
|
@ -25,6 +25,7 @@
|
||||||
"crypto": "1.0.1",
|
"crypto": "1.0.1",
|
||||||
"idb": "8.0.0",
|
"idb": "8.0.0",
|
||||||
"jquery": "3.7.1",
|
"jquery": "3.7.1",
|
||||||
|
"os": "0.1.2",
|
||||||
"rxjs": "7.8.1",
|
"rxjs": "7.8.1",
|
||||||
"tar": "7.4.3",
|
"tar": "7.4.3",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
|
@ -19332,6 +19333,11 @@
|
||||||
"node": ">=8"
|
"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": {
|
"node_modules/os-browserify": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz",
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
"crypto": "1.0.1",
|
"crypto": "1.0.1",
|
||||||
"idb": "8.0.0",
|
"idb": "8.0.0",
|
||||||
"jquery": "3.7.1",
|
"jquery": "3.7.1",
|
||||||
|
"os": "0.1.2",
|
||||||
"rxjs": "7.8.1",
|
"rxjs": "7.8.1",
|
||||||
"tar": "7.4.3",
|
"tar": "7.4.3",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
|
|
|
@ -329,9 +329,12 @@ export class DaemonDataService {
|
||||||
this._blockCount = await this.daemonService.getBlockCount();
|
this._blockCount = await this.daemonService.getBlockCount();
|
||||||
this._gettingBlockCount = false;
|
this._gettingBlockCount = false;
|
||||||
|
|
||||||
|
if (this._daemonInfo.synchronized) {
|
||||||
this._gettingLastBlockHeader = true;
|
this._gettingLastBlockHeader = true;
|
||||||
this._lastBlockHeader = await this.daemonService.getLastBlockHeader(true);
|
this._lastBlockHeader = await this.daemonService.getLastBlockHeader(true);
|
||||||
this._gettingLastBlockHeader = false;
|
this._gettingLastBlockHeader = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this._gettingIsBlockchainPruned = true;
|
this._gettingIsBlockchainPruned = true;
|
||||||
//if (firstRefresh) this._isBlockchainPruned = (await this.daemonService.pruneBlockchain(true)).pruned;
|
//if (firstRefresh) this._isBlockchainPruned = (await this.daemonService.pruneBlockchain(true)).pruned;
|
||||||
|
|
|
@ -4,6 +4,18 @@ import { Injectable, NgZone } from '@angular/core';
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class MoneroInstallerService {
|
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 _upgrading: boolean = false;
|
||||||
private _progress: { progress: number, status: string } = { progress: 0, status: 'Starting upgrade' }
|
private _progress: { progress: number, status: string } = { progress: 0, status: 'Starting upgrade' }
|
||||||
|
|
||||||
|
@ -17,8 +29,9 @@ export class MoneroInstallerService {
|
||||||
|
|
||||||
constructor(private ngZone: NgZone) {}
|
constructor(private ngZone: NgZone) {}
|
||||||
|
|
||||||
public async downloadMonero(downloadUrl: string, destination: string): Promise<string> {
|
public async downloadMonero(destination: string): Promise<string> {
|
||||||
this._upgrading = true;
|
this._upgrading = true;
|
||||||
|
const downloadUrl = await this.getMoneroDownloadLink();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await new Promise<string>((resolve, reject) => {
|
const result = await new Promise<string>((resolve, reject) => {
|
||||||
|
@ -55,5 +68,50 @@ export class MoneroInstallerService {
|
||||||
throw error;
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class SettingsComponent implements AfterViewInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnSyncEnableChange(): void {
|
public OnSyncEnableChange(): void {
|
||||||
this.currentSettings.noSync != this.currentSettings.noSync;
|
this.currentSettings.noSync = !this.currentSettings.noSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnRelayFlufflyBlocksChange(): void {
|
public OnRelayFlufflyBlocksChange(): void {
|
||||||
|
|
|
@ -120,7 +120,7 @@ export class VersionComponent implements AfterViewInit {
|
||||||
const downloadUrl = 'https://downloads.getmonero.org/cli/linux64'; // Cambia in base al sistema
|
const downloadUrl = 'https://downloads.getmonero.org/cli/linux64'; // Cambia in base al sistema
|
||||||
const destination = settings.downloadUpgradePath; // Aggiorna con il percorso desiderato
|
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`;
|
settings.monerodPath = `${moneroFolder}/monerod`;
|
||||||
|
|
||||||
|
|
|
@ -57,3 +57,11 @@ import * as $$ from 'jquery';
|
||||||
import * as $ from 'jquery';
|
import * as $ from 'jquery';
|
||||||
import * as bootstrapTable from 'bootstrap-table';
|
import * as bootstrapTable from 'bootstrap-table';
|
||||||
//import 'bootstrap-table';
|
//import 'bootstrap-table';
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
electronAPI: {
|
||||||
|
getOsType: () => void;
|
||||||
|
gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue