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

Module: helpers/app-loaders

Table of contents

Type Aliases

Variables

Functions

Type Aliases

MultiWindowConfiguration

Ƭ MultiWindowConfiguration: Record<MultiWindowKey | "main-window", BrowserWindowConstructorOptions & { route?: string }>

Describes the configuration for multiple windows in an application, including the main window. This type maps window identifiers (including 'main-window') to their respective configuration, which includes standard BrowserWindow constructor options and an optional route.

The route property can be used to specify the initial URL or frontend route the window should display.

Example

const windowsConfig: MultiWindowConfiguration = {
  "main-window": { width: 800, height: 600, route: "/home" },
  "settings-window": { width: 600, height: 400, route: "/settings" }
};

Defined in

src/electron/helpers/app-loaders.ts:42 (opens in a new tab)


MultiWindowKey

Ƭ MultiWindowKey: `${string}-window`

Represents a unique key for identifying multiple window configurations. Each key is a combination of a base identifier and the suffix '-window'.

Example

const windowKey: MultiWindowKey = "app-window";

Defined in

src/electron/helpers/app-loaders.ts:25 (opens in a new tab)

Variables

appLoaders

Const appLoaders: Record<string, LoadURL> = {}

Defined in

src/electron/helpers/app-loaders.ts:14 (opens in a new tab)

Functions

isMultiWindow

isMultiWindow(object_): object_ is MultiWindowConfiguration

Determines if the given configuration object is meant for multi-window setups. This is identified by checking for the presence of a specific key ("main-window") in the object, which indicates a structured configuration for multiple windows.

Parameters

NameTypeDescription
object_BrowserWindowConstructorOptions | MultiWindowConfigurationThe configuration object to be tested. This object can be either a set of options for a single BrowserWindow or a configuration object defining multiple windows.

Returns

object_ is MultiWindowConfiguration

Returns true if the configuration is for multiple windows, otherwise false.

Defined in

src/electron/helpers/app-loaders.ts:59 (opens in a new tab)


isSingleWindow

isSingleWindow(object_): object_ is BrowserWindowConstructorOptions

Determines if the given configuration object is intended for a single-window setup. This check is performed by verifying that none of the keys in the object end with "-window", which would suggest a configuration for multiple distinct windows.

Parameters

NameTypeDescription
object_BrowserWindowConstructorOptions | MultiWindowConfigurationThe configuration object to be evaluated. This parameter can either be a straightforward BrowserWindow configuration or a multi-window setup object.

Returns

object_ is BrowserWindowConstructorOptions

Returns true if the configuration only pertains to a single window, otherwise false.

Defined in

src/electron/helpers/app-loaders.ts:78 (opens in a new tab)


registerApps

registerApps(): void

Registers each installed application by discovering markdown files named 'captain.md' in app directories. This function reads each markdown file to extract front matter data which dictates whether an app requires a single or multi-window setup. It then registers a custom protocol for each app, enabling the app to be served statically.

The function handles multi-window apps by creating specific configurations for each window mentioned in the front matter and registering each with its custom protocol and path. For apps without multiple window configurations, a single protocol is registered.

Assumptions:

  • Each app directory must contain a 'captain.md' file with YAML front matter that includes window configurations.
  • Apps are located in a specific directory retrievable by getCaptainApps().

Side Effects:

  • Global appLoaders object is populated with functions capable of serving the app files under specific protocols.

Returns

void

Does not return a value but logs information about the discovered and registered applications.

Defined in

src/electron/helpers/app-loaders.ts:104 (opens in a new tab)