Skip to content

Commit

Permalink
Removing old windows files after update
Browse files Browse the repository at this point in the history
  • Loading branch information
aandrew-me committed Aug 25, 2024
1 parent 9529493 commit 2ff34e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 26 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,32 @@ function createWindow() {
win.loadFile("html/index.html");
// win.setMenu(null)
win.show();
autoUpdater.checkForUpdates();

autoUpdater.checkForUpdates().then(result => {
// Removing unnecesary files for windows
if (result && process.platform === "win32") {
if (result.updateInfo.version === app.getVersion()) {
fs.readdir(path.join(process.env.LOCALAPPDATA, "ytdownloader-updater"), {encoding: "utf-8", withFileTypes: true}, (err, files) => {
if (err) {
console.log("No update directory to clear")
} else {
files.forEach(file => {
if (file.isFile()) {
fs.rm(path.join(file.path, file.name), (_err) => {
console.log("Removed file:", file.name)
})
} else {
fs.rm(path.join(file.path, file.name), { recursive: true}, (err) => {
console.log("Removed directory:", file.name)
})
}
})
}
})

}
}
});
}
let loadedLanguage;

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
},
"nsis": {
"allowToChangeInstallationDirectory": true,
"oneClick": false
"oneClick": false,
"deleteAppDataOnUninstall": true
},
"msi": {
"oneClick": true,
Expand Down

0 comments on commit 2ff34e9

Please sign in to comment.