Skip to content

Commit

Permalink
Add auto updater function
Browse files Browse the repository at this point in the history
  • Loading branch information
StivenCodess committed Oct 30, 2023
1 parent ad333d3 commit 90e2d1d
Show file tree
Hide file tree
Showing 7 changed files with 538 additions and 115 deletions.
580 changes: 476 additions & 104 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
"scripts": {
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1",
"dist": "electron-builder"
"dist": "electron-builder -p always"
},
"repository": "https://github.com/StivenCodess/ExcelUpPricer",
"publish": {
"provider": "github",
"owner": "StivenCodess",
"releaseType": "release"
},
"build": {
"appId": "com.stivencodess.exceluppricer",
"productname": "Excel Up Pricer",
"productName": "Excel Up Pricer",
"win": {
"target": "nsis"
},
Expand All @@ -27,10 +28,10 @@
"author": "StivenCodess",
"license": "ISC",
"devDependencies": {
"electron": "^27.0.2"
"electron": "^27.0.2",
"electron-builder": "^24.6.4"
},
"dependencies": {
"electron-builder": "^24.6.4",
"electron-log": "^5.0.0",
"electron-updater": "^6.1.4",
"toastify-js": "^1.12.0",
Expand Down
8 changes: 8 additions & 0 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ const buttonsPercentages = document.querySelectorAll(".percentages-buttons butto

const infoIcon = document.getElementById("info-icon");

const statusMsg = document.getElementById("status-msg");

let selectedButton = null;
let percentage = null;

document.addEventListener("DOMContentLoaded", () => {
window.api.status_message((e, msg) => {
statusMsg.innerHTML = `Status: ${msg}`;
});
});

buttonsPercentages.forEach((button) => {
button.addEventListener("click", (e) => {
if (selectedButton) selectedButton.classList.remove("selected");
Expand Down
33 changes: 27 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { join } = require("path");

const XLSX = require("xlsx");

let win = null;

autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = true;

Expand Down Expand Up @@ -34,11 +36,11 @@ const decreasePrice = (dataExcel, percentage) => {
};

const createWindow = () => {
const win = new BrowserWindow({
win = new BrowserWindow({
// width: 630,
// height: 580,
width: 1500,
height: 1000,
height: 700,
resizable: true,
webPreferences: {
nodeIntegration: true,
Expand All @@ -50,10 +52,6 @@ const createWindow = () => {
// win.setMenu(null);
win.loadFile("src/static/index.html");
win.webContents.openDevTools();

win.webContents.on("did-finish-load", () => {
win.webContents.send("uploaded-server", "Hello!");
});
};

ipcMain.on("uploaded", async (e, data, percentage, action) => {
Expand Down Expand Up @@ -94,4 +92,27 @@ ipcMain.on("uploaded", async (e, data, percentage, action) => {
app.whenReady().then(() => {
createWindow();
autoUpdater.checkForUpdates();
win.webContents.on("did-finish-load", () => {
win.webContents.send("status", "Checking Updates");
});

win.webContents.send("status", "Sigo checkeando");
});

autoUpdater.on("update-available", (info) => {
win.webContents.send("status", "Actualizacion disponible");
let pth = autoUpdater.downloadUpdate();
win.webContents.send("status", pth);
});

autoUpdater.on("update-not-available", (info) => {
win.webContents.send("status", "No hay actualizacion disponible");
});

autoUpdater.on("update-downloaded", (info) => {
win.webContents.send("status", "Actualizacion descargada");
});

autoUpdater.on("error", (info) => {
win.webContents.send("status", info);
});
1 change: 1 addition & 0 deletions src/preload/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const API = {
toast: (options) => Toastify(options).showToast(),
update_excel: (datafile, percentage, action) =>
ipcRenderer.send("uploaded", datafile, percentage, action),
status_message: (callback) => ipcRenderer.on("status", callback),
};

contextBridge.exposeInMainWorld("api", API);
18 changes: 18 additions & 0 deletions src/static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ body {
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
}

img,
Expand Down Expand Up @@ -226,3 +227,20 @@ input[type="file"]::-webkit-file-upload-button {
background-color: #26874e;
color: white;
}

.status-container {
background-color: white;
color: black;
width: 250px;
position: absolute;
right: -20px;
bottom: 50px;
border-radius: 8px;
padding: 10px 0px;
}

.status-container span {
display: block;
text-align: start;
padding-left: 10px;
}
4 changes: 3 additions & 1 deletion src/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<main>
<h1>Excel Up Pricer</h1>
<h3>Aumenta o disminuí los precios de tu excel para Abarrotes 2.12</h3>

<div class="info-icon" id="info-icon">
<img src="../assets/icons/info.svg" alt="info icon" />
</div>
Expand Down Expand Up @@ -51,6 +50,9 @@ <h3>Aumenta o disminuí los precios de tu excel para Abarrotes 2.12</h3>
<button id="decrease-price-button">DESCONTAR</button>
</div>
</main>
<div class="status-container">
<span id="status-msg">Status: </span>
</div>
<h4>Programmed by StivenCodess 👽</h4>
</body>
<script src="../js/utils.js"></script>
Expand Down

0 comments on commit 90e2d1d

Please sign in to comment.