diff --git a/main.js b/main.js index 60e6dea..0cb0c3d 100644 --- a/main.js +++ b/main.js @@ -21,33 +21,71 @@ function createWindow() { contextIsolation: false, }, }); - electronDL(); - // Rest of your code... - - function downloadBatchFile() { - const downloadURL = - "https://raw.githubusercontent.com/Parcoil/Sparkle/main/update.bat"; + function downloadAndExtractSparkle() { + const downloadURL = `https://github.com/Parcoil/Sparkle/releases/latest/download/win-unpacked.zip`; const downloadDir = app.getPath("userData"); - const downloadPath = path.join(downloadDir, "update.bat"); - - electronDL - .download(BrowserWindow.getFocusedWindow(), downloadURL, { - directory: downloadDir, - filename: "update.bat", // Set the desired filename - overwrite: true, // Overwrite the file if it already exists - }) - .then((dl) => { - console.log(`Downloaded to ${dl.getSavePath()}`); - - // Run the downloaded batch file as administrator - runBatFile(dl.getSavePath()); - }) - .catch((error) => { - console.error(`Error downloading the file: ${error}`); + const downloadPath = path.join(downloadDir, "win-unpacked.zip"); + const extractionPath = `C:\\Users\\${process.env.USERNAME}\\AppData\\Local\\Programs\\sparkle`; + + // Kill the Sparkle.exe process twice before downloading + killSparkleProcess(() => { + killSparkleProcess(() => { + electronDL + .download(BrowserWindow.getFocusedWindow(), downloadURL, { + directory: downloadDir, + filename: "win-unpacked.zip", + overwrite: true, + }) + .then((dl) => { + console.log(`Downloaded to ${dl.getSavePath()}`); + + // Extract the downloaded zip file to the specified path + extractZip(dl.getSavePath(), extractionPath); + + // You can add further actions here after extraction if needed + }) + .catch((error) => { + console.error(`Error downloading the file: ${error}`); + }); }); + }); + } + + function extractZip(zipFilePath, extractionPath) { + exec( + `powershell Expand-Archive -Path "${zipFilePath}" -DestinationPath "${extractionPath}" -Force`, + (error, stdout, stderr) => { + if (error) { + console.error(`Error extracting zip: ${error.message}`); + return; + } + if (stderr) { + console.error(`Zip extraction stderr: ${stderr}`); + return; + } + console.log(`Zip extracted to ${extractionPath}`); + } + ); } + function killSparkleProcess(callback) { + // Kill Sparkle.exe process + exec("taskkill /f /im Sparkle.exe", (error, stdout, stderr) => { + if (error) { + console.error(`Error killing Sparkle.exe process: ${error.message}`); + } + if (stderr) { + console.error(`Sparkle.exe process termination stderr: ${stderr}`); + } + console.log("Sparkle.exe process terminated."); + callback(); + }); + } + + // Call the function to initiate the download and extraction process + downloadAndExtractSparkle(); + // Trigger the batch file download when the app is ready client.on("ready", () => { @@ -93,7 +131,7 @@ function createWindow() { }); ipcMain.on("run-update-batch", () => { - downloadBatchFile(); + downloadAndExtractSparkle(); }); const batFilePath = diff --git a/package.json b/package.json index ae13837..742be78 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sparkle", "main": "main.js", - "version": "1.0.8", + "version": "1.2.0", "author": "The Parcoil network", "scripts": { "start": "electron .", diff --git a/settings.html b/settings.html index 41538af..c4ff6fc 100644 --- a/settings.html +++ b/settings.html @@ -33,9 +33,8 @@ - - - + +
Update progress located on taskbar
© 2024 Parcoil Network