Skip to content

Commit 8bd020a

Browse files
Reload page on system resume to fix stale Messenger connection
After a system suspend/wake cycle, the long-poll/WebSocket connection to messenger.com is silently broken. This adds a powerMonitor 'resume' listener that waits for network connectivity via ensureOnline(), then reloads the page to restore the connection without user intervention. Fixes #103 Co-Authored-By: Paperclip <noreply@paperclip.ing>
1 parent c3cbcf9 commit 8bd020a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

source/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
MenuItemConstructorOptions,
1313
systemPreferences,
1414
nativeTheme,
15+
powerMonitor,
1516
} from 'electron';
1617
import {ipcMain as ipc} from 'electron-better-ipc';
1718
import {autoUpdater} from 'electron-updater';
@@ -430,6 +431,15 @@ function createMainWindow(): BrowserWindow {
430431

431432
const {webContents} = mainWindow;
432433

434+
// Reload the page on system resume to restore the Messenger connection,
435+
// which is lost when the computer sleeps. Wait for network connectivity
436+
// before reloading to avoid a blank page on slow reconnects.
437+
// See: https://github.com/sindresorhus/caprine/issues/103
438+
powerMonitor.on('resume', async () => {
439+
await ensureOnline();
440+
webContents.reload();
441+
});
442+
433443
webContents.on('dom-ready', async () => {
434444
// Set window title to Caprine
435445
mainWindow.setTitle(app.name);

0 commit comments

Comments
 (0)