Clickable folder link after download

This commit is contained in:
Geomitron
2020-02-12 10:56:32 -05:00
parent 7d4d339018
commit 6c26c98468
7 changed files with 28 additions and 5 deletions

View File

@@ -20,7 +20,10 @@
Download Anyway
</button>
<div class="header">{{download.header}}</div>
<div class="description">{{download.description}}</div>
<div *ngIf="download.type != 'done'" class="description">{{download.description}}</div>
<div *ngIf="download.type == 'done'" class="description">
<a (click)="openFolder(download.description)">{{download.description}}</a>
</div>
<div appProgressBar [percent]="download.percent" class="ui progress">
<div class="bar">
<div class="progress"></div>

View File

@@ -1,6 +1,7 @@
import { Component, ChangeDetectorRef } from '@angular/core'
import { DownloadProgress } from '../../../../../electron/shared/interfaces/download.interface'
import { DownloadService } from '../../../../core/services/download.service'
import { ElectronService } from 'src/app/core/services/electron.service'
@Component({
selector: 'app-downloads-modal',
@@ -11,7 +12,7 @@ export class DownloadsModalComponent {
downloads: DownloadProgress[] = []
constructor(private downloadService: DownloadService, ref: ChangeDetectorRef) {
constructor(private electronService: ElectronService, private downloadService: DownloadService, ref: ChangeDetectorRef) {
downloadService.onDownloadUpdated(download => {
const index = this.downloads.findIndex(thisDownload => thisDownload.versionID == download.versionID)
if (index == -1) {
@@ -45,8 +46,13 @@ export class DownloadsModalComponent {
getBackgroundColor(download: DownloadProgress) {
switch(download.type) {
case 'good': return 'unset'
case 'done': return 'unset'
case 'warning': return 'yellow'
case 'error': return 'indianred'
}
}
openFolder(filepath: string) {
this.electronService.sendIPC('open-folder', filepath)
}
}

View File

@@ -26,6 +26,7 @@ export class DownloadService {
}
addDownload(versionID: number, newDownload: NewDownload) {
if (this.downloads.findIndex(download => download.versionID == versionID) != -1) { return } // Don't download something twice
this.electronService.receiveIPC('download-updated', result => {
this.downloadUpdatedEmitter.emit(result)

View File

@@ -0,0 +1,10 @@
import { IPCEmitHandler } from '../shared/IPCHandler'
import { shell } from 'electron'
export default class OpenFolderHandler implements IPCEmitHandler<'open-folder'> {
event: 'open-folder' = 'open-folder'
async handler(filepath: string) {
shell.showItemInFolder(filepath)
}
}

View File

@@ -161,7 +161,7 @@ export class DownloadHandler implements IPCEmitHandler<'download'> {
download.header = `Download complete.`
download.description = filepath
download.percent = 100
download.type = 'good'
download.type = 'done'
emitIPCEvent('download-updated', download)
})

View File

@@ -8,6 +8,7 @@ import { DownloadHandler } from '../ipc/download/DownloadHandler'
import { Settings } from './Settings'
import InitSettingsHandler from '../ipc/InitSettingsHandler.ipc'
import BatchSongDetailsHandler from '../ipc/BatchSongDetailsHandler.ipc'
import OpenFolderHandler from '../ipc/OpenFolderHandler.ipc'
/**
* To add a new IPC listener:
@@ -57,13 +58,15 @@ export interface IPCInvokeHandler<E extends keyof IPCInvokeEvents> {
export function getIPCEmitHandlers(): IPCEmitHandler<keyof IPCEmitEvents>[]{
return [
new DownloadHandler()
new DownloadHandler(),
new OpenFolderHandler()
]
}
export type IPCEmitEvents = {
'download': Download
'download-updated': DownloadProgress
'open-folder': string
}
export interface IPCEmitHandler<E extends keyof IPCEmitEvents> {

View File

@@ -23,5 +23,5 @@ export interface DownloadProgress {
header: string
description: string
percent: number
type: 'good' | 'warning' | 'error' | 'cancel'
type: 'good' | 'warning' | 'error' | 'cancel' | 'done'
}