generated from maximegris/angular-electron
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d066b7c
commit f9d8789
Showing
10 changed files
with
329 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 46 additions & 23 deletions
69
src/app/core/services/monero-installer/monero-installer.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,59 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ElectronService } from '../electron/electron.service'; | ||
import { Injectable, NgZone } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class MoneroInstallerService { | ||
constructor(private electronService: ElectronService) {} | ||
|
||
public downloadMonero(downloadUrl: string, destination: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
if (this.electronService.isElectron) { | ||
this.electronService.ipcRenderer.invoke('download-monero', downloadUrl, destination) | ||
.then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
|
||
this.electronService.ipcRenderer.on('download-progress', (event, { progress, status }) => { | ||
console.log(`Progress: ${progress}% - ${status}`); | ||
// Qui puoi aggiornare lo stato di progresso nel tuo componente | ||
}); | ||
} | ||
else { | ||
const wdw = (window as any); | ||
private _upgrading: boolean = false; | ||
private _progress: { progress: number, status: string } = { progress: 0, status: 'Starting upgrade' } | ||
|
||
public get upgrading(): boolean { | ||
return this._upgrading; | ||
} | ||
|
||
public get progress(): { progress: number, status: string } { | ||
return this._progress; | ||
} | ||
|
||
constructor(private ngZone: NgZone) {} | ||
|
||
public async downloadMonero(downloadUrl: string, destination: string): Promise<string> { | ||
this._upgrading = true; | ||
|
||
try { | ||
const result = await new Promise<string>((resolve, reject) => { | ||
const wdw = (window as any); | ||
|
||
if (wdw.electronAPI && wdw.electronAPI.onDownloadProgress && wdw.electronAPI.downloadMonerod) { | ||
wdw.electronAPI.onDownloadProgress((event: any, progress: any) => { | ||
console.log(`Download progress: ${progress}`); | ||
}); | ||
wdw.electronAPI.onDownloadProgress((event: any, progress: { progress: number, status: string }) => { | ||
//console.log(`${progress.progress.toFixed(2)} % ${progress.status}`); | ||
this.ngZone.run(() => { | ||
this._progress = progress; | ||
}); | ||
|
||
if (progress.status.includes('Error')) { | ||
reject(progress.status); | ||
} | ||
|
||
if (progress.progress == 200) { | ||
resolve(progress.status); | ||
} | ||
|
||
}); | ||
|
||
wdw.electronAPI.downloadMonerod(downloadUrl, destination); | ||
} | ||
} | ||
}); | ||
|
||
this._upgrading = false; | ||
return result; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
this._upgrading = false; | ||
|
||
throw error; | ||
} | ||
|
||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.