Skip to content

Commit c72522a

Browse files
fix: disable background throttling when visualizer is active
Chromium aggressively throttles setInterval in minimized/hidden BrowserWindows down to ~1000ms intervals. Since the audio FFT analysis runs in the main renderer via setInterval, minimizing or closing the main window caused the visualizer to become choppy. Call mainWindow.webContents.setBackgroundThrottling(false) when the visualizer is enabled to keep the audio data loop running at full ~30fps. Re-enable throttling when the visualizer is disabled or the plugin is cleaned up.
1 parent 7c7daec commit c72522a

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/plugins/taskbar-widget/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,15 @@ export const createMiniPlayer = async (
10301030
visualizerAudioPeakThreshold = config.visualizer.audioPeakThreshold;
10311031
visualizerWidth = config.visualizer.width ?? 84;
10321032
blurOpacity = config.blurOpacity ?? 0.5;
1033+
1034+
// Disable background throttling on the main window when the visualizer
1035+
// is enabled. Chromium aggressively throttles setInterval in minimized
1036+
// or hidden BrowserWindows (~1 s), which starves the audio analysis
1037+
// loop running in the renderer. This keeps data flowing at full speed.
1038+
if (visualizerEnabled && !mainWindow.isDestroyed()) {
1039+
mainWindow.webContents.setBackgroundThrottling(false);
1040+
}
1041+
10331042
const preloadPath = writePreloadScript();
10341043
const { x, y, width, height } = getWidgetBounds();
10351044
const htmlPath = writeHtmlFile(height);
@@ -1294,6 +1303,7 @@ export const updateConfig = (newConfig: TaskbarWidgetPluginConfig) => {
12941303
positionOffsetY = newConfig.offsetY;
12951304
backgroundBlurEnabled = newConfig.backgroundBlur;
12961305
blurOpacity = newConfig.blurOpacity ?? 0.5;
1306+
const wasVisualizerEnabled = visualizerEnabled;
12971307
visualizerEnabled = newConfig.visualizer.enabled;
12981308
visualizerPosition = newConfig.visualizer.position;
12991309
visualizerWidth = newConfig.visualizer.width ?? 84;
@@ -1304,6 +1314,15 @@ export const updateConfig = (newConfig: TaskbarWidgetPluginConfig) => {
13041314
visualizerAudioPeakThreshold = newConfig.visualizer.audioPeakThreshold;
13051315
lastBounds = null; // Force reposition on next tick
13061316

1317+
// Toggle background throttling based on visualizer state
1318+
if (mainWindowRef && !mainWindowRef.isDestroyed()) {
1319+
if (visualizerEnabled && !wasVisualizerEnabled) {
1320+
mainWindowRef.webContents.setBackgroundThrottling(false);
1321+
} else if (!visualizerEnabled && wasVisualizerEnabled) {
1322+
mainWindowRef.webContents.setBackgroundThrottling(true);
1323+
}
1324+
}
1325+
13071326
if (miniPlayerWin && !miniPlayerWin.isDestroyed()) {
13081327
repositionWidget();
13091328
miniPlayerWin.webContents.send(
@@ -1326,6 +1345,11 @@ export const cleanup = () => {
13261345
intentionalClose = true;
13271346
isShowing = false;
13281347

1348+
// Restore normal background throttling
1349+
if (mainWindowRef && !mainWindowRef.isDestroyed()) {
1350+
mainWindowRef.webContents.setBackgroundThrottling(true);
1351+
}
1352+
13291353
clearBlurRecoveryTimers();
13301354

13311355
if (hideRecoveryInterval) {

0 commit comments

Comments
 (0)