From f14babadeb0cb1cf84a980b1fe0fccfe9fb88eab Mon Sep 17 00:00:00 2001 From: AquaJo <84229101+AquaJo@users.noreply.github.com> Date: Thu, 22 Aug 2024 01:50:39 +0200 Subject: [PATCH] fixed welcome page 'k'-dialog (self log in) so you can exit again + fixed java exiting error --- src/index.js | 27 +++++++++++++++------------ src/pages/welcomePage.js | 8 +++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index 69b575b..9177184 100644 --- a/src/index.js +++ b/src/index.js @@ -79,10 +79,8 @@ if (!gotTheLock) { mainWindow.webContents.send('log', 'Update heruntergeladen!'); // () // delete java process if existent before quitAndInstall!! --> using jarExec.pid - deleteJavaProcess(); - let obj = {}; - obj.deleteJavaProcess = '1'; - setCommunicatorJSON([obj, '']); + deleteJavaProcess(); // runs async bc java is responding to it in the background --> useful for setting communicator json at least to clean reset val + deleteJavaProcessSync(); // delete processes if existent immediately before quitAndInstall autoUpdater.quitAndInstall(); }); @@ -135,19 +133,28 @@ if (!gotTheLock) { if (!updating_finish) { console.log('Exit with code: ' + code); deleteJavaProcess(); + deleteJavaProcessSync(); } }); - function deleteJavaProcess() { + + function deleteJavaProcessSync() { updating_finish = true; // general finish flag in theory + if (!jarExec) return; try { process.kill(jarExec.pid); // could have also used spawn process for jarExec ... console.log(`Java process with PID ${jarExec.pid} terminated.`); } catch (error) { - console.info( + console.log( `Failed to terminate Java process with PID ${jarExec.pid}: ${error.message}. Maybe you were running an instance without java installed?` ); } } + function deleteJavaProcess() { + updating_finish = true; // general finish flag in theory + let obj = {}; + obj.deleteJavaProcess = '1'; + setCommunicatorJSON([obj, '']); + } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. @@ -169,9 +176,7 @@ if (!gotTheLock) { app.on('window-all-closed', async () => { console.log('close detected'); // communicate with java to delete ongoing java program - let obj = {}; - obj.deleteJavaProcess = '1'; - setCommunicatorJSON([obj, '']); + deleteJavaProcess(); if (process.platform !== 'darwin') app.quit(); }); @@ -467,15 +472,13 @@ if (!gotTheLock) { return; } mainWindow.webContents.send('noJavaAlert', ''); // also triggered on update due to process killing, but shouldn't matter - console.info(err); + console.log(err); //throw err; } console.log(stdout); console.log(stderr); } ); - //console.log(jarExec); - console.log('jarExec.pid:' + jarExec.pid); // could have also used spawn process for jarExec ... } } else { // TODO: No Java installed diff --git a/src/pages/welcomePage.js b/src/pages/welcomePage.js index 1b1ad33..f31cdf8 100644 --- a/src/pages/welcomePage.js +++ b/src/pages/welcomePage.js @@ -188,7 +188,7 @@ document.addEventListener('keydown', async (event) => { callback: async function (data) { if (!data) { manualLoginOpen = false; - open(); + //open(); // don't open it again if user cancels! (but keep the open of reopening ... ) } else { let ip = data.IP; if (ip !== undefined) { @@ -221,6 +221,7 @@ document.addEventListener('keydown', async (event) => { ) // .then(async (data) => { try { + // bruh fr? console.log(data[0].error); manualLoginOpen = false; @@ -228,8 +229,9 @@ document.addEventListener('keydown', async (event) => { console.log('apiKey is incorrect'); } catch (error) { - console.log('successfull login'); - // error should mean success ;) ... + // the typical "error is a success" ^^ ... + console.log('successfull login'); // ↓ + // error should mean success ;) ... --> oh bruh I 'already' recognized / mentioned that back then ... // clearing normal IP input let input = document.getElementById('IPInput'); input.value = '';