diff --git a/main.js b/main.js index 030c413..80f428c 100644 --- a/main.js +++ b/main.js @@ -2,10 +2,9 @@ const { app, BrowserWindow, session, desktopCapturer, ipcMain, clipboard } = req const { autoUpdater } = require('electron-updater'); const path = require('path'); const packageJson = require('./package.json'); -const PERIODIC_UPDATE_CHECK_INTERVAL_MS = 1 * 60 * 1000; const updateState = { - status: 'idle', // idle | checking | available | downloading | downloaded | installing | not-available | error + status: 'idle', // idle | checking | available | downloading | downloaded | not-available | error info: null, error: null, }; @@ -25,8 +24,6 @@ function isNewerVersionAvailable(info) { } let updateCheckInProgress = false; -let installInProgress = false; -let periodicUpdateTimer = null; function resolveBackendUrl() { const configuredUrl = (process.env.CHATTZ_URL || process.env.APP_BASE_URL || '').trim(); @@ -52,10 +49,6 @@ function webContentsOrigin(webContents) { } async function runUpdateCheck(reason = 'manual') { - if (installInProgress) { - console.log(`Update check skipped (${reason}): install already in progress`); - return; - } if (updateCheckInProgress) { console.log(`Update check skipped (${reason}): another check is already in progress`); return; @@ -85,57 +78,6 @@ async function runUpdateCheck(reason = 'manual') { } } -function installDownloadedUpdate() { - if (installInProgress) { - console.log('Update install already in progress'); - return; - } - - installInProgress = true; - updateState.status = 'installing'; - updateState.error = null; - broadcastUpdateState(); - - const wins = BrowserWindow.getAllWindows(); - for (const win of wins) { - if (win.isDestroyed()) continue; - try { - win.removeAllListeners('close'); - win.destroy(); - } catch (err) { - console.warn('Failed to destroy window before update install', err); - } - } - - setImmediate(() => { - try { - autoUpdater.quitAndInstall(false, true); - } catch (err) { - installInProgress = false; - updateState.status = 'error'; - updateState.error = err && err.message ? err.message : String(err); - broadcastUpdateState(); - console.error('quitAndInstall failed', err); - } - }); - - setTimeout(() => { - if (installInProgress) { - console.warn('Update install is still waiting for app shutdown'); - } - }, 15000); -} - -function startPeriodicUpdateChecks() { - if (periodicUpdateTimer || !app.isPackaged) { - return; - } - - periodicUpdateTimer = setInterval(() => { - void runUpdateCheck('periodic'); - }, PERIODIC_UPDATE_CHECK_INTERVAL_MS); -} - function createWindow() { const sess = session.fromPartition('persist:chattz'); const backendUrl = resolveBackendUrl(); @@ -267,7 +209,6 @@ app.whenReady().then(() => { }); ipcMain.on('download-update', () => { - if (installInProgress) return; updateState.status = 'downloading'; updateState.error = null; broadcastUpdateState(); @@ -275,14 +216,13 @@ app.whenReady().then(() => { }); ipcMain.on('quit-and-install', () => { - installDownloadedUpdate(); + autoUpdater.quitAndInstall(); }); // Check once on startup setTimeout(() => { void runUpdateCheck('startup'); }, 5000); - startPeriodicUpdateChecks(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { @@ -297,13 +237,6 @@ app.on('window-all-closed', () => { } }); -app.on('before-quit', () => { - if (periodicUpdateTimer) { - clearInterval(periodicUpdateTimer); - periodicUpdateTimer = null; - } -}); - function safeOrigin(value) { try { return new URL(value).origin; diff --git a/static/shared/app-core.js b/static/shared/app-core.js index 8531b48..deee4bc 100644 --- a/static/shared/app-core.js +++ b/static/shared/app-core.js @@ -29,7 +29,6 @@ const state = { viewMode: 'chat', // 'chat' or 'video' iceServers: [{ urls: "stun:stun.l.google.com:19302" }], peerGainNodes: new Map(), // userId -> GainNode - peerAudioNodes: new Map(), // userId -> { sourceNode, compressorNode, gainNode } visibleVolumeSliders: new Set(), // userIds whose sliders are visible }, voicePresencePollId: null, @@ -1040,24 +1039,7 @@ function shouldInitiateOffer(peerId) { return state.me.id > peerId; } -function disconnectPeerAudioNodes(peerId) { - const nodes = state.voice.peerAudioNodes.get(peerId); - if (!nodes) return; - - for (const node of [nodes.sourceNode, nodes.compressorNode, nodes.gainNode]) { - try { - node?.disconnect(); - } catch { } - } - - state.voice.peerAudioNodes.delete(peerId); - state.voice.peerGainNodes.delete(peerId); -} - function stopAndClearAudioPipeline() { - for (const peerId of state.voice.peerAudioNodes.keys()) { - disconnectPeerAudioNodes(peerId); - } if (state.voice.deepFilterProcessor) { state.voice.deepFilterProcessor.destroy(); state.voice.deepFilterProcessor = null; @@ -1283,7 +1265,7 @@ async function createLocalVoiceStream() { sampleRate: 48000, echoCancellation: true, noiseSuppression: false, - autoGainControl: true, + autoGainControl: false, }, video: false, }; @@ -1406,27 +1388,16 @@ function ensurePeerConnection(peerId) { const ctx = state.voice.audioContext; if (ctx.state === 'suspended') ctx.resume(); - disconnectPeerAudioNodes(peerId); - const sourceNode = ctx.createMediaStreamSource(audio.srcObject); - const compressorNode = ctx.createDynamicsCompressor(); const gainNode = ctx.createGain(); - compressorNode.threshold.setValueAtTime(-24, ctx.currentTime); - compressorNode.knee.setValueAtTime(18, ctx.currentTime); - compressorNode.ratio.setValueAtTime(4, ctx.currentTime); - compressorNode.attack.setValueAtTime(0.003, ctx.currentTime); - compressorNode.release.setValueAtTime(0.25, ctx.currentTime); - const currentVolume = state.userVolumes.get(peerId) ?? 1.0; gainNode.gain.setValueAtTime(currentVolume, ctx.currentTime); - sourceNode.connect(compressorNode); - compressorNode.connect(gainNode); + sourceNode.connect(gainNode); gainNode.connect(ctx.destination); state.voice.peerGainNodes.set(peerId, gainNode); - state.voice.peerAudioNodes.set(peerId, { sourceNode, compressorNode, gainNode }); // Mute the original element as we play through Web Audio destination audio.volume = 0; @@ -1611,7 +1582,6 @@ async function joinVoice() { pc.close(); state.voice.peerConnections.delete(msg.user_id); } - disconnectPeerAudioNodes(msg.user_id); document.getElementById(`audio-${msg.user_id}`)?.remove(); } else if (msg.type === "signal") { await handleSignal(msg.from_user_id, msg.kind, msg.data);