From bb419bf1bcfa1a537d042dbd7b0e6007e2ee4e12 Mon Sep 17 00:00:00 2001 From: The Jared Wilcurt Date: Mon, 1 Jan 2024 14:12:13 -0500 Subject: [PATCH] validate extract --- nw-testing/manual-testing.cjs | 5 +++-- .../index.cjs | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nw-testing/manual-testing.cjs b/nw-testing/manual-testing.cjs index 3f08648..7ceb5db 100644 --- a/nw-testing/manual-testing.cjs +++ b/nw-testing/manual-testing.cjs @@ -132,9 +132,10 @@ function manualTesting () { * @return {boolean} true = continue, false = retry/stop */ validateExtract: function (pathToExtract) { - console.log('validateExtract', pathToExtract); + const exists = fs.existsSync(pathToExtract); + console.log('Validate extract exists', pathToExtract, exists); // This is just an example, you can put any logic you want here - return true; + return exists; }, /** * When download or extract fails, but we haven't diff --git a/src/downloadLatestAppAndOpenWindowInBackground/index.cjs b/src/downloadLatestAppAndOpenWindowInBackground/index.cjs index e1259db..a8af2c4 100644 --- a/src/downloadLatestAppAndOpenWindowInBackground/index.cjs +++ b/src/downloadLatestAppAndOpenWindowInBackground/index.cjs @@ -63,16 +63,29 @@ async function downloadLatestAppAndOpenWindowInBackground (options) { helpers.throwError(options, 'Issue found with your options.autoUpdate.validateZip function.', error); } } - if (!zipIsValid) { return; } // extract zip - await extractZip(latestRemote); + const extractedSuccessfully = await extractZip(options, latestRemote); + + console.log({ extractedSuccessfully }); // validate extraction - stub(); + let extractIsValid = true; + if (options.autoUpdate.validateExtract) { + try { + const extractFilePath = helpers.getExtractPath(latestRemote); + extractIsValid = await options.autoUpdate.validateExtract(extractFilePath); + } catch (error) { + extractIsValid = false; + helpers.throwError(options, 'Issue found with your options.autoUpdate.validateExtract function.', error); + } + } + if (!extractIsValid) { + return; + } // Update/Retry/Error/Complete stub();