Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
Redownload Sparkle if its installed already!
  • Loading branch information
Thedogecraft committed Jan 15, 2024
1 parent 2eadcbc commit fc8d1fd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 27 deletions.
84 changes: 61 additions & 23 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -93,7 +131,7 @@ function createWindow() {
});

ipcMain.on("run-update-batch", () => {
downloadBatchFile();
downloadAndExtractSparkle();
});

const batFilePath =
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sparkle",
"main": "main.js",
"version": "1.0.8",
"version": "1.2.0",
"author": "The Parcoil network",
"scripts": {
"start": "electron .",
Expand Down
21 changes: 18 additions & 3 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,39 @@
<a href="index.html"><button class="nostyle">Home</button></a>
<a><button class="nostyle" id="runDebloat">Debloat</button></a>
<a><button class="nostyle" id="runClean">Cleaner</button></a>

<a><button class="nostyle" id="internet">Drivers</button></a>
<a><button class="nostyle" id="internet">Wifi Booster</button></a>
<a><button class="nostyle" id="internet">Wifi Booster</button></a>
<a href="settings.html"><button class="nostyle">Settings</button></a>
</div>

<div class="center-content">
<h1><span class="white-text">Settings</span></h1>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" checked>
<label class="form-check-label" for="flexSwitchCheckDefault">Discord RPC </label>

</div>



<button class="btn btn-primary mt-4" id="checkUpdatesBtn">Check for updates</button>

<div class="text-center mt-5">
<p id="updateProgress">Update progress located on taskbar</p>
<p class="mt-5" style="color:#4c4c4c">&copy; 2024 Parcoil Network </p>
</div>
<script src="script.js"></script>
</body>
<script>
document.getElementById("checkUpdatesBtn").addEventListener("click", function () {
// Show the text
document.getElementById("updateProgress").style.display = "block";

// Hide the text after 5 seconds
setTimeout(function () {
document.getElementById("updateProgress").style.display = "none";
}, 5000); // 5000 milliseconds = 5 seconds
});
</script>
<script>


Expand Down
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ body::-webkit-scrollbar {
.gone {
display: none;
}

#updateProgress {
display: none;
}

0 comments on commit fc8d1fd

Please sign in to comment.