Skip to content

fix: ensure WebSocket notifications are sent before application quits#4381

Open
cjuriartec wants to merge 1 commit intopear-devs:masterfrom
cjuriartec:fix/reliable-ws-shutdown
Open

fix: ensure WebSocket notifications are sent before application quits#4381
cjuriartec wants to merge 1 commit intopear-devs:masterfrom
cjuriartec:fix/reliable-ws-shutdown

Conversation

@cjuriartec
Copy link
Copy Markdown

Problem

When closing the application (e.g. via Cmd+Q on macOS), the WebSocket clients wouldn't consistently receive a final "isPlaying: false" state because the application was terminating before the network buffers could be flushed.

Solution

  • Expose a wsNotifyClose function in the api-server plugin.
  • Added a before-quit event listener in the main backend process that triggers this notification.
  • Ensured structural compatibility for WebSocket context types with as unknown as WSContext<WebSocket> to prevent TypeScript errors.

Testing

Verified with Boring Notch connection. The notification is now consistently received before Pear Desktop fully exits.

@JellyBrick JellyBrick added the bug Something isn't working label Mar 23, 2026

export const backend = createBackend<BackendType, APIServerConfig>({
async start(ctx) {
const { app } = await import('electron');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you used await import?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe they were not aware that vite does tree-shaking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants