fix(updater): auto-restart após download + perMachine false para silent install

- 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 <noreply@anthropic.com>
This commit is contained in:
VPS 4 Builder
2026-05-31 02:49:57 +02:00
parent 2a26f72460
commit bfcf84c5ac
2 changed files with 35 additions and 11 deletions
+34 -10
View File
@@ -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 {
+1 -1
View File
@@ -22,7 +22,7 @@
},
"nsis": {
"oneClick": true,
"perMachine": true,
"perMachine": false,
"allowToChangeInstallationDirectory": false,
"createDesktopShortcut": true,
"createStartMenuShortcut": true,