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

View file

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

View file

@ -12,23 +12,25 @@ export class SettingsManager {
await this.#init() await this.#init()
} }
async #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() //console.log(settings)
this.settings = JSON.parse(this.settings.toString()) if (!settings) settings = await this.#makeNewSettingsFile()
this.settings = JSON.parse(settings.toString())
this.currentSetting = this.settings.presets[this.settings.currentSetting] this.currentSetting = this.settings.presets[this.settings.currentSetting]
} }
async #getSettings() { async #getSettings() {
return new Promise((resolve, reject) => { 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) resolve(data)
reject(err)
}) })
}) })
} }
async #makeNewSettingsFile() { async #makeNewSettingsFile() {
const settings = ` const settings = `
{ {

View file

@ -87,31 +87,29 @@ export class UI {
} }
this.multibar.stop() this.multibar.stop()
fs.rm("ffmpeg2pass-0.log", (error) => { error }) fs.rm("ffmpeg2pass-0.log", (error) => { error })
console.clear()
this.term.bold.green("Finished!\n") this.term.bold.green("Finished!\n")
this.term.grey("press enter to exit...\n") this.term.grey("press enter to exit...\n")
this.term.inputField(() => { process.exit() }) this.term.inputField(() => { process.exit() })
} }
async startMenu() { async startMenu(settings) {
await this.#menu() await this.#menu()
} }
async #menu() { async #menu() {
console.clear()
let menu = [] let menu = []
for (let i = 0; i < settings.presets.length; i++) { for (let i = 0; i < this.settings.presets.length; i++) {
menu.push(`${i}. ${settings.presets[i].name}`) menu.push(`${i}. ${this.settings.presets[i].name}`)
} }
this.term("How to convert: [app] [optional: -preset {Index}] [filename.extension(s)]\n") this.term("How to convert: [app] [optional: -preset {Index}] [filename.extension(s)]\n")
this.term("examples: \n") this.term("examples: \n")
this.term.italic(" npx DMC -preset 0 file.mp3 file4.mov img.jpg\n") this.term.italic(" 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.exe file34.wav file2.mp3\n\n")
this.term.yellow("Hello! This menu is for selecting performance/speed preset.\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) => { this.term.singleColumnMenu(menu, (error, response) => {
currentSetting = response.selectedIndex this.settings.currentSetting = response.selectedIndex
fs.writeFileSync("settings.json", JSON.stringify(settings)) fs.writeFileSync("settings.json", JSON.stringify(this.settings))
this.term.green("\n Using").green.bold(` ${settings.presets[settings.currentSetting].name} `).green("setting\n") 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.grey("Press enter to exit...")
this.term.inputField(() => { process.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", "description": "helps free discord users to send any media(image, video, audio) and not get limited by discords 8mb file limit",
"main": "index.js", "main": "index.js",
"bin": { "bin": {
"DMC": "./bin/index.js" "DMC": "node bin/index.js"
}, },
"type": "module", "type": "module",
"scripts": { "scripts": {