Initial settings, download UI, various bugfixes

This commit is contained in:
Geomitron
2020-02-09 21:15:40 -05:00
parent 89948b118b
commit de39ad4f1e
33 changed files with 1034 additions and 110 deletions

View File

@@ -0,0 +1,20 @@
import { Directive, ElementRef, Input } from '@angular/core'
import * as _ from 'underscore'
@Directive({
selector: '[appProgressBar]'
})
export class ProgressBarDirective {
progress: (percent: number) => void
@Input() set percent(percent: number) {
this.progress(percent)
}
constructor(element: ElementRef) {
const $progressBar = $(element.nativeElement)
this.progress = _.throttle((percent: number) => $progressBar.progress({ percent }), 100)
this.percent = 0
}
}

View File

@@ -1,9 +1,24 @@
import { Injectable } from '@angular/core'
import { Injectable, EventEmitter } from '@angular/core'
import { ElectronService } from './electron.service'
import { Download, NewDownload } from '../../../electron/shared/interfaces/download.interface'
@Injectable({
providedIn: 'root'
})
export class DownloadService {
constructor() { }
private downloadUpdatedEmitter = new EventEmitter<Download>()
constructor(private electronService: ElectronService) { }
addDownload(newDownload: NewDownload) {
this.electronService.receiveIPC('download-updated', result => {
this.downloadUpdatedEmitter.emit(result)
})
this.electronService.sendIPC('add-download', newDownload)
}
onDownloadUpdated(callback: (download: Download) => void) {
this.downloadUpdatedEmitter.subscribe(callback)
}
}

View File

@@ -6,7 +6,7 @@ import { ipcRenderer, webFrame, remote } from 'electron'
import * as childProcess from 'child_process'
import * as fs from 'fs'
import * as util from 'util'
import { IPCEvents } from '../../../electron/shared/IPCHandler'
import { IPCInvokeEvents, IPCEmitEvents } from '../../../electron/shared/IPCHandler'
@Injectable({
providedIn: 'root'
@@ -42,7 +42,27 @@ export class ElectronService {
* @param data The data object to send across IPC.
* @returns A promise that resolves to the output data.
*/
async invoke<E extends keyof IPCEvents>(event: E, data: IPCEvents[E]['input']) {
return this.ipcRenderer.invoke(event, data) as Promise<IPCEvents[E]['output']>
async invoke<E extends keyof IPCInvokeEvents>(event: E, data: IPCInvokeEvents[E]['input']) {
return this.ipcRenderer.invoke(event, data) as Promise<IPCInvokeEvents[E]['output']>
}
/**
* Sends an IPC message to the main process.
* @param event The name of the IPC event to send.
* @param data The data object to send across IPC.
*/
sendIPC<E extends keyof IPCEmitEvents>(event: E, data: IPCEmitEvents[E]) {
this.ipcRenderer.send(event, data)
}
/**
* Receives an IPC message from the main process.
* @param event The name of the IPC event to receive.
* @param callback The data object to receive across IPC.
*/
receiveIPC<E extends keyof IPCEmitEvents>(event: E, callback: (result: IPCEmitEvents[E]) => void) {
this.ipcRenderer.on(event, (_event, ...results) => {
callback(results[0])
})
}
}

View File

@@ -0,0 +1,20 @@
import { Injectable } from '@angular/core'
import { ElectronService } from './electron.service'
import { Settings } from 'src/electron/shared/Settings'
@Injectable({
providedIn: 'root'
})
export class SettingsService {
private settings: Settings
constructor(private electronService: ElectronService) { }
async getSettings() {
if (this.settings == undefined) {
this.settings = await this.electronService.invoke('init-settings', undefined)
}
return this.settings
}
}