Captain is currently in ALPHA. We are happy to get your feedback
Core API
Helpers Windows

Module: helpers/windows

Table of contents

Functions

Functions

createAppWindow

createAppWindow(id, options?): Promise<BrowserWindow>

Asynchronously creates and opens a new application window for a specified app, loading its content via a custom, namespaced protocol. This function configures a new Electron BrowserWindow and initiates content loading based on a predefined loader associated with the app's unique identifier. It sets up the window without a frame and applies additional options provided by the caller.

The window's web content is prepared with a specific preload script that can manipulate or interact with the content securely before it fully loads, enhancing functionality and user experience.

Parameters

NameTypeDescription
idstringThe unique identifier for the app, used to determine the content loader and to namespace its protocol. This ID is crucial for loading the correct app resources and handling them in an isolated manner.
options?BrowserWindowConstructorOptionsOptional configuration options for customizing the new BrowserWindow instance. These options can dictate the visual and functional properties of the window, such as dimensions, frame visibility, and web preferences.

Returns

Promise<BrowserWindow>

A promise that resolves to the created BrowserWindow instance. This promise may reject if there is an issue with loading the app's content, with errors logged to the console.

Defined in

src/electron/helpers/windows.ts:249 (opens in a new tab)


createAppWindows

createAppWindows(configurations): Promise<void>

Asynchronously creates a multi-window application environment consisting of a main window and multiple child windows. This function identifies the main window configuration from the provided configurations array and then initializes all specified windows accordingly. It also sets up basic IPC (Inter-Process Communication) mechanisms allowing the main window to send messages to child windows and receive messages from them.

The function handles dynamic creation of child windows on-demand via specific IPC commands and ensures that communication only occurs with existing, non-destroyed windows. Child windows are linked to the main window as their parent, establishing a structured window hierarchy.

Parameters

NameTypeDescription
configurations{ id: string ; options: BrowserWindowConstructorOptions & { route?: string } }[]An array of objects where each object contains an 'id' and 'options' for creating a BrowserWindow. The 'id' should end with '-main-window' for the main window. Optional 'route' in options can specify initial content to load.

Returns

Promise<void>

This function does not return a value but initializes windows and sets up IPC channels for communication.

IPC Events:

  • CHILD_MESSAGE_FROM_PARENT_KEY: Listens for messages intended for child windows and forwards them appropriately.
  • CHILD_MESSAGE_TO_CHILD_KEY: Receives messages from child windows and forwards them to the main window if applicable.
  • CHILD_OPEN_KEY: Handles requests to dynamically open new child windows as specified by the IPC message data. Only registered windows can be opened

Defined in

src/electron/helpers/windows.ts:488 (opens in a new tab)


createCoreAppWindow

createCoreAppWindow(id, query?, options?): Promise<BrowserWindow>

Creates a specialized core application window for specific features like live-painting, storytelling, and other non-essential but integral components of Captain. These components utilize the SDK and are hosted within Captain's custom protocol.

This function configures a new Electron BrowserWindow with a specified set of options, ensuring it adheres to a minimum size requirement. It loads the window with a specific app URL composed of the provided app ID and an optional query string.

The window is frameless and utilizes a custom preload script for enhanced functionality, which is specified in the webPreferences.

Parameters

NameTypeDefault valueDescription
idstringundefinedThe unique identifier for the core app component. This ID is used to generate the URL and to register the window within the application.
query?string""Optional query string to append to the URL, allowing for dynamic content loading based on initial parameters.
options?BrowserWindowConstructorOptions{}Optional Electron BrowserWindow options to further customize the window's appearance and behavior. This can include dimensions, features, and web preferences.

Returns

Promise<BrowserWindow>

A promise that resolves to the created BrowserWindow instance, allowing for further manipulation and management within the application.

Defined in

src/electron/helpers/windows.ts:169 (opens in a new tab)


createCoreWindow

createCoreWindow(options?): Promise<BrowserWindow>

Creates the core application window for Captain, which includes essential features such as the dashboard, settings, downloads, and the marketplace. This window is a central hub for managing and interacting with core functionalities of the application.

The function configures a new Electron BrowserWindow with specified options, ensuring it meets minimum size requirements. The window is frameless and uses a specific preload script, enhancing its functionality with additional capabilities specified in the webPreferences.

Parameters

NameTypeDescription
options?BrowserWindowConstructorOptionsOptional Electron BrowserWindow options to customize the window's appearance and behavior. This can include dimensions, features, and specific web preferences tailored to enhance the core functionalities of the application.

Returns

Promise<BrowserWindow>

A promise that resolves to the newly created BrowserWindow instance, allowing for further manipulation and lifecycle management within the application. This window serves as the primary interface for user interaction with the application's central features.

Defined in

src/electron/helpers/windows.ts:211 (opens in a new tab)


