GrassClipper/resources/js/options.js

127 lines
3.3 KiB
JavaScript
Raw Normal View History

/**
* Toggle the killswitch script
*/
async function toggleKillSwitch() {
2022-05-03 05:48:03 +00:00
const killSwitch = document.querySelector('#killswitchOption')
const config = await getCfg()
2022-05-03 05:48:03 +00:00
config.enableKillswitch = killSwitch.checked
2022-05-03 05:48:03 +00:00
Neutralino.storage.setData('config', JSON.stringify(config))
}
/**
* Toggles the server launching panel
*/
async function toggleServerLaunchSection() {
2022-05-03 05:48:03 +00:00
const config = await getCfg()
2022-05-03 05:48:03 +00:00
displayServerLaunchSection()
2022-05-03 05:48:03 +00:00
// Save setting
config.serverLaunchPanel = !config.serverLaunchPanel
Neutralino.storage.setData('config', JSON.stringify(config))
2022-05-06 01:16:15 +00:00
// Show a dialog for those who may want to open the downloads section
if (config.serverLaunchPanel && !config.serverFolder) {
closeSettings()
openDialog(
2022-05-06 03:25:39 +00:00
localeObj.serverEnableDialogTitle || 'You found the Grasscutter server launcher!',
localeObj.serverEnableDialogText || 'If you do not have an existing Grasscutter installation to set, would you like to download a build?',
2022-05-06 01:16:15 +00:00
true,
openDownloads
)
}
}
/**
* Get all languages for the language selector
*/
async function getLanguages() {
2022-05-03 05:48:03 +00:00
const languageFiles = (await filesystem.readDirectory(`${NL_CWD}/languages`)).filter(file => file.entry.endsWith('.json'))
const config = await getCfg()
2022-05-03 05:48:03 +00:00
// Clear language options
const languageSelect = document.querySelector('#languageSelect')
languageSelect.innerHTML = ''
2022-05-03 05:48:03 +00:00
// Load all languages as options
for (const file of languageFiles) {
const fullLanguageName = JSON.parse(await filesystem.readFile(`${NL_CWD}/languages/${file.entry}`)).fullLangName
const lang = file.entry.split('.json')[0]
2022-05-03 05:48:03 +00:00
const option = document.createElement('option')
option.value = lang
option.innerHTML = fullLanguageName
2022-05-03 05:48:03 +00:00
// Set language selected to config language
if (lang === config.language) {
option.selected = true
2022-05-03 05:44:57 +00:00
}
2022-05-03 05:48:03 +00:00
document.querySelector('#languageSelect').appendChild(option)
}
}
/**
* Save lang, refresh to apply
*
* @param {DOMElement} elm
*/
async function handleLanguageChange(elm) {
2022-05-03 05:48:03 +00:00
const list = elm
const config = await getCfg()
2022-05-03 05:48:03 +00:00
// Set language in config
config.language = list.value
Neutralino.storage.setData('config', JSON.stringify(config))
2022-05-03 05:48:03 +00:00
// Force refresh of application, no need for restart!
window.location.reload()
}
2022-04-24 23:17:23 +00:00
/**
* Toggle the use of HTTPS
*/
2022-05-03 05:44:57 +00:00
async function toggleHttps() {
2022-05-03 05:48:03 +00:00
const httpsCheckbox = document.querySelector('#httpsOption')
const config = await getCfg()
2022-04-24 23:17:23 +00:00
2022-05-03 05:48:03 +00:00
config.useHttps = httpsCheckbox.checked
2022-04-24 23:17:23 +00:00
2022-05-03 05:48:03 +00:00
Neutralino.storage.setData('config', JSON.stringify(config))
2022-04-24 23:17:23 +00:00
}
/**
* Add the current value of the IP input to the favorites list
* OR
* Remove the current value of the IP input from the favorites list
*/
2022-05-03 05:44:57 +00:00
async function setFavorite() {
2022-05-03 05:48:03 +00:00
const ip = document.querySelector('#ip').value
const port = document.querySelector('#port').value || '443'
const ipArr = await getFavIps()
2022-05-03 05:48:03 +00:00
const addr = `${ip}:${port}`
2022-04-24 23:06:25 +00:00
2022-05-03 05:48:03 +00:00
// Set star icon
const star = document.querySelector('#star')
2022-05-03 05:48:03 +00:00
if (star.src.includes('filled') && ip) {
star.src = 'icons/star_empty.svg'
2022-05-03 05:48:03 +00:00
// remove from list
ipArr.splice(ipArr.indexOf(addr), 1)
} else {
star.src = 'icons/star_filled.svg'
2022-05-03 05:48:03 +00:00
// add to list
if (ip && !ipArr.includes(addr)) {
ipArr.push(addr)
}
2022-05-03 05:48:03 +00:00
}
2022-05-03 05:48:03 +00:00
Neutralino.storage.setData('favorites', JSON.stringify(ipArr))
}