[WIP] Fix issue preventing Disney Plus from closing #34

Merged
Copilot merged 4 commits from copilot/fix-disney-plus-close-issue into main 2025-11-18 10:51:08 -06:00
Copilot commented 2025-11-18 10:35:55 -06:00 (Migrated from github.com)

Fix: Disney Plus Cannot Close After Opening

Problem

After opening Disney+ (or any embedded browser service), users were unable to close it using the Escape or Ctrl+Q keyboard shortcuts. The browser view would remain open with no way to return to the main menu except by quitting the entire application.

Root Cause

When a BrowserView is created and covers the main window, keyboard events are captured by the BrowserView's webContents instead of the main window's renderer process. This meant the keyboard event handlers in renderer.js never received the Escape or Ctrl+Q keypress events.

Solution

Implemented global keyboard shortcuts using Electron's globalShortcut API in the main process. These shortcuts work system-wide and intercept keys even when the BrowserView has focus.

Changes Made

  • Register keyboard shortcuts in the main process using Electron's globalShortcut API
  • Ensure shortcuts work when BrowserView is active
  • Added closeBrowserView helper function for consistent cleanup
  • Properly unregister shortcuts when browser closes or app quits
  • Added comprehensive tests for global shortcuts functionality
  • Improved createBrowserView to unregister existing shortcuts before registering new ones
  • Run security checks (no vulnerabilities found)

Technical Implementation

  1. Added globalShortcut import to main.js
  2. Created registerBrowserShortcuts() - Registers Escape and CommandOrControl+Q globally
  3. Created unregisterBrowserShortcuts() - Cleans up registered shortcuts
  4. Created closeBrowserView() - Centralized helper that:
    • Removes the browser view
    • Unregisters shortcuts
    • Shows the home screen
  5. Modified createBrowserView() to:
    • Unregister existing shortcuts when replacing a browser view
    • Register shortcuts when browser opens
  6. Updated lifecycle handlers to unregister shortcuts on window close and app quit
  7. Added comprehensive test testGlobalShortcuts() to validate implementation

Testing

  • All 7 tests pass (including new global shortcuts test)
  • No npm package vulnerabilities found
  • CodeQL security scan: 0 alerts
  • Syntax validation passed

Security Summary

No security vulnerabilities were discovered or introduced by this change. The implementation follows best practices:

  • Shortcuts are properly registered/unregistered to prevent memory leaks
  • Global shortcuts only work when a BrowserView is active
  • Proper null checks prevent crashes
  • Dependencies are up-to-date and vulnerability-free

User Impact

Users can now reliably close Disney+ and other embedded browser services using:

  • Escape key to close and return to main menu
  • Ctrl+Q (Cmd+Q on Mac) to close and return to main menu

This fix applies to all embedded browser services (Netflix, Plex, Jellyfin, etc.), not just Disney+.

Original prompt

This section details on the original issue you should resolve

<issue_title>After Putting in Credentials, Disney plus will open but not be able to close</issue_title>
<issue_description>After Putting in Credentials, Disney plus will open but not be able to close</issue_description>

Comments on the Issue (you are @copilot in this section)


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

## Fix: Disney Plus Cannot Close After Opening ✅ ### Problem After opening Disney+ (or any embedded browser service), users were unable to close it using the Escape or Ctrl+Q keyboard shortcuts. The browser view would remain open with no way to return to the main menu except by quitting the entire application. ### Root Cause When a BrowserView is created and covers the main window, keyboard events are captured by the BrowserView's webContents instead of the main window's renderer process. This meant the keyboard event handlers in `renderer.js` never received the Escape or Ctrl+Q keypress events. ### Solution Implemented global keyboard shortcuts using Electron's `globalShortcut` API in the main process. These shortcuts work system-wide and intercept keys even when the BrowserView has focus. ### Changes Made - [x] Register keyboard shortcuts in the main process using Electron's globalShortcut API - [x] Ensure shortcuts work when BrowserView is active - [x] Added closeBrowserView helper function for consistent cleanup - [x] Properly unregister shortcuts when browser closes or app quits - [x] Added comprehensive tests for global shortcuts functionality - [x] Improved createBrowserView to unregister existing shortcuts before registering new ones - [x] Run security checks (no vulnerabilities found) ### Technical Implementation 1. **Added globalShortcut import** to main.js 2. **Created `registerBrowserShortcuts()`** - Registers Escape and CommandOrControl+Q globally 3. **Created `unregisterBrowserShortcuts()`** - Cleans up registered shortcuts 4. **Created `closeBrowserView()`** - Centralized helper that: - Removes the browser view - Unregisters shortcuts - Shows the home screen 5. **Modified `createBrowserView()`** to: - Unregister existing shortcuts when replacing a browser view - Register shortcuts when browser opens 6. **Updated lifecycle handlers** to unregister shortcuts on window close and app quit 7. **Added comprehensive test** `testGlobalShortcuts()` to validate implementation ### Testing - ✅ All 7 tests pass (including new global shortcuts test) - ✅ No npm package vulnerabilities found - ✅ CodeQL security scan: 0 alerts - ✅ Syntax validation passed ### Security Summary No security vulnerabilities were discovered or introduced by this change. The implementation follows best practices: - Shortcuts are properly registered/unregistered to prevent memory leaks - Global shortcuts only work when a BrowserView is active - Proper null checks prevent crashes - Dependencies are up-to-date and vulnerability-free ### User Impact Users can now reliably close Disney+ and other embedded browser services using: - **Escape** key to close and return to main menu - **Ctrl+Q** (Cmd+Q on Mac) to close and return to main menu This fix applies to all embedded browser services (Netflix, Plex, Jellyfin, etc.), not just Disney+. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>After Putting in Credentials, Disney plus will open but not be able to close</issue_title> > <issue_description>After Putting in Credentials, Disney plus will open but not be able to close</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes SluberskiHomeLab/castroix#33 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/SluberskiHomeLab/castroix/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
SluberskiHomeLab (Migrated from github.com) reviewed 2025-11-18 10:35:55 -06:00
Sign in to join this conversation.
No description provided.