fix settings loading

This commit is contained in:
Djkato 2022-05-04 13:09:33 +02:00
parent 57fdf245e1
commit 55c12e920a
5 changed files with 22 additions and 22 deletions

View file

@ -11,13 +11,12 @@ let resolve = path.resolve
let term = termkit.terminal
const ui = new UI(settings.settings, settings.currentSetting)
/**
* TODO : Adapt audio quality as well to accomodate long videos(Currently 5m is too much)
* FIND A WAY TO COMPILE THIS:..
*/
const inputList = process.argv.slice(2)
const inputList = process.argv//.slice()
//if launched without params
if (!inputList[0]) {
ui.startMenu() //stops program here
@ -27,6 +26,7 @@ if (!inputList[0]) {
let filePaths = [], fileNames = [], fileTypes = []
let presetIndexArg = undefined
//if preset argument go through list from 2 and add argument
console.log(inputList)
if (inputList[0] == "-preset") {
presetIndexArg = inputList[1]

View file

@ -3,7 +3,7 @@ const FileHound = require('filehound')
let exec = child_process.exec
let command = "npm run start"
let command = "npm run start -preset 4"
let testFiles = FileHound.create()
.path("testing ground")
.findSync()

View file

@ -12,23 +12,25 @@ export class SettingsManager {
await this.#init()
}
async #init() {
this.settings = await this.#getSettings().catch(async (err) => {
this.settings = undefined
let settings = await this.#getSettings().catch(async (err) => {
settings = undefined
})
if (!this.settings) this.settings = await this.#makeNewSettingsFile()
this.settings = JSON.parse(this.settings.toString())
//console.log(settings)
if (!settings) settings = await this.#makeNewSettingsFile()
this.settings = JSON.parse(settings.toString())
this.currentSetting = this.settings.presets[this.settings.currentSetting]
}
async #getSettings() {
return new Promise((resolve, reject) => {
getSettings = fs.readFile("settings.json", (err, data) => {
const getSettings = fs.readFile("settings.json", (err, data) => {
if (err) reject(err)
resolve(data)
reject(err)
})
})
}
async #makeNewSettingsFile() {
const settings = `
{

View file

@ -87,31 +87,29 @@ export class UI {
}
this.multibar.stop()
fs.rm("ffmpeg2pass-0.log", (error) => { error })
console.clear()
this.term.bold.green("Finished!\n")
this.term.grey("press enter to exit...\n")
this.term.inputField(() => { process.exit() })
}
async startMenu() {
async startMenu(settings) {
await this.#menu()
}
async #menu() {
console.clear()
let menu = []
for (let i = 0; i < settings.presets.length; i++) {
menu.push(`${i}. ${settings.presets[i].name}`)
for (let i = 0; i < this.settings.presets.length; i++) {
menu.push(`${i}. ${this.settings.presets[i].name}`)
}
this.term("How to convert: [app] [optional: -preset {Index}] [filename.extension(s)]\n")
this.term("examples: \n")
this.term.italic(" npx DMC -preset 0 file.mp3 file4.mov img.jpg\n")
this.term.italic(" DMC.exe -preset 2 file34.wav file2.mp3\n\n")
this.term.italic(" DMC -preset 0 file.mp3 file4.mov img.jpg\n")
this.term.italic(" DMC.exe file34.wav file2.mp3\n\n")
this.term.yellow("Hello! This menu is for selecting performance/speed preset.\n")
this.term.yellow("Currently using ").bgMagenta(`"${settings.presets[settings.currentSetting].name}"`).yellow(" preset")
this.term.yellow("Currently using ").bgMagenta(`"${this.settings.presets[this.settings.currentSetting].name}"`).yellow(" preset")
this.term.singleColumnMenu(menu, (error, response) => {
currentSetting = response.selectedIndex
fs.writeFileSync("settings.json", JSON.stringify(settings))
this.term.green("\n Using").green.bold(` ${settings.presets[settings.currentSetting].name} `).green("setting\n")
this.settings.currentSetting = response.selectedIndex
fs.writeFileSync("settings.json", JSON.stringify(this.settings))
this.term.green("\n Using").green.bold(` ${this.settings.presets[this.settings.currentSetting].name} `).green("setting\n")
this.term.grey("Press enter to exit...")
this.term.inputField(() => { process.exit() })
})

View file

@ -4,7 +4,7 @@
"description": "helps free discord users to send any media(image, video, audio) and not get limited by discords 8mb file limit",
"main": "index.js",
"bin": {
"DMC": "./bin/index.js"
"DMC": "node bin/index.js"
},
"type": "module",
"scripts": {