From 6c26c98468c829f68f631043dbc801d74d788b75 Mon Sep 17 00:00:00 2001 From: Geomitron <22552797+Geomitron@users.noreply.github.com> Date: Wed, 12 Feb 2020 10:56:32 -0500 Subject: [PATCH] Clickable folder link after download --- .../downloads-modal/downloads-modal.component.html | 5 ++++- .../downloads-modal/downloads-modal.component.ts | 8 +++++++- src/app/core/services/download.service.ts | 1 + src/electron/ipc/OpenFolderHandler.ipc.ts | 10 ++++++++++ src/electron/ipc/download/DownloadHandler.ts | 2 +- src/electron/shared/IPCHandler.ts | 5 ++++- src/electron/shared/interfaces/download.interface.ts | 2 +- 7 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/electron/ipc/OpenFolderHandler.ipc.ts diff --git a/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.html b/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.html index cdf28f8..0fb88a0 100644 --- a/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.html +++ b/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.html @@ -20,7 +20,10 @@ Download Anyway
{{download.header}}
-
{{download.description}}
+
{{download.description}}
+
+ {{download.description}} +
diff --git a/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.ts b/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.ts index 888d6d1..d626629 100644 --- a/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.ts +++ b/src/app/components/browse/status-bar/downloads-modal/downloads-modal.component.ts @@ -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) + } } \ No newline at end of file diff --git a/src/app/core/services/download.service.ts b/src/app/core/services/download.service.ts index 3e1b920..d3e5950 100644 --- a/src/app/core/services/download.service.ts +++ b/src/app/core/services/download.service.ts @@ -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) diff --git a/src/electron/ipc/OpenFolderHandler.ipc.ts b/src/electron/ipc/OpenFolderHandler.ipc.ts new file mode 100644 index 0000000..ee205e5 --- /dev/null +++ b/src/electron/ipc/OpenFolderHandler.ipc.ts @@ -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) + } +} \ No newline at end of file diff --git a/src/electron/ipc/download/DownloadHandler.ts b/src/electron/ipc/download/DownloadHandler.ts index 46d1b44..4e42f1c 100644 --- a/src/electron/ipc/download/DownloadHandler.ts +++ b/src/electron/ipc/download/DownloadHandler.ts @@ -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) }) diff --git a/src/electron/shared/IPCHandler.ts b/src/electron/shared/IPCHandler.ts index 155475f..ccc3965 100644 --- a/src/electron/shared/IPCHandler.ts +++ b/src/electron/shared/IPCHandler.ts @@ -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 { export function getIPCEmitHandlers(): IPCEmitHandler[]{ return [ - new DownloadHandler() + new DownloadHandler(), + new OpenFolderHandler() ] } export type IPCEmitEvents = { 'download': Download 'download-updated': DownloadProgress + 'open-folder': string } export interface IPCEmitHandler { diff --git a/src/electron/shared/interfaces/download.interface.ts b/src/electron/shared/interfaces/download.interface.ts index 38e7547..9334233 100644 --- a/src/electron/shared/interfaces/download.interface.ts +++ b/src/electron/shared/interfaces/download.interface.ts @@ -23,5 +23,5 @@ export interface DownloadProgress { header: string description: string percent: number - type: 'good' | 'warning' | 'error' | 'cancel' + type: 'good' | 'warning' | 'error' | 'cancel' | 'done' } \ No newline at end of file