favorites list and tracking

This commit is contained in:
SpikeHD 2022-04-20 22:43:32 -07:00
parent 48df224b74
commit 25a3680caf
2 changed files with 52 additions and 4 deletions

View File

@ -27,8 +27,8 @@
<div id="secondHalf">
<div id="secondControlContainer">
<div id="serverInput">
<input type="text" id="ip" placeholder="IP Address" />
<img src="icons/star_empty.svg" id="star" />
<input type="text" id="ip" placeholder="IP Address" oninput="handleFavoriteInput()"/>
<img src="icons/star_empty.svg" id="star" onclick="setFavorite()" />
</div>
<button class="playBtn" id="playPrivate" onclick="launchPrivate()">Play Private</button>
</div>

View File

@ -5,6 +5,7 @@ document.addEventListener('DOMContentLoaded', async () => {
displayGenshinFolder();
const config = await getCfg()
const ipArr = await getFavIps()
if (!config.genshinImpactFolder) {
handleGenshinFolderNotSet()
@ -12,8 +13,23 @@ document.addEventListener('DOMContentLoaded', async () => {
// Set last connect
document.querySelector('#ip').value = config.lastConnect
if (ipArr.includes(config.lastConnect)) {
document.querySelector('#star').src = 'icons/star_filled.svg'
}
})
async function getFavIps() {
const ipStr = await Neutralino.storage.getData('favorites').catch(e => {
// The data isn't set, so this is our first time opening
Neutralino.storage.setData('favorites', JSON.stringify([]))
})
const ipArr = ipStr ? JSON.parse(ipStr) : []
return ipArr
}
async function getCfg() {
const cfgStr = await Neutralino.storage.getData('config').catch(e => {
// The data isn't set, so this is our first time opening
@ -126,7 +142,39 @@ async function setBackgroundImage() {
}
async function handleFavoriteInput() {
console.log('onchange')
const ip = document.querySelector('#ip').value
const ipArr = await getFavIps()
if (!ip || !ipArr.includes(ip)) {
document.querySelector('#star').src = 'icons/star_empty.svg'
} else {
document.querySelector('#star').src = 'icons/star_filled.svg'
}
}
async function setFavorite() {
const ip = document.querySelector('#ip').value
const ipArr = await getFavIps()
// Set star icon
const star = document.querySelector('#star')
if (star.src.includes('filled') && ip) {
star.src = 'icons/star_empty.svg'
// remove from list
ipArr.splice(ipArr.indexOf(ip), 1)
} else {
star.src = 'icons/star_filled.svg'
// add to list
if (ip && !ipArr.includes(ip)) {
ipArr.push(ip)
}
}
Neutralino.storage.setData('favorites', JSON.stringify(ipArr))
}
async function setGenshinImpactFolder() {
@ -173,7 +221,7 @@ async function launchPrivate() {
Neutralino.storage.setData('config', JSON.stringify(config))
// Pass IP and game folder to the private server launcher
Neutralino.os.execCommand(`${NL_CWD}/scripts/private_server_launch.cmd ${ip} "${config.genshinImpactFolder}/Genshin Impact Game/${await getGenshinExecName()}"`).catch(e => console.log(e))
Neutralino.os.execCommand(`${NL_CWD}/scripts/private_server_launch.cmd ${ip} "${config.genshinImpactFolder}/${await getGenshinExecName()}"`).catch(e => console.log(e))
}
function minimizeWin() {