Skip to content

Commit c6a5d9f

Browse files
committed
feat: Implement auto-update functionality using electron-updater and electron-log.
1 parent 4323ca5 commit c6a5d9f

File tree

3 files changed

+178
-10
lines changed

3 files changed

+178
-10
lines changed

application/package-lock.json

Lines changed: 108 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@
101101
},
102102
"dependencies": {
103103
"clipboardy": "^4.0.0",
104+
"electron-log": "^5.4.3",
104105
"electron-mac-permissions": "^2.2.2",
105106
"electron-store": "^11.0.2",
107+
"electron-updater": "^6.6.2",
106108
"uiohook-napi": "^1.5.4"
107109
},
108110
"trustedDependencies": [

application/src/main.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
nativeImage,
1515
clipboard,
1616
Notification,
17-
systemPreferences,
1817
shell,
1918
screen,
19+
dialog,
2020
} from "electron";
2121
import { spawn, exec } from "node:child_process";
2222
import path from "node:path";
@@ -27,6 +27,13 @@ import Store from "electron-store";
2727
import pkg from "uiohook-napi";
2828
const { uIOhook, UiohookKey } = pkg;
2929
const uiohook = uIOhook;
30+
import { autoUpdater } from "electron-updater";
31+
import log from "electron-log";
32+
33+
// Configure logging
34+
autoUpdater.logger = log;
35+
autoUpdater.logger.transports.file.level = "info";
36+
log.info("App starting...");
3037
const { getAuthStatus, askForMicrophoneAccess, askForAccessibilityAccess } =
3138
permissions;
3239

@@ -1139,6 +1146,11 @@ app.whenReady().then(async () => {
11391146
createTray();
11401147
startUiohook(); // Start the global hook
11411148

1149+
// Check for updates
1150+
if (app.isPackaged) {
1151+
autoUpdater.checkForUpdatesAndNotify();
1152+
}
1153+
11421154
app.on("activate", () => {
11431155
if (BrowserWindow.getAllWindows().length === 0) {
11441156
createWindow();
@@ -1164,3 +1176,58 @@ app.on("will-quit", () => {
11641176
if (process.platform === "darwin") {
11651177
app.dock?.hide();
11661178
}
1179+
1180+
// ============================================================================
1181+
// AUTO-UPDATER EVENTS
1182+
// ============================================================================
1183+
1184+
autoUpdater.on("checking-for-update", () => {
1185+
log.info("Checking for update...");
1186+
});
1187+
1188+
autoUpdater.on("update-available", (info) => {
1189+
log.info("Update available:", info);
1190+
// Optionally notify user
1191+
});
1192+
1193+
autoUpdater.on("update-not-available", (info) => {
1194+
log.info("Update not available:", info);
1195+
});
1196+
1197+
autoUpdater.on("error", (err) => {
1198+
log.error("Error in auto-updater. " + err);
1199+
});
1200+
1201+
autoUpdater.on("download-progress", (progressObj) => {
1202+
let log_message = "Download speed: " + progressObj.bytesPerSecond;
1203+
log_message = log_message + " - Downloaded " + progressObj.percent + "%";
1204+
log_message =
1205+
log_message +
1206+
" (" +
1207+
progressObj.transferred +
1208+
"/" +
1209+
progressObj.total +
1210+
")";
1211+
log.info(log_message);
1212+
});
1213+
1214+
autoUpdater.on("update-downloaded", (info) => {
1215+
log.info("Update downloaded");
1216+
1217+
// Create a dialog to ask the user to restart
1218+
const dialogOpts = {
1219+
type: "info",
1220+
buttons: ["Reiniciar", "Depois"],
1221+
title: "Atualização Disponível",
1222+
message:
1223+
process.platform === "win32" ? info.releaseNotes : info.releaseName,
1224+
detail:
1225+
"Uma nova versão foi baixada. Reinicie o aplicativo para aplicar as atualizações.",
1226+
};
1227+
1228+
dialog.showMessageBox(dialogOpts).then((returnValue) => {
1229+
if (returnValue.response === 0) {
1230+
autoUpdater.quitAndInstall();
1231+
}
1232+
});
1233+
});

0 commit comments

Comments
 (0)