mirror of
https://github.com/everoddandeven/monerod-gui.git
synced 2024-12-22 11:39:25 +00:00
Prompt select folder if download path is not configured instead of showing an error
This commit is contained in:
parent
a4e3ea5224
commit
10142f5b88
7 changed files with 74 additions and 35 deletions
18
app/main.ts
18
app/main.ts
|
@ -669,14 +669,26 @@ try {
|
|||
|
||||
// Inizializza il progresso
|
||||
event.sender.send('download-progress', { progress: 0, status: 'Starting download' });
|
||||
|
||||
win?.setProgressBar(0, {
|
||||
mode: 'normal'
|
||||
});
|
||||
|
||||
// Scarica il file Monero
|
||||
const fileName = await downloadFile(downloadUrl, destination, (progress) => {
|
||||
win?.setProgressBar(progress, {
|
||||
mode: 'normal'
|
||||
});
|
||||
|
||||
event.sender.send('download-progress', { progress, status: 'Downloading' });
|
||||
});
|
||||
|
||||
// Scarica e verifica l'hash
|
||||
event.sender.send('download-progress', { progress: 100, status: 'Verifying hash' });
|
||||
win?.setProgressBar(100, {
|
||||
mode: 'indeterminate'
|
||||
});
|
||||
|
||||
await downloadAndVerifyHash(hashUrl, fileName, destination);
|
||||
|
||||
// Estrai il file
|
||||
|
@ -686,9 +698,13 @@ try {
|
|||
|
||||
event.sender.send('download-progress', { progress: 100, status: 'Download and extraction completed successfully' });
|
||||
event.sender.send('download-progress', { progress: 200, status: `${destination}/${extractedDir}` });
|
||||
|
||||
win?.setProgressBar(100, {
|
||||
mode: 'none'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
event.sender.send('download-progress', { progress: 0, status: `Error: ${error}` });
|
||||
//throw new Error(`Error: ${error}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -69,12 +69,18 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
onSelectedFolder: (callback) => {
|
||||
ipcRenderer.on('selected-folder', callback);
|
||||
},
|
||||
unregisterOnSelectedFolder: () => {
|
||||
ipcRenderer.removeAllListeners('selected-folder');
|
||||
},
|
||||
selectFile: (extensions = undefined) => {
|
||||
ipcRenderer.invoke('select-file', extensions);
|
||||
},
|
||||
onSelectedFile: (callback) => {
|
||||
ipcRenderer.on('selected-file', callback);
|
||||
},
|
||||
unregisterOnSelectedFile: () => {
|
||||
ipcRenderer.removeAllListeners('selected-file');
|
||||
},
|
||||
isWifiConnected: () => {
|
||||
ipcRenderer.invoke('is-wifi-connected');
|
||||
},
|
||||
|
|
|
@ -204,4 +204,31 @@ export class ElectronService {
|
|||
return this._isAppImage;
|
||||
}
|
||||
|
||||
public async selectFile(extensions?: string[]): Promise<string> {
|
||||
|
||||
const selectPromise: Promise<string> = new Promise<string>((resolve) => {
|
||||
window.electronAPI.onSelectedFile((event: any, path: string) => {
|
||||
window.electronAPI.unregisterOnSelectedFile();
|
||||
resolve(path);
|
||||
});
|
||||
});
|
||||
|
||||
window.electronAPI.selectFile(extensions);
|
||||
|
||||
return await selectPromise;
|
||||
}
|
||||
|
||||
public async selectFolder(): Promise<string> {
|
||||
const selectPromise = new Promise<string>((resolve) => {
|
||||
window.electronAPI.onSelectedFolder((event: any, folder: string) => {
|
||||
window.electronAPI.unregisterOnSelectedFolder();
|
||||
resolve(folder);
|
||||
});
|
||||
});
|
||||
|
||||
window.electronAPI.selectFolder();
|
||||
|
||||
return await selectPromise;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ export class SettingsComponent {
|
|||
}
|
||||
|
||||
public async chooseMonerodFile(): Promise<void> {
|
||||
const file = await this.selectFile();
|
||||
const file = await this.electronService.selectFile();
|
||||
|
||||
if (file == '') {
|
||||
return;
|
||||
|
@ -213,7 +213,7 @@ export class SettingsComponent {
|
|||
}
|
||||
|
||||
private async choosePemFile(): Promise<string> {
|
||||
return await this.selectFile(['pem', 'PEM']);
|
||||
return await this.electronService.selectFile(['pem', 'PEM']);
|
||||
}
|
||||
|
||||
public async selectSslPrivateKey(): Promise<void> {
|
||||
|
@ -246,33 +246,8 @@ export class SettingsComponent {
|
|||
});
|
||||
}
|
||||
|
||||
private async selectFile(extensions?: string[]): Promise<string> {
|
||||
|
||||
const selectPromise: Promise<string> = new Promise<string>((resolve) => {
|
||||
window.electronAPI.onSelectedFile((event: any, path: string) => {
|
||||
resolve(path);
|
||||
});
|
||||
});
|
||||
|
||||
window.electronAPI.selectFile(extensions);
|
||||
|
||||
return await selectPromise;
|
||||
}
|
||||
|
||||
private async selectFolder(): Promise<string> {
|
||||
const selectPromise = new Promise<string>((resolve) => {
|
||||
window.electronAPI.onSelectedFolder((event: any, folder: string) => {
|
||||
resolve(folder);
|
||||
});
|
||||
});
|
||||
|
||||
window.electronAPI.selectFolder();
|
||||
|
||||
return await selectPromise;
|
||||
}
|
||||
|
||||
public async chooseMoneroDownloadPath(): Promise<void> {
|
||||
const folder = await this.selectFolder();
|
||||
const folder = await this.electronService.selectFolder();
|
||||
|
||||
if (folder == '')
|
||||
{
|
||||
|
@ -285,7 +260,7 @@ export class SettingsComponent {
|
|||
}
|
||||
|
||||
public async chooseDataDir(): Promise<void> {
|
||||
const folder = await this.selectFolder();
|
||||
const folder = await this.electronService.selectFolder();
|
||||
|
||||
if (folder == '') {
|
||||
return;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
<div class="row d-flex justify-content-center">
|
||||
@for(card of cards; track card.header) {
|
||||
@if(card.loading) {
|
||||
@if(loading) {
|
||||
<div class="card text-bg-dark m-3 text-center" style="max-width: 18rem;" aria-hidden="true">
|
||||
<div class="card-header"><strong>{{card.header}}</strong></div>
|
||||
<div class="card-body">
|
||||
|
|
|
@ -68,9 +68,7 @@ export class VersionComponent implements AfterViewInit {
|
|||
|
||||
private createErrorCards(): SimpleBootstrapCard[] {
|
||||
return [
|
||||
new SimpleBootstrapCard('GUI Version', this.daemonService.getGuiVersion()),
|
||||
new SimpleBootstrapCard('Current Monerod version', 'Error', false),
|
||||
new SimpleBootstrapCard('Latest Monerod version', 'Error', false)
|
||||
new SimpleBootstrapCard('GUI Version', this.daemonService.getGuiVersion())
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -103,6 +101,7 @@ export class VersionComponent implements AfterViewInit {
|
|||
}
|
||||
catch(error: any) {
|
||||
console.error(error);
|
||||
this.cards = this.createErrorCards();
|
||||
}
|
||||
|
||||
this.loading = false;
|
||||
|
@ -123,17 +122,31 @@ export class VersionComponent implements AfterViewInit {
|
|||
|
||||
public async upgrade(): Promise<void> {
|
||||
if (this.upgrading || this.installing) {
|
||||
console.warn("Already upgrading");
|
||||
this.upgradeSuccess = false;
|
||||
this.upgradeError = `Daemon is already upgrading`;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const settings = await this.daemonService.getSettings();
|
||||
|
||||
if (settings.downloadUpgradePath == '') {
|
||||
settings.downloadUpgradePath = await this.electronService.selectFolder();
|
||||
if (settings.downloadUpgradePath != '') {
|
||||
await this.daemonService.saveSettings(settings, true);
|
||||
}
|
||||
else {
|
||||
throw new Error("Must select a valid download path before installing");
|
||||
}
|
||||
}
|
||||
|
||||
await this.daemonService.upgrade();
|
||||
|
||||
this.upgradeError = '';
|
||||
this.upgradeSuccess = true;
|
||||
}
|
||||
catch(error: any) {
|
||||
|
||||
console.error(error);
|
||||
this.upgradeSuccess = false;
|
||||
this.upgradeError = `${error}`;
|
||||
|
|
|
@ -100,6 +100,8 @@ declare global {
|
|||
selectFile: (extensions?: string[]) => void;
|
||||
onSelectedFolder: (callback: (event: any, path: string) => void) => void;
|
||||
onSelectedFile: (callback: (event: any, path: string) => void) => void;
|
||||
unregisterOnSelectedFile: () => void;
|
||||
unregisterOnSelectedFolder: () => void;
|
||||
getOsType: () => void;
|
||||
gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void;
|
||||
unregisterGotOsType: () => void;
|
||||
|
|
Loading…
Reference in a new issue