From 4cf3575374a436e9c3d803198ff610bd5de559b3 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Tue, 19 Apr 2022 21:45:34 -0700 Subject: [PATCH] properly handle missing config --- resources/js/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/resources/js/index.js b/resources/js/index.js index 30a8502..e0f2f2e 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -7,13 +7,20 @@ document.addEventListener('DOMContentLoaded', async () => { }) async function getCfg() { - return JSON.parse(await Neutralino.storage.getData('config').catch(e => { + const cfgStr = await Neutralino.storage.getData('config').catch(e => { // The data isn't set, so this is our first time opening Neutralino.storage.setData('config', JSON.stringify({ genshinImpactFolder: '', lastConnect: '' })) - })) + }) + + if (!cfgStr) return { + genshinImpactFolder: '', + lastConnect: '' + } + + return JSON.parse(cfgStr) } async function displayGenshinFolder() { @@ -76,7 +83,6 @@ async function launchOfficial() { async function launchPrivate() { const ip = document.getElementById('ip').value || 'localhost' - const port = '' const config = await getCfg()