mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-09 03:25:09 +00:00
Download Selected button, Various small improvements
This commit is contained in:
11
src/electron/shared/ElectronUtilFunctions.ts
Normal file
11
src/electron/shared/ElectronUtilFunctions.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import InitSettingsHandler from '../ipc/InitSettingsHandler.ipc'
|
||||
import { basename } from 'path'
|
||||
|
||||
/**
|
||||
* @param absoluteFilepath The absolute filepath to a folder
|
||||
* @returns The relative filepath from the scanned folder to <absoluteFilepath>
|
||||
*/
|
||||
export async function getRelativeFilepath(absoluteFilepath: string) {
|
||||
const settings = await InitSettingsHandler.getSettings()
|
||||
return basename(settings.libraryPath) + absoluteFilepath.substring(settings.libraryPath.length)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { red } from 'cli-color'
|
||||
import { getRelativeFilepath } from './UtilFunctions'
|
||||
import { getRelativeFilepath } from './ElectronUtilFunctions'
|
||||
|
||||
// TODO: add better error reporting (through the UI)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Download, NewDownload, DownloadProgress } from './interfaces/download.i
|
||||
import { DownloadHandler } from '../ipc/download/DownloadHandler'
|
||||
import { Settings } from './Settings'
|
||||
import InitSettingsHandler from '../ipc/InitSettingsHandler.ipc'
|
||||
import BatchSongDetailsHandler from '../ipc/BatchSongDetailsHandler.ipc'
|
||||
|
||||
/**
|
||||
* To add a new IPC listener:
|
||||
@@ -21,6 +22,7 @@ export function getIPCInvokeHandlers(): IPCInvokeHandler<keyof IPCInvokeEvents>[
|
||||
new InitSettingsHandler(),
|
||||
new SearchHandler(),
|
||||
new SongDetailsHandler(),
|
||||
new BatchSongDetailsHandler(),
|
||||
new AlbumArtHandler()
|
||||
]
|
||||
}
|
||||
@@ -42,6 +44,10 @@ export type IPCInvokeEvents = {
|
||||
input: SongResult['id']
|
||||
output: VersionResult[]
|
||||
}
|
||||
'batch-song-details': {
|
||||
input: number[]
|
||||
output: VersionResult[]
|
||||
}
|
||||
}
|
||||
|
||||
export interface IPCInvokeHandler<E extends keyof IPCInvokeEvents> {
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
let sanitize = require('sanitize-filename')
|
||||
|
||||
/**
|
||||
* @param absoluteFilepath The absolute filepath to a folder
|
||||
* @returns The relative filepath from the scanned folder to <absoluteFilepath>
|
||||
*/
|
||||
export function getRelativeFilepath(absoluteFilepath: string) {
|
||||
// TODO: figure out how these functions should use <settings> (like an async initialization script that
|
||||
// loads everything and connects to the database, etc...)
|
||||
// return basename(scanSettings.songsFolderPath) + absoluteFilepath.substring(scanSettings.songsFolderPath.length)
|
||||
return absoluteFilepath
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns A random UUID
|
||||
*/
|
||||
@@ -53,4 +42,23 @@ export function sanitizeFilename(filename: string): string {
|
||||
*/
|
||||
export function interpolate(val: number, fromA: number, fromB: number, toA: number, toB: number) {
|
||||
return ((val - fromA) / (fromB - fromA)) * (toB - toA) + toA
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits <objectList> into multiple arrays, grouping by matching <key> values.
|
||||
* @param objectList A list of objects.
|
||||
* @param key A key from the list of objects.
|
||||
*/
|
||||
export function groupBy<T>(objectList: T[], key: keyof T) {
|
||||
const results: T[][] = []
|
||||
for (const object of objectList) {
|
||||
const matchingGroup = results.find(result => result[0][key] == object[key])
|
||||
if (matchingGroup != undefined) {
|
||||
matchingGroup.push(object)
|
||||
} else {
|
||||
results.push([object])
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
Reference in New Issue
Block a user