Skip to content

Conversation

peppescg
Copy link
Collaborator

@peppescg peppescg commented Aug 28, 2025

Refactor: Extract Window Management to Dedicated Module

Changes Made

  • Created main-window.ts module: Extracted all window management logic from main.ts into a dedicated, well-structured module
  • Centralized window operations: All window creation, showing, hiding, focusing, and lifecycle management now handled in one place
  • Improved error handling: Added comprehensive try/catch blocks and consistent error logging across all window operations
  • Enhanced type safety: Added proper TypeScript interfaces for window options and platform-specific configurations
  • Better separation of concerns: Removed window management complexity from the main process entry point

Benefits

  • Maintainability: Window logic is now isolated and easier to modify
  • Reusability: Window functions can be imported and used consistently across modules
  • Robustness: Comprehensive error handling and validation for all window operations
  • Testability: Isolated module makes testing window behavior more feasible
  • Code organization: Cleaner main.ts focused on app lifecycle, not window details

Files Modified

  • NEW: main/src/main-window.ts - Complete window management module with 15+ exported functions
  • main/src/main.ts - Simplified by removing window management code and importing from new module
  • main/src/auto-update.ts - Updated to use new window management functions
  • main/src/system-tray.ts - Updated to use centralized window functions
  • main/src/toolhive-manager.ts - Updated imports and function calls

@peppescg peppescg self-assigned this Aug 28, 2025
@Copilot Copilot AI review requested due to automatic review settings August 28, 2025 10:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extracts window management functionality from the main Electron process file into a dedicated module for better code organization and maintainability.

Key Changes:

  • Created a new mainWindow.ts module containing all window-related operations and state management
  • Updated the main process to use the new window management functions instead of inline window handling
  • Modified test files to accommodate changes in function signatures (synchronous to asynchronous)

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
main/src/mainWindow.ts New module containing comprehensive window management functionality with proper error handling and TypeScript interfaces
main/src/main.ts Simplified by removing window creation logic and importing functions from the new mainWindow module
main/src/auto-update.ts Updated function signature to make window creation asynchronous
main/src/system-tray.ts Updated to use new window management functions from mainWindow module
main/src/toolhive-manager.ts Removed debug logging statement
main/src/tests/auto-update.test.ts Updated test mocks to handle asynchronous window creation

@peppescg peppescg linked an issue Aug 28, 2025 that may be closed by this pull request
kantord
kantord previously approved these changes Aug 28, 2025
Copy link
Member

@kantord kantord left a comment

Choose a reason for hiding this comment

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

I tested it locally on Linux and it at least does not seem to break anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] TypError Object has been destroyed
2 participants