Skip to main content
usePluginContext returns the full PluginUIContext object that the shell injects into every plugin’s React tree via PluginShellProvider. It is the foundational hook — all other shell utility hooks (useShellAuth, useShellToast, etc.) call it internally.

Import

import { usePluginContext } from "@skyvexsoftware/stratos-sdk";

Signature

function usePluginContext(): PluginUIContext
Throws if called outside a PluginShellProvider.

Return value

type PluginUIContext = {
  /** The plugin's unique ID */
  pluginId: string;

  /** Authentication state */
  auth: {
    isAuthenticated: boolean;
    token: string | null;
    user: unknown;
  };

  /** Current airline info from the Stratos API (null if not logged in) */
  airline?: {
    id: string;
    name: string;
    icao: string;
    logo_light: string;
    logo_dark: string;
  } | null;

  /** Synchronous config store, namespaced to this plugin */
  config: {
    get<T>(key: string): T | undefined;
    get<T>(key: string, defaultValue: T): T;
  };

  /** Raw Socket.io connection proxy */
  socket: {
    connected: boolean;
    emit(event: string, data: unknown): void;
    on(event: string, handler: (data: unknown) => void): void;
    off(event: string, handler: (data: unknown) => void): void;
  };

  /** Navigation helpers */
  navigation: PluginNavigationHelper;

  /** Toast/notification API */
  toast: PluginToastAPI;

  /** Scoped logger for renderer-side logging */
  logger: PluginLogger;
};

PluginNavigationHelper

type PluginNavigationHelper = {
  navigateTo(path: string): void;
  navigateToPlugin(pluginId: string, path: string): void;
  navigateToShell(path: string): void;
  getCurrentPath(): string;
};

PluginToastAPI

type PluginToastAPI = {
  success(message: string): void;
  error(message: string): void;
  info(message: string): void;
  warning(message: string): void;
};

PluginLogger

type PluginLogger = {
  info(category: string, message: string, ...args: unknown[]): void;
  warn(category: string, message: string, ...args: unknown[]): void;
  error(category: string, message: string, ...args: unknown[]): void;
  debug(category: string, message: string, ...args: unknown[]): void;
};

Usage

import { usePluginContext } from "@skyvexsoftware/stratos-sdk";

export function MyComponent() {
  const ctx = usePluginContext();

  return (
    <div>
      <p>Plugin: {ctx.pluginId}</p>
      <p>Authenticated: {ctx.auth.isAuthenticated ? "Yes" : "No"}</p>
      <button onClick={() => ctx.toast.success("Saved!")}>Save</button>
    </div>
  );
}

Notes

  • Prefer the focused utility hooks (useShellAuth, useShellToast, etc.) over reaching into the context object directly. They are more readable and produce narrower re-render subscriptions.
  • The socket field on the context is a low-level proxy. For high-frequency simulator data, use useSimData or useSocket instead.