Guppy.App behaviour (guppy v0.1.0)

Copy Markdown View Source

Optional application-level coordinator for larger Guppy apps.

Guppy.Window remains the per-window abstraction and can still be started on its own. Guppy.App adds one OTP boundary for app-global configuration, resource slots, command/menu dispatch, and app-supervised windows.

defmodule MyApp do
  use Guppy.App,
    windows: [
      %{id: "main", module: MyApp.MainWindow, arg: %{}}
    ],
    commands: [%{id: "new_file", label: "New File"}],
    menus: [%{label: "File", items: [%{id: "new_file", label: "New", callback: "new_file"}]}]

  @impl Guppy.App
  def handle_command("new_file", _payload, state) do
    {:noreply, state}
  end
end

App modules usually start under the module name as the registered coordinator process, similar to Ecto.Repo. The process is non-rendering; windows remain Guppy.Window modules. App lifecycle events such as "app_activated" and "app_deactivated" are delivered to optional handle_event/3 callbacks.

Summary

Types

Result shape for use Guppy.App callbacks.

App coordinator state threaded through use Guppy.App callbacks.

Functions

Returns the app-owned native badge label, or nil.

Closes an app-owned window by string id.

Returns Guppy.IR.div/2 action/shortcut options for the app command registry.

Returns the native action callback id that routes shortcut actions to handle_command/3.

Returns command registry entries keyed by id.

Returns the validated app configuration.

Returns the app ref for the current app-supervised window process, if any.

Returns the app window id for the current app-supervised window process, if any.

Dispatches an app command asynchronously.

Dispatches the command bound to an app keymap entry, if any.

Returns app-owned Dock/app-icon menu items.

Activates/focuses an app-owned window by string id.

Returns app keymap entries.

Returns app-owned menus.

Opens the built-in command-palette overlay for an app.

Opens an app-owned transient context-menu popup for command items.

Opens a configured or dynamic app window by string id.

Returns packaging/signing metadata hooks stored in app config.

Registers a theme family for later lookup by theme id.

Installs or clears the app-owned native badge label.

Updates one app command's enabled state.

Replaces the app command registry after validation.

Installs app-owned native Dock/app-icon menu items.

Replaces app keymap entries after validation against commands.

Installs app-owned native menus.

Replaces the app stylesheet cache after validation.

Replaces the app theme after validation.

Starts an app supervisor and a registered app coordinator.

Resolves app stylesheet class references to style option keyword entries.

Returns the app stylesheet cache.

Returns the active app theme.

Looks up a semantic color token in the active app theme.

Looks up a semantic color token or raises when it is unavailable.

Returns registered app theme families keyed by family id.

Looks up a resolved semantic style token in the active app theme.

Looks up a semantic style token or raises when it is unavailable.

Returns the pid for an app-owned window id, or nil.

Returns known app window ids and pids.

Types

app_ref()

@type app_ref() :: GenServer.server()

callback_result()

@type callback_result() :: {:noreply, state()} | {:stop, term(), state()}

Result shape for use Guppy.App callbacks.

state()

@opaque state()

App coordinator state threaded through use Guppy.App callbacks.

Treat it as opaque: pattern-match nothing out of it and return it (possibly via the tuple shapes in callback_result/0) unchanged.

Callbacks

handle_command(t, map, state)

(optional)
@callback handle_command(String.t(), map(), state()) :: callback_result()

handle_event(t, map, state)

(optional)
@callback handle_event(String.t(), map(), state()) :: callback_result()

handle_info(term, state)

(optional)
@callback handle_info(term(), state()) :: callback_result()

init(keyword)

(optional)
@callback init(keyword()) ::
  map()
  | keyword()
  | Guppy.App.Config.t()
  | {:ok, map() | keyword() | Guppy.App.Config.t()}
  | {:stop, term()}

Functions

app_badge(app \\ nil)

Returns the app-owned native badge label, or nil.

close_window(app, window_id)

Closes an app-owned window by string id.

command_bindings(app \\ nil)

Returns Guppy.IR.div/2 action/shortcut options for the app command registry.

command_callback()

Returns the native action callback id that routes shortcut actions to handle_command/3.

commands(app \\ nil)

Returns command registry entries keyed by id.

config(app \\ nil)

Returns the validated app configuration.

current_app()

Returns the app ref for the current app-supervised window process, if any.

current_window_id()

Returns the app window id for the current app-supervised window process, if any.

dispatch(app, command_id, payload \\ %{})

Dispatches an app command asynchronously.

dispatch_key(app, key, payload \\ %{})

Dispatches the command bound to an app keymap entry, if any.

dock_menu(app \\ nil)

Returns app-owned Dock/app-icon menu items.

focus_window(window_id)

Activates/focuses an app-owned window by string id.

focus_window(app, window_id)

keymap(app \\ nil)

Returns app keymap entries.

open_command_palette(app \\ nil)

Opens the built-in command-palette overlay for an app.

open_context_menu(items)

Opens an app-owned transient context-menu popup for command items.

open_context_menu(app, items)

open_context_menu(app, items, opts)

open_window(app, window_id, overrides \\ [], timeout \\ 30000)

Opens a configured or dynamic app window by string id.

package(app \\ nil)

Returns packaging/signing metadata hooks stored in app config.

register_theme_family(app, family)

Registers a theme family for later lookup by theme id.

set_app_badge(app, label)

Installs or clears the app-owned native badge label.

set_command_enabled(command_id, enabled)

Updates one app command's enabled state.

set_command_enabled(app, command_id, enabled)

set_commands(app, commands)

Replaces the app command registry after validation.

set_dock_menu(app, items)

Installs app-owned native Dock/app-icon menu items.

set_keymap(app, keymap)

Replaces app keymap entries after validation against commands.

set_menus(app, menus)

Installs app-owned native menus.

set_stylesheet(app, stylesheet)

Replaces the app stylesheet cache after validation.

set_theme(app, theme)

Replaces the app theme after validation.

start_link(module, opts \\ [])

Starts an app supervisor and a registered app coordinator.

styles(app, class_refs)

Resolves app stylesheet class references to style option keyword entries.

stylesheet(app \\ nil)

Returns the app stylesheet cache.

theme(app \\ nil)

Returns the active app theme.

theme_color(token)

Looks up a semantic color token in the active app theme.

theme_color(app, token)

theme_color!(token)

Looks up a semantic color token or raises when it is unavailable.

theme_color!(app, token)

theme_families(app \\ nil)

Returns registered app theme families keyed by family id.

theme_style(token)

Looks up a resolved semantic style token in the active app theme.

theme_style(app, token)

theme_style!(token)

Looks up a semantic style token or raises when it is unavailable.

theme_style!(app, token)

window_pid(app, window_id)

Returns the pid for an app-owned window id, or nil.

windows(app \\ nil)

Returns known app window ids and pids.