Restructure; use DaisyUI

This commit is contained in:
Geomitron
2023-11-28 19:50:45 -06:00
parent 49c3f38f99
commit 2eef4d0bee
727 changed files with 1283 additions and 298840 deletions

View File

@@ -1,8 +1,7 @@
import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
import { CheckboxDirective } from 'src/app/core/directives/checkbox.directive'
import { ElectronService } from 'src/app/core/services/electron.service'
import { SettingsService } from 'src/app/core/services/settings.service'
import { CheckboxDirective } from 'src-angular/app/core/directives/checkbox.directive'
import { SettingsService } from 'src-angular/app/core/services/settings.service'
@Component({
selector: 'app-settings',
@@ -13,8 +12,7 @@ export class SettingsComponent implements OnInit, AfterViewInit {
@ViewChild('themeDropdown', { static: true }) themeDropdown: ElementRef
@ViewChild(CheckboxDirective, { static: true }) videoCheckbox: CheckboxDirective
cacheSize = 'Calculating...'
updateAvailable = false
updateAvailable: boolean | null = false
loginClicked = false
downloadUpdateText = 'Update available'
retryUpdateText = 'Failed to check for update'
@@ -25,74 +23,66 @@ export class SettingsComponent implements OnInit, AfterViewInit {
constructor(
public settingsService: SettingsService,
private electronService: ElectronService,
private ref: ChangeDetectorRef
) { }
async ngOnInit() {
this.electronService.receiveIPC('update-available', result => {
this.updateAvailable = result != null
window.electron.on.updateAvailable(result => {
this.updateAvailable = result !== null
this.updateRetrying = false
if (this.updateAvailable) {
if (result !== null) {
this.downloadUpdateText = `Update available (${result.version})`
}
this.ref.detectChanges()
})
this.electronService.receiveIPC('update-error', (err: Error) => {
window.electron.on.updateError(err => {
console.log(err)
this.updateAvailable = null
this.updateRetrying = false
this.retryUpdateText = `Failed to check for update: ${err.message}`
this.retryUpdateText = `Failed to check for update: ${err}`
this.ref.detectChanges()
})
this.electronService.invoke('get-current-version', undefined).then(version => {
window.electron.invoke.getCurrentVersion().then(version => {
this.currentVersion = `v${version}`
this.ref.detectChanges()
})
this.electronService.invoke('get-update-available', undefined).then(isAvailable => {
window.electron.invoke.getUpdateAvailable().then(isAvailable => {
this.updateAvailable = isAvailable
this.ref.detectChanges()
})
const cacheSize = await this.settingsService.getCacheSize()
this.cacheSize = Math.round(cacheSize / 1000000) + ' MB'
}
ngAfterViewInit() {
$(this.themeDropdown.nativeElement).dropdown({
onChange: (_value: string, text: string) => {
this.settingsService.theme = text
},
})
// TODO
// $(this.themeDropdown.nativeElement).dropdown({
// onChange: (_value: string, text: string) => {
// this.settingsService.theme = text
// },
// })
this.videoCheckbox.check(this.settingsService.downloadVideos)
}
async clearCache() {
this.cacheSize = 'Please wait...'
await this.settingsService.clearCache()
this.cacheSize = 'Cleared!'
}
async downloadVideos(isChecked: boolean) {
this.settingsService.downloadVideos = isChecked
}
async getLibraryDirectory() {
const result = await this.electronService.showOpenDialog({
const result = await window.electron.invoke.showOpenDialog({
title: 'Choose library folder',
buttonLabel: 'This is where my charts are!',
defaultPath: this.settingsService.libraryDirectory || '',
properties: ['openDirectory'],
})
if (result.canceled == false) {
if (result.canceled === false) {
this.settingsService.libraryDirectory = result.filePaths[0]
}
}
openLibraryDirectory() {
this.electronService.openFolder(this.settingsService.libraryDirectory)
if (this.settingsService.libraryDirectory) {
window.electron.emit.showFolder(this.settingsService.libraryDirectory)
}
}
changeRateLimit(event: Event) {
@@ -102,16 +92,16 @@ export class SettingsComponent implements OnInit, AfterViewInit {
downloadUpdate() {
if (this.updateDownloaded) {
this.electronService.sendIPC('quit-and-install', undefined)
window.electron.emit.quitAndInstall()
} else if (!this.updateDownloading) {
this.updateDownloading = true
this.electronService.sendIPC('download-update', undefined)
window.electron.emit.downloadUpdate()
this.downloadUpdateText = 'Downloading... (0%)'
this.electronService.receiveIPC('update-progress', result => {
window.electron.on.updateProgress(result => {
this.downloadUpdateText = `Downloading... (${result.percent.toFixed(0)}%)`
this.ref.detectChanges()
})
this.electronService.receiveIPC('update-downloaded', () => {
window.electron.on.updateDownloaded(() => {
this.downloadUpdateText = 'Quit and install update'
this.updateDownloaded = true
this.ref.detectChanges()
@@ -120,21 +110,15 @@ export class SettingsComponent implements OnInit, AfterViewInit {
}
retryUpdate() {
if (this.updateRetrying == false) {
if (this.updateRetrying === false) {
this.updateRetrying = true
this.retryUpdateText = 'Retrying...'
this.ref.detectChanges()
this.electronService.sendIPC('retry-update', undefined)
window.electron.emit.retryUpdate()
}
}
toggleDevTools() {
const toolsOpened = this.electronService.currentWindow.webContents.isDevToolsOpened()
if (toolsOpened) {
this.electronService.currentWindow.webContents.closeDevTools()
} else {
this.electronService.currentWindow.webContents.openDevTools()
}
window.electron.emit.toggleDevTools()
}
}