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

@@ -4,7 +4,7 @@ import { join } from 'path'
import { rimraf } from 'rimraf'
import { promisify } from 'util'
import { getSettings } from '../SettingsHandler.ipc'
import { settings } from '../SettingsHandler.ipc'
import { DownloadError } from './ChartDownload'
const readdir = promisify(_readdir)
@@ -17,12 +17,13 @@ interface EventCallback {
type Callbacks = { [E in keyof EventCallback]: EventCallback[E] }
const transferErrors = {
libraryError: () => ({ header: 'Library folder not specified', body: 'Please go to the settings to set your library folder.' }),
readError: (err: NodeJS.ErrnoException) => fsError(err, 'Failed to read file.'),
deleteError: (err: NodeJS.ErrnoException) => fsError(err, 'Failed to delete file.'),
rimrafError: (err: NodeJS.ErrnoException) => fsError(err, 'Failed to delete folder.'),
mvError: (err: NodeJS.ErrnoException) => fsError(
err,
`Failed to move folder to library.${err.code == 'EPERM' ? ' (does the chart already exist?)' : ''}`,
`Failed to move folder to library.${err.code === 'EPERM' ? ' (does the chart already exist?)' : ''}`,
),
}
@@ -34,10 +35,10 @@ export class FileTransfer {
private callbacks = {} as Callbacks
private wasCanceled = false
private destinationFolder: string
private destinationFolder: string | null
private nestedSourceFolder: string // The top-level folder that is copied to the library folder
constructor(private sourceFolder: string, destinationFolderName: string) {
this.destinationFolder = join(getSettings().libraryPath, destinationFolderName)
this.destinationFolder = settings.libraryPath ? join(settings.libraryPath, destinationFolderName) : null
this.nestedSourceFolder = sourceFolder
}
@@ -49,10 +50,14 @@ export class FileTransfer {
}
async beginTransfer() {
this.callbacks.start(this.destinationFolder)
await this.cleanFolder()
if (this.wasCanceled) { return }
this.moveFolder()
if (!this.destinationFolder) {
this.callbacks.error(transferErrors.libraryError(), () => this.beginTransfer())
} else {
this.callbacks.start(this.destinationFolder)
await this.cleanFolder()
if (this.wasCanceled) { return }
this.moveFolder()
}
}
/**
@@ -68,7 +73,7 @@ export class FileTransfer {
}
// Remove nested folders
if (files.length == 1 && !files[0].isFile()) {
if (files.length === 1 && !files[0].isFile()) {
this.nestedSourceFolder = join(this.nestedSourceFolder, files[0].name)
await this.cleanFolder()
return
@@ -76,7 +81,7 @@ export class FileTransfer {
// Delete '__MACOSX' folder
for (const file of files) {
if (!file.isFile() && file.name == '__MACOSX') {
if (!file.isFile() && file.name === '__MACOSX') {
try {
await rimraf(join(this.nestedSourceFolder, file.name))
} catch (err) {
@@ -93,14 +98,18 @@ export class FileTransfer {
* Moves the downloaded chart to the library path.
*/
private moveFolder() {
mv(this.nestedSourceFolder, this.destinationFolder, { mkdirp: true }, err => {
if (err) {
this.callbacks.error(transferErrors.mvError(err), () => this.moveFolder())
} else {
rimraf(this.sourceFolder) // Delete temp folder
this.callbacks.complete()
}
})
if (!this.destinationFolder) {
this.callbacks.error(transferErrors.libraryError(), () => this.moveFolder())
} else {
mv(this.nestedSourceFolder, this.destinationFolder, { mkdirp: true }, err => {
if (err) {
this.callbacks.error(transferErrors.mvError(err), () => this.moveFolder())
} else {
rimraf(this.sourceFolder) // Delete temp folder
this.callbacks.complete()
}
})
}
}
/**