@@ -14,9 +14,9 @@ import {
1414 nativeImage ,
1515 clipboard ,
1616 Notification ,
17- systemPreferences ,
1817 shell ,
1918 screen ,
19+ dialog ,
2020} from "electron" ;
2121import { spawn , exec } from "node:child_process" ;
2222import path from "node:path" ;
@@ -27,6 +27,13 @@ import Store from "electron-store";
2727import pkg from "uiohook-napi" ;
2828const { uIOhook, UiohookKey } = pkg ;
2929const 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..." ) ;
3037const { 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", () => {
11641176if ( 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