mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-08 19:15:09 +00:00
Download video backgrounds setting; improved settings loading
This commit is contained in:
@@ -52,6 +52,7 @@ class GetSettingsHandler implements IPCInvokeHandler<'get-settings'> {
|
||||
// Read/create settings
|
||||
if (await exists(settingsPath)) {
|
||||
settings = JSON.parse(await readFile(settingsPath, 'utf8'))
|
||||
settings = Object.assign(JSON.parse(JSON.stringify(defaultSettings)), settings)
|
||||
} else {
|
||||
await SetSettingsHandler.saveSettings(defaultSettings)
|
||||
settings = defaultSettings
|
||||
|
||||
@@ -9,6 +9,8 @@ import { DriveFile } from 'src/electron/shared/interfaces/songDetails.interface'
|
||||
import { FileTransfer } from './FileTransfer'
|
||||
import * as _rimraf from 'rimraf'
|
||||
import { FilesystemChecker } from './FilesystemChecker'
|
||||
import { getSettings } from '../SettingsHandler.ipc'
|
||||
import { hasVideoExtension } from '../../shared/ElectronUtilFunctions'
|
||||
|
||||
const rimraf = promisify(_rimraf)
|
||||
|
||||
@@ -45,7 +47,7 @@ export class ChartDownload {
|
||||
|
||||
constructor(public versionID: number, private data: NewDownload) {
|
||||
this.updateGUI('', 'Waiting for other downloads to finish...', 'good')
|
||||
this.files = data.driveData.files
|
||||
this.files = this.filterDownloadFiles(data.driveData.files)
|
||||
this.individualFileProgressPortion = 80 / this.files.length
|
||||
if (data.driveData.inChartPack) {
|
||||
this.destinationFolderName = sanitizeFilename(parse(data.driveData.files[0].name).name)
|
||||
@@ -61,6 +63,12 @@ export class ChartDownload {
|
||||
this.callbacks[event] = callback
|
||||
}
|
||||
|
||||
filterDownloadFiles(files: DriveFile[]) {
|
||||
return files.filter(file => {
|
||||
return (file.name != 'ch.dat') && (getSettings().downloadVideos || !hasVideoExtension(file.name))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Retries the last failed step if it is running.
|
||||
*/
|
||||
@@ -135,7 +143,6 @@ export class ChartDownload {
|
||||
|
||||
// DOWNLOAD FILES
|
||||
for (let i = 0; i < this.files.length; i++) {
|
||||
if (this.files[i].name == 'ch.dat') { continue }
|
||||
let wasCanceled = false
|
||||
this.cancelFn = () => { wasCanceled = true }
|
||||
const downloader = await getDownloader(this.files[i].webContentLink, join(this.tempPath, this.files[i].name))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { basename } from 'path'
|
||||
import { basename, parse } from 'path'
|
||||
import { getSettingsHandler } from '../ipc/SettingsHandler.ipc'
|
||||
import { emitIPCEvent } from '../main'
|
||||
import { lower } from './UtilFunctions'
|
||||
|
||||
/**
|
||||
* @returns The relative filepath from the library folder to `absoluteFilepath`.
|
||||
@@ -10,6 +11,13 @@ export function getRelativeFilepath(absoluteFilepath: string) {
|
||||
return basename(settings.libraryPath) + absoluteFilepath.substring(settings.libraryPath.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns `true` if `name` has a valid video file extension.
|
||||
*/
|
||||
export function hasVideoExtension(name: string) {
|
||||
return (['.mp4', '.avi', '.webm', '.ogv', '.mpeg'].includes(parse(lower(name)).ext))
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message in the main BrowserWindow's console.
|
||||
*/
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
* Represents Bridge's user settings.
|
||||
*/
|
||||
export interface Settings {
|
||||
rateLimitDelay: number // Number of seconds to wait between each file download from Google servers
|
||||
theme: string // The name of the currently enabled UI theme
|
||||
libraryPath: string // The path to the user's library
|
||||
rateLimitDelay: number // Number of seconds to wait between each file download from Google servers
|
||||
downloadVideos: boolean // If background videos should be downloaded
|
||||
theme: string // The name of the currently enabled UI theme
|
||||
libraryPath: string // The path to the user's library
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,7 @@ export interface Settings {
|
||||
*/
|
||||
export const defaultSettings: Settings = {
|
||||
rateLimitDelay: 31,
|
||||
downloadVideos: true,
|
||||
theme: 'Default',
|
||||
libraryPath: undefined
|
||||
}
|
||||
@@ -29,6 +29,13 @@ export function sanitizeFilename(filename: string): string {
|
||||
return (newFilename == '' ? randomBytes(5).toString('hex') : newFilename)
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns `text` converted to lower case.
|
||||
*/
|
||||
export function lower(text: string) {
|
||||
return text.toLowerCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `val` from the range (`fromStart`, `fromEnd`) to the range (`toStart`, `toEnd`).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user