mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 22:29:38 +00:00
Various refactoring
This commit is contained in:
@@ -26,19 +26,20 @@ 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)
|
||||
if (this.downloads.findIndex(download => download.versionID == versionID) == -1) { // Don't download something twice
|
||||
this.electronService.receiveIPC('download-updated', result => {
|
||||
this.downloadUpdatedEmitter.emit(result)
|
||||
|
||||
// Update <this.downloads> with result
|
||||
const thisDownloadIndex = this.downloads.findIndex(download => download.versionID == result.versionID)
|
||||
if (thisDownloadIndex == -1) {
|
||||
this.downloads.push(result)
|
||||
} else {
|
||||
this.downloads[thisDownloadIndex] = result
|
||||
}
|
||||
})
|
||||
this.electronService.sendIPC('download', { action: 'add', versionID, data: newDownload })
|
||||
// Update <this.downloads> with result
|
||||
const thisDownloadIndex = this.downloads.findIndex(download => download.versionID == result.versionID)
|
||||
if (thisDownloadIndex == -1) {
|
||||
this.downloads.push(result)
|
||||
} else {
|
||||
this.downloads[thisDownloadIndex] = result
|
||||
}
|
||||
})
|
||||
this.electronService.sendIPC('download', { action: 'add', versionID, data: newDownload })
|
||||
}
|
||||
}
|
||||
|
||||
onDownloadUpdated(callback: (download: DownloadProgress) => void) {
|
||||
|
||||
@@ -11,21 +11,25 @@ export class SettingsService {
|
||||
private settings: Settings
|
||||
private currentThemeLink: HTMLLinkElement
|
||||
|
||||
constructor(private electronService: ElectronService) { }
|
||||
constructor(private electronService: ElectronService) {
|
||||
this.getSettings() // Should resolve immediately because GetSettingsHandler returns a value, not a promise
|
||||
console.log(`QUICKLY RESOLVED SETTINGS: ${this.settings}`)
|
||||
}
|
||||
|
||||
async getSettings() {
|
||||
if (this.settings == undefined) {
|
||||
this.settings = await this.electronService.invoke('init-settings', undefined)
|
||||
this.settings = await this.electronService.invoke('get-settings', undefined)
|
||||
}
|
||||
return this.settings
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
if (this.settings != undefined) {
|
||||
this.electronService.sendIPC('update-settings', this.settings)
|
||||
this.electronService.sendIPC('set-settings', this.settings)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: research how to make theme changes with fomantic UI
|
||||
changeTheme(theme: string) {
|
||||
if (this.currentThemeLink != undefined) this.currentThemeLink.remove()
|
||||
if (theme == 'Default') { return }
|
||||
@@ -40,12 +44,14 @@ export class SettingsService {
|
||||
async getCacheSize() {
|
||||
return this.electronService.defaultSession.getCacheSize()
|
||||
}
|
||||
|
||||
|
||||
async clearCache() {
|
||||
this.saveSettings()
|
||||
return this.electronService.defaultSession.clearCache()
|
||||
}
|
||||
|
||||
// Individual getters/setters
|
||||
// TODO: remove the undefined checks if the constructor gets the settings every time
|
||||
get libraryDirectory() {
|
||||
return this.settings == undefined ? '' : this.settings.libraryPath
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user