From bfcf84c5acb5aba7fac8e1bf1d240e4e825cbdc7 Mon Sep 17 00:00:00 2001 From: VPS 4 Builder Date: Sun, 31 May 2026 02:49:57 +0200 Subject: [PATCH] =?UTF-8?q?fix(updater):=20auto-restart=20ap=C3=B3s=20down?= =?UTF-8?q?load=20+=20perMachine=20false=20para=20silent=20install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - perMachine: false → instala em %LocalAppData% sem UAC, permitindo silent update - update-downloaded: chama quitAndInstall(true, true) automaticamente após 15s - Contagem regressiva visível no tray tooltip e menu - Botão "Instalar Agora" cancela o countdown e instala imediatamente - isSilent=true + isForceRunAfter=true: sem janela do instalador, reabre após instalar Co-Authored-By: Claude Sonnet 4.6 --- index.js | 44 ++++++++++++++++++++++++++++++++++---------- package.json | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 4fcb909..27a3e1b 100644 --- a/index.js +++ b/index.js @@ -52,17 +52,31 @@ autoUpdater.on('download-progress', (progress) => { }); autoUpdater.on('update-downloaded', (info) => { - console.log('✅ Atualização baixada:', info.version, '— será instalada ao fechar o app.'); + console.log('✅ Atualização baixada:', info.version, '— reiniciando em 15 segundos...'); downloadProgress = "Pronto"; - updateTrayMenu(); - // Notificar o usuário na tray + if (tray) { tray.displayBalloon({ title: 'ScoreOdonto - Atualização Pronta', - content: `Versão ${info.version} será instalada automaticamente ao fechar o aplicativo.`, + content: `Versão ${info.version} baixada. O aplicativo será reiniciado automaticamente em 15 segundos.`, iconType: 'info' }); } + + // Contagem regressiva no tray tooltip + let countdown = 15; + const countdownInterval = setInterval(() => { + countdown--; + if (tray) tray.setToolTip(`ScoreOdonto — Reiniciando em ${countdown}s para instalar v${info.version}...`); + if (countdown <= 0) { + clearInterval(countdownInterval); + // isSilent=true (sem janela do instalador), isForceRunAfter=true (reabre após instalar) + autoUpdater.quitAndInstall(true, true); + } + }, 1000); + + // Permite cancelar o restart manual pelo menu + updateTrayMenu(countdown, countdownInterval, info.version); }); autoUpdater.on('error', (err) => { @@ -200,13 +214,18 @@ function createConfigWindow() { }); } -function updateTrayMenu() { +let pendingCountdownInterval = null; + +function updateTrayMenu(countdown = null, countdownInterval = null, updateVersion = null) { if (!tray) return; + // Salva o interval ativo para poder cancelar + if (countdownInterval !== null) pendingCountdownInterval = countdownInterval; + let statusText = "ScoreOdonto: Desconectado 🔴"; if (currentStatus.connected) { - statusText = currentStatus.identified - ? "ScoreOdonto: Identificado 🟢" + statusText = currentStatus.identified + ? "ScoreOdonto: Identificado 🟢" : "ScoreOdonto: Conectado... 🟡"; } @@ -218,10 +237,15 @@ function updateTrayMenu() { // Se houver um download em andamento, mostra a barra no menu if (downloadProgress !== null) { if (downloadProgress === "Pronto") { - template.push({ - label: '📦 Instalar Nova Versão (Reiniciar)', + const countdownLabel = countdown !== null + ? `⏱️ Reiniciando em ${countdown}s para instalar v${updateVersion}...` + : '📦 Atualização pronta para instalar'; + template.push({ label: countdownLabel, enabled: false }); + template.push({ + label: '🚀 Instalar Agora (Reiniciar)', click: () => { - autoUpdater.quitAndInstall(); + if (pendingCountdownInterval) clearInterval(pendingCountdownInterval); + autoUpdater.quitAndInstall(true, true); } }); } else { diff --git a/package.json b/package.json index 4086b49..bff425a 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "nsis": { "oneClick": true, - "perMachine": true, + "perMachine": false, "allowToChangeInstallationDirectory": false, "createDesktopShortcut": true, "createStartMenuShortcut": true,