Prompt select folder if download path is not configured instead of showing an error

This commit is contained in:
everoddandeven 2024-10-29 16:29:32 +01:00
parent a4e3ea5224
commit 10142f5b88
7 changed files with 74 additions and 35 deletions

View file

@ -670,13 +670,25 @@ try {
// Inizializza il progresso // Inizializza il progresso
event.sender.send('download-progress', { progress: 0, status: 'Starting download' }); event.sender.send('download-progress', { progress: 0, status: 'Starting download' });
win?.setProgressBar(0, {
mode: 'normal'
});
// Scarica il file Monero // Scarica il file Monero
const fileName = await downloadFile(downloadUrl, destination, (progress) => { const fileName = await downloadFile(downloadUrl, destination, (progress) => {
win?.setProgressBar(progress, {
mode: 'normal'
});
event.sender.send('download-progress', { progress, status: 'Downloading' }); event.sender.send('download-progress', { progress, status: 'Downloading' });
}); });
// Scarica e verifica l'hash // Scarica e verifica l'hash
event.sender.send('download-progress', { progress: 100, status: 'Verifying hash' }); event.sender.send('download-progress', { progress: 100, status: 'Verifying hash' });
win?.setProgressBar(100, {
mode: 'indeterminate'
});
await downloadAndVerifyHash(hashUrl, fileName, destination); await downloadAndVerifyHash(hashUrl, fileName, destination);
// Estrai il file // 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: 100, status: 'Download and extraction completed successfully' });
event.sender.send('download-progress', { progress: 200, status: `${destination}/${extractedDir}` }); event.sender.send('download-progress', { progress: 200, status: `${destination}/${extractedDir}` });
win?.setProgressBar(100, {
mode: 'none'
});
} 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}`);
} }
}); });

View file

@ -69,12 +69,18 @@ contextBridge.exposeInMainWorld('electronAPI', {
onSelectedFolder: (callback) => { onSelectedFolder: (callback) => {
ipcRenderer.on('selected-folder', callback); ipcRenderer.on('selected-folder', callback);
}, },
unregisterOnSelectedFolder: () => {
ipcRenderer.removeAllListeners('selected-folder');
},
selectFile: (extensions = undefined) => { selectFile: (extensions = undefined) => {
ipcRenderer.invoke('select-file', extensions); ipcRenderer.invoke('select-file', extensions);
}, },
onSelectedFile: (callback) => { onSelectedFile: (callback) => {
ipcRenderer.on('selected-file', callback); ipcRenderer.on('selected-file', callback);
}, },
unregisterOnSelectedFile: () => {
ipcRenderer.removeAllListeners('selected-file');
},
isWifiConnected: () => { isWifiConnected: () => {
ipcRenderer.invoke('is-wifi-connected'); ipcRenderer.invoke('is-wifi-connected');
}, },

View file

@ -204,4 +204,31 @@ export class ElectronService {
return this._isAppImage; 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;
}
} }

View file

@ -201,7 +201,7 @@ export class SettingsComponent {
} }
public async chooseMonerodFile(): Promise<void> { public async chooseMonerodFile(): Promise<void> {
const file = await this.selectFile(); const file = await this.electronService.selectFile();
if (file == '') { if (file == '') {
return; return;
@ -213,7 +213,7 @@ export class SettingsComponent {
} }
private async choosePemFile(): Promise<string> { private async choosePemFile(): Promise<string> {
return await this.selectFile(['pem', 'PEM']); return await this.electronService.selectFile(['pem', 'PEM']);
} }
public async selectSslPrivateKey(): Promise<void> { 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> { public async chooseMoneroDownloadPath(): Promise<void> {
const folder = await this.selectFolder(); const folder = await this.electronService.selectFolder();
if (folder == '') if (folder == '')
{ {
@ -285,7 +260,7 @@ export class SettingsComponent {
} }
public async chooseDataDir(): Promise<void> { public async chooseDataDir(): Promise<void> {
const folder = await this.selectFolder(); const folder = await this.electronService.selectFolder();
if (folder == '') { if (folder == '') {
return; return;

View file

@ -29,7 +29,7 @@
<div class="row d-flex justify-content-center"> <div class="row d-flex justify-content-center">
@for(card of cards; track card.header) { @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 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-header"><strong>{{card.header}}</strong></div>
<div class="card-body"> <div class="card-body">

View file

@ -68,9 +68,7 @@ export class VersionComponent implements AfterViewInit {
private createErrorCards(): SimpleBootstrapCard[] { private createErrorCards(): SimpleBootstrapCard[] {
return [ return [
new SimpleBootstrapCard('GUI Version', this.daemonService.getGuiVersion()), new SimpleBootstrapCard('GUI Version', this.daemonService.getGuiVersion())
new SimpleBootstrapCard('Current Monerod version', 'Error', false),
new SimpleBootstrapCard('Latest Monerod version', 'Error', false)
]; ];
} }
@ -103,6 +101,7 @@ export class VersionComponent implements AfterViewInit {
} }
catch(error: any) { catch(error: any) {
console.error(error); console.error(error);
this.cards = this.createErrorCards();
} }
this.loading = false; this.loading = false;
@ -123,17 +122,31 @@ export class VersionComponent implements AfterViewInit {
public async upgrade(): Promise<void> { public async upgrade(): Promise<void> {
if (this.upgrading || this.installing) { if (this.upgrading || this.installing) {
console.warn("Already upgrading"); this.upgradeSuccess = false;
this.upgradeError = `Daemon is already upgrading`;
return; return;
} }
try { 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(); await this.daemonService.upgrade();
this.upgradeError = ''; this.upgradeError = '';
this.upgradeSuccess = true; this.upgradeSuccess = true;
} }
catch(error: any) { catch(error: any) {
console.error(error); console.error(error);
this.upgradeSuccess = false; this.upgradeSuccess = false;
this.upgradeError = `${error}`; this.upgradeError = `${error}`;

View file

@ -100,6 +100,8 @@ declare global {
selectFile: (extensions?: string[]) => void; selectFile: (extensions?: string[]) => void;
onSelectedFolder: (callback: (event: any, path: string) => void) => void; onSelectedFolder: (callback: (event: any, path: string) => void) => void;
onSelectedFile: (callback: (event: any, path: string) => void) => void; onSelectedFile: (callback: (event: any, path: string) => void) => void;
unregisterOnSelectedFile: () => void;
unregisterOnSelectedFolder: () => void;
getOsType: () => void; getOsType: () => void;
gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void; gotOsType: (callback: (event: any, osType: { platform: string, arch: string }) => void) => void;
unregisterGotOsType: () => void; unregisterGotOsType: () => void;