Module: Lich::Common::SessionLauncher

Defined in:
documented/common/session_launcher.rb

Overview

Launches independent child Lich sessions using prepared launch_data mapped to CLI-style argv.

Constant Summary collapse

OPTIONAL_PATH_FLAGS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Configuration for optional directory path CLI flags that may be passed to child launches. Each entry maps a CLI option name to a context key, launcher constant name, and priority. Used by optional_spawn_flags to emit --home, --data, --scripts, etc. flags only when the child process directory would differ from defaults.

See Also:

  • optional_spawn_flags
[
  { option: 'home', key: :home_dir, constant: :LICH_DIR },
  { option: 'data', key: :data_dir, constant: :DATA_DIR },
  { option: 'scripts', key: :script_dir, constant: :SCRIPT_DIR },
  { option: 'temp', key: :temp_dir, constant: :TEMP_DIR },
  { option: 'maps', key: :map_dir, constant: :MAP_DIR },
  { option: 'logs', key: :log_dir, constant: :LOG_DIR },
  { option: 'backup', key: :backup_dir, constant: :BACKUP_DIR },
  { option: 'lib', key: :lib_dir, constant: :LIB_DIR }
].freeze

Class Method Summary collapse

Class Method Details

.launch(launch_data, launch_context: nil) ⇒ Hash

Launches a detached child Lich process from prebuilt launch data.

Parameters:

  • launch_data (Array<String>)

    Launch lines from Authentication::LaunchData.prepare

  • launch_context (Hash, nil) (defaults to: nil)

    Optional context keys: :char_name, :game_code, :frontend, :custom_launch, :dark_mode and optional directory overrides (:home_dir, :data_dir, :script_dir, :temp_dir, :map_dir, :log_dir, :backup_dir, :lib_dir).

Returns:

  • (Hash)

    Structured result:

    • success: { ok: true, pid: Integer }
    • failure: { ok: false, error: String }


42
43
44
45
46
47
48
49
50
51
# File 'documented/common/session_launcher.rb', line 42

def launch(launch_data, launch_context: nil)
  unless launch_data.is_a?(Array) && launch_data.any?
    return { ok: false, error: 'launch_data must be a non-empty Array' }
  end

  pid = spawn_process(launch_data, launch_context: launch_context)
  { ok: true, pid: pid }
rescue StandardError => e
  { ok: false, error: e.message }
end