createGuardedWindow

createGuardedWindow(id, options?): Promise<BrowserWindow>

Creates a new BrowserWindow instance with enhanced security settings suitable for loading locally served applications like ComfyUI. This function is designed to provide a secure environment by disabling Node.js integration, enabling context isolation, and supporting webview tags, aligning with best practices for security in Electron applications.

The primary use of this function is to set up a BrowserWindow that can safely host web applications that do not require Node.js integration within the rendering process, mitigating potential security risks. While the window supports loading any URL, it is strongly advised to use it only for trusted, locally served content. The configuration explicitly allows webview tags, which are essential for embedding separate web content securely within the application.

Parameters

NameTypeDescription
idstringThe unique identifier for the app, used to determine the content loader and to namespace its protocol. This ID is crucial for loading the correct app resources and handling them in an isolated manner.
options?BrowserWindowConstructorOptionsOptional configuration options for customizing the new BrowserWindow instance. These options can dictate the visual and functional properties of the window, such as dimensions, frame visibility, and web preferences.

Returns

Promise<BrowserWindow>

A promise that resolves to the created BrowserWindow instance. This promise may reject if there is an issue with loading the app's content, with errors logged to the console.

Defined in

src/electron/helpers/windows.ts:294 (opens in a new tab)


createInstallerWindow

createInstallerWindow(«destructured»): Promise<BrowserWindow>

Creates and displays the installer window with predefined dimensions. This window is used during the application's installation or update process. It loads a specific URL that corresponds to the installer interface.

Parameters

NameTypeDefault value
«destructured»Objectundefined
› step?string"installer/00"

Returns

Promise<BrowserWindow>

A promise that resolves to the created BrowserWindow instance for the installer.

Defined in

src/electron/helpers/windows.ts:29 (opens in a new tab)


createPromptWindow

createPromptWindow(): Promise<BrowserWindow>

Creates and manages a prompt window that functions similarly to a spotlight-like search bar. This window is designed to be always available but hidden by default and can be triggered to show via a specific key combination. It hides automatically when it loses focus.

The window is non-resizable, transparent, and always on top, ensuring it's visible above all other applications and interfaces. It does not support minimization or maximization to maintain its simplicity and specific functionality.

Key bindings:

  • A global shortcut (Control+Alt+Space) is registered to show the prompt window.
  • The 'Escape' key is used to hide the window when it is focused.

Events:

  • On 'show': Focuses on the window and registers the 'Escape' key to hide it.
  • On 'hide': Unregisters the 'Escape' key to prevent unintended interactions when the window is not visible.
  • On 'focus': Sends a custom IPC message indicating the window is focused.
  • On 'blur': Automatically hides the window to ensure it only remains visible while active.

IPC Events:

  • Handles custom IPC event for resizing the window based on dynamic content dimensions received from the renderer process.

Lifecycle:

  • On application's 'will-quit' event, unregisters all global shortcuts to clean up resources appropriately.

Returns

Promise<BrowserWindow>

The created prompt window, allowing further manipulation if necessary.

Defined in

src/electron/helpers/windows.ts:78 (opens in a new tab)


handleAppWindow

handleAppWindow(appId, options): Promise<null | BrowserWindow>

Manages or initializes an application window for a given third-party app identified by an appId. This function ensures that only one instance of any app window exists by checking if it's already present in the global apps object. If the window does not exist, it creates a new one using the specified options. It also sets up an event listener to nullify its reference in the global apps object upon closure, ensuring clean up and preventing memory leaks.

If the window is found to be minimized when this function is called, it will restore the window to its normal state. This ensures that the app window is visible and accessible to the user immediately after handling.

Parameters

NameTypeDescription
appIdstringThe unique identifier for the third-party app. This ID is used to store and retrieve the app window from the global apps object.
optionsBrowserWindowConstructorOptionsConfiguration options for creating the app window if it does not already exist. These options dictate the visual and functional properties of the window, such as dimensions, frame visibility, and web preferences.

Returns

Promise<null | BrowserWindow>

Returns a promise that resolves to the app window. This can be used to interact further with the window, such as loading URLs or manipulating window state.

Defined in

src/electron/helpers/windows.ts:410 (opens in a new tab)


handleCoreAppWindow

handleCoreAppWindow(appId, query, options): Promise<null | BrowserWindow>

Manages or initializes a core application window for a specific core app identified by an appId. This function checks if a window for the core app already exists in the global apps object. If not, it creates a new one using the provided options and an optional query string constructed from the query object. It ensures that only one instance of any core app window exists by managing its lifecycle through the global apps object.

Upon the window's closure, its reference in the apps object is nullified to ensure cleanup and prevent memory leaks. If the window is minimized when this function is called, it will be restored to ensure visibility.

Parameters

NameTypeDescription
appIdstringThe unique identifier for the core app, used to store and retrieve the app window from the global apps object.
queryRecord<string, string>An object representing key-value pairs that will be converted to a query string and appended to the window's URL, allowing for dynamic content loading based on provided parameters.
optionsBrowserWindowConstructorOptionsConfiguration options for creating the window if it does not already exist. These options can specify the visual and functional properties of the window, such as dimensions, frame visibility, and web preferences.

Returns

Promise<null | BrowserWindow>

Returns a promise that resolves to the app window. This allows for further interaction with the window, such as loading URLs or manipulating its state.

Defined in

src/electron/helpers/windows.ts:444 (opens in a new tab)


openApp

openApp(appId, payload?): Promise<void>

Opens an application identified by the appId. This function supports both single-window and multi-window configurations, dynamically handling the creation of these windows based on the options provided.

If the 'options' parameter indicates a multi-window configuration (as determined by the 'isMultiWindow' function), it initializes multiple windows each with its specific configuration. These configurations are extracted based on keys ending with '-window'. Otherwise, it handles a single-window setup.

The function operates asynchronously, ensuring all necessary windows are opened and configured before completing.

Parameters

NameTypeDescription
appIdstringThe unique identifier for the application. This ID is used as a base for creating window IDs in multi-window configurations.
payload?ObjectAn object containing optional settings for opening the application: - query: Optional query parameters, not used directly in this function but can be passed to window initialization functions. - options: Configuration options for the window. This can either be a single set of BrowserWindowConstructorOptions for a single window or a MultiWindowConfiguration object containing multiple configurations.
payload.options?BrowserWindowConstructorOptions | MultiWindowConfiguration-
payload.query?Record<string, string>-

Returns

Promise<void>

A promise that resolves when all windows are successfully opened and configured.

Defined in

src/electron/helpers/windows.ts:567 (opens in a new tab)


openComfyUI

openComfyUI(): Promise<void>

Opens an instance of ComfyUI within a securely configured BrowserWindow, created by the createGuardedWindow function. This function is tailored for safely loading and interacting with the ComfyUI application in either a development or production environment. It manages the window's lifecycle, handles error logging, and ensures that the UI is focused and ready for user interaction.

In a production environment, the function attempts to load ComfyUI from a custom protocol URL, ensuring the application is loaded securely and efficiently. In a development setting, it loads ComfyUI from a localhost URL, which is determined by a port number provided as a command-line argument, facilitating testing and development workflows.

This function also includes robust error handling to manage and log loading errors, enhancing reliability and maintainability. Additionally, it listens for the 'close' event to clean up resources by setting the window reference to null, ensuring that the application does not leak memory or resources.

Finally, the function checks if the window is minimized when activated. If so, it restores and focuses the window to ensure that ComfyUI is immediately visible and ready for user interaction, enhancing user experience by making the application responsive and accessible upon launch.

Returns

Promise<void>

This function does not return a value; it operates asynchronously and modifies the application state by managing the BrowserWindow instance dedicated to ComfyUI.

Defined in

src/electron/helpers/windows.ts:332 (opens in a new tab)


openCore

openCore(page, action?): Promise<void>

Opens the core window of the application to a specified page, with an optional action parameter. This function ensures the core window is initialized and visible, loading the designated page within the core section of the application. If provided, the action parameter allows for dynamic interaction with the page, typically influencing how the page behaves or interacts with the main process.

The core window is managed as a singleton within the application's lifecycle, ensuring that only one instance exists at a time. If the window is minimized when this function is called, it will be restored and focused to bring it to the user's attention.

Parameters

NameTypeDescription
pagestringThe specific page within the core module to navigate to. This should correspond to a valid route or file within the core section of your application's architecture.
action?stringAn optional query parameter that can trigger specific functionality on the page, enhancing interactivity and providing context-sensitive actions.

Returns

Promise<void>

Defined in

src/electron/helpers/windows.ts:371 (opens in a new tab)


openPreviewApp

openPreviewApp(query?): Promise<void>

Opens a preview application for viewing a specific file, allowing for multiple instances of the preview app to run concurrently with different contents. Each instance is uniquely identified using a file ID provided in the query. If an instance of the preview app for the specified file is already open, it will restore and focus that window instead of opening a new one.

This function ensures that each preview instance is managed separately, using a scoped identifier based on the file ID, which helps in tracking and managing multiple instances effectively.

Parameters

NameTypeDescription
query?Record<string, string>Contains the necessary parameters to identify and load the content in the preview app. Must include an 'id' key representing the unique identifier of the file to preview. If the 'id' is not provided, the function logs an error and exits without opening a new window.

Returns

Promise<void>

  • A promise that resolves when the preview app is opened, focused, or restored. The function does not return any value but performs asynchronous operations to manage the application windows.

Defined in

src/electron/helpers/windows.ts:615 (opens in a new tab